| 1 |
/****************************************************************************** |
| 2 |
* |
| 3 |
* Project: KML Translator |
| 4 |
* Purpose: Implements OGRLIBKMLDriver |
| 5 |
* Author: Brian Case, rush at winkey dot org |
| 6 |
* |
| 7 |
****************************************************************************** |
| 8 |
* Copyright (c) 2010, Brian Case |
| 9 |
* Copyright (c) 2014, Even Rouault <even dot rouault at spatialys.com> |
| 10 |
* |
| 11 |
* SPDX-License-Identifier: MIT |
| 12 |
*****************************************************************************/ |
| 13 |
|
| 14 |
#include "libkml_headers.h" |
| 15 |
#include "ogrlibkmlfeature.h" |
| 16 |
|
| 17 |
#include "gdal.h" |
| 18 |
#include "ogr_geometry.h" |
| 19 |
#include "ogr_libkml.h" |
| 20 |
#include "ogrlibkmlfield.h" |
| 21 |
#include "ogrlibkmlfeaturestyle.h" |
| 22 |
#include "ogrlibkmlgeometry.h" |
| 23 |
#include "ogrsf_frmts.h" |
| 24 |
|
| 25 |
using kmldom::AliasPtr; |
| 26 |
using kmldom::CameraPtr; |
| 27 |
using kmldom::ElementPtr; |
| 28 |
using kmldom::FeaturePtr; |
| 29 |
using kmldom::GeometryPtr; |
| 30 |
using kmldom::GroundOverlayPtr; |
| 31 |
using kmldom::IconPtr; |
| 32 |
using kmldom::ImagePyramidPtr; |
| 33 |
using kmldom::KmlFactory; |
| 34 |
using kmldom::LinkPtr; |
| 35 |
using kmldom::LocationPtr; |
| 36 |
using kmldom::ModelPtr; |
| 37 |
using kmldom::NetworkLinkPtr; |
| 38 |
using kmldom::OrientationPtr; |
| 39 |
using kmldom::PhotoOverlayPtr; |
| 40 |
using kmldom::PlacemarkPtr; |
| 41 |
using kmldom::ResourceMapPtr; |
| 42 |
using kmldom::ScalePtr; |
| 43 |
using kmldom::ViewVolumePtr; |
| 44 |
|
| 45 |
static CameraPtr feat2kmlcamera(const struct fieldconfig &oFC, int iHeading, |
| 46 |
int iTilt, int iRoll, OGRFeature *poOgrFeat, |
| 47 |
KmlFactory *poKmlFactory) |
| 48 |
{ |
| 49 |
const int iCameraLongitudeField = |
| 50 |
poOgrFeat->GetFieldIndex(oFC.camera_longitude_field); |
| 51 |
const int iCameraLatitudeField = |
| 52 |
poOgrFeat->GetFieldIndex(oFC.camera_latitude_field); |
| 53 |
const int iCameraAltitudeField = |
| 54 |
poOgrFeat->GetFieldIndex(oFC.camera_altitude_field); |
| 55 |
const int iCameraAltitudeModeField = |
| 56 |
poOgrFeat->GetFieldIndex(oFC.camera_altitudemode_field); |
| 57 |
|
| 58 |
const bool bNeedCamera = |
| 59 |
iCameraLongitudeField >= 0 && |
| 60 |
poOgrFeat->IsFieldSetAndNotNull(iCameraLongitudeField) && |
| 61 |
iCameraLatitudeField >= 0 && |
| 62 |
poOgrFeat->IsFieldSetAndNotNull(iCameraLatitudeField) && |
| 63 |
((iHeading >= 0 && poOgrFeat->IsFieldSetAndNotNull(iHeading)) || |
| 64 |
(iTilt >= 0 && poOgrFeat->IsFieldSetAndNotNull(iTilt)) || |
| 65 |
(iRoll >= 0 && poOgrFeat->IsFieldSetAndNotNull(iRoll))); |
| 66 |
|
| 67 |
if (!bNeedCamera) |
| 68 |
return nullptr; |
| 69 |
|
| 70 |
CameraPtr const camera = poKmlFactory->CreateCamera(); |
| 71 |
camera->set_latitude(poOgrFeat->GetFieldAsDouble(iCameraLatitudeField)); |
| 72 |
camera->set_longitude(poOgrFeat->GetFieldAsDouble(iCameraLongitudeField)); |
| 73 |
int isGX = FALSE; |
| 74 |
|
| 75 |
if (iCameraAltitudeModeField >= 0 && |
| 76 |
poOgrFeat->IsFieldSetAndNotNull(iCameraAltitudeModeField)) |
| 77 |
{ |
| 78 |
const int nAltitudeMode = kmlAltitudeModeFromString( |
| 79 |
poOgrFeat->GetFieldAsString(iCameraAltitudeModeField), isGX); |
| 80 |
camera->set_altitudemode(nAltitudeMode); |
| 81 |
} |
| 82 |
else if (CPLTestBool( |
| 83 |
CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE"))) |
| 84 |
{ |
| 85 |
CPLError(CE_Warning, CPLE_AppDefined, |
| 86 |
"Camera should define altitudeMode != 'clampToGround'"); |
| 87 |
} |
| 88 |
|
| 89 |
if (iCameraAltitudeField >= 0 && |
| 90 |
poOgrFeat->IsFieldSetAndNotNull(iCameraAltitudeField)) |
| 91 |
{ |
| 92 |
camera->set_altitude(poOgrFeat->GetFieldAsDouble(iCameraAltitudeField)); |
| 93 |
} |
| 94 |
else if (CPLTestBool( |
| 95 |
CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE"))) |
| 96 |
{ |
| 97 |
CPLError(CE_Warning, CPLE_AppDefined, |
| 98 |
"Camera should have an altitude/Z"); |
| 99 |
camera->set_altitude(0.0); |
| 100 |
} |
| 101 |
|
| 102 |
if (iHeading >= 0 && poOgrFeat->IsFieldSetAndNotNull(iHeading)) |
| 103 |
camera->set_heading(poOgrFeat->GetFieldAsDouble(iHeading)); |
| 104 |
if (iTilt >= 0 && poOgrFeat->IsFieldSetAndNotNull(iTilt)) |
| 105 |
camera->set_tilt(poOgrFeat->GetFieldAsDouble(iTilt)); |
| 106 |
if (iRoll >= 0 && poOgrFeat->IsFieldSetAndNotNull(iRoll)) |
| 107 |
camera->set_roll(poOgrFeat->GetFieldAsDouble(iRoll)); |
| 108 |
|
| 109 |
return camera; |
| 110 |
} |
| 111 |
|
| 112 |
/************************************************************************/ |
| 113 |
/* OGRLIBKMLReplaceXYLevelInURL() */ |
| 114 |
/************************************************************************/ |
| 115 |
|
| 116 |
static CPLString OGRLIBKMLReplaceLevelXYInURL(const char *pszURL, int level, |
| 117 |
int x, int y) |
| 118 |
{ |
| 119 |
CPLString osRet(pszURL); |
| 120 |
size_t nPos = osRet.find("$[level]"); |
| 121 |
osRet = osRet.substr(0, nPos) + CPLSPrintf("%d", level) + |
| 122 |
osRet.substr(nPos + strlen("$[level]")); |
| 123 |
|
| 124 |
nPos = osRet.find("$[x]"); |
| 125 |
osRet = osRet.substr(0, nPos) + CPLSPrintf("%d", x) + |
| 126 |
osRet.substr(nPos + strlen("$[x]")); |
| 127 |
|
| 128 |
nPos = osRet.find("$[y]"); |
| 129 |
osRet = osRet.substr(0, nPos) + CPLSPrintf("%d", y) + |
| 130 |
osRet.substr(nPos + strlen("$[y]")); |
| 131 |
|
| 132 |
return osRet; |
| 133 |
} |
| 134 |
|
| 135 |
/************************************************************************/ |
| 136 |
/* IsPowerOf2 */ |
| 137 |
/************************************************************************/ |
| 138 |
|
| 139 |
static bool IsPowerOf2(int nVal) |
| 140 |
{ |
| 141 |
if (nVal < 1) |
| 142 |
return false; |
| 143 |
|
| 144 |
const unsigned int nTmp = static_cast<unsigned int>(nVal); |
| 145 |
|
| 146 |
return (nTmp & (nTmp - 1)) == 0; |
| 147 |
} |
| 148 |
|
| 149 |
/************************************************************************/ |
| 150 |
/* OGRLIBKMLGetMaxDimensions() */ |
| 151 |
/************************************************************************/ |
| 152 |
|
| 153 |
static void OGRLIBKMLGetMaxDimensions(const char *pszURL, int nTileSize, |
| 154 |
int *panMaxWidth, int *panMaxHeight) |
| 155 |
{ |
| 156 |
VSIStatBufL sStat; |
| 157 |
int nMaxLevel = 0; |
| 158 |
*panMaxWidth = 0; |
| 159 |
*panMaxHeight = 0; |
| 160 |
while (true) |
| 161 |
{ |
| 162 |
CPLString osURL = OGRLIBKMLReplaceLevelXYInURL(pszURL, nMaxLevel, 0, 0); |
| 163 |
if (strstr(osURL, ".kmz/")) |
| 164 |
osURL = "/vsizip/" + osURL; |
| 165 |
if (VSIStatL(osURL, &sStat) == 0) |
| 166 |
nMaxLevel++; |
| 167 |
else |
| 168 |
{ |
| 169 |
if (nMaxLevel == 0) |
| 170 |
return; |
| 171 |
break; |
| 172 |
} |
| 173 |
} |
| 174 |
nMaxLevel--; |
| 175 |
|
| 176 |
{ |
| 177 |
int i = 0; // Used after for. |
| 178 |
for (;; i++) |
| 179 |
{ |
| 180 |
CPLString osURL = |
| 181 |
OGRLIBKMLReplaceLevelXYInURL(pszURL, nMaxLevel, i + 1, 0); |
| 182 |
if (strstr(osURL, ".kmz/")) |
| 183 |
osURL = "/vsizip/" + osURL; |
| 184 |
if (VSIStatL(osURL, &sStat) != 0) |
| 185 |
break; |
| 186 |
} |
| 187 |
*panMaxWidth = (i + 1) * nTileSize; |
| 188 |
} |
| 189 |
|
| 190 |
int i = 0; // Used after for. |
| 191 |
for (;; i++) |
| 192 |
{ |
| 193 |
CPLString osURL = |
| 194 |
OGRLIBKMLReplaceLevelXYInURL(pszURL, nMaxLevel, 0, i + 1); |
| 195 |
if (strstr(osURL, ".kmz/")) |
| 196 |
osURL = "/vsizip/" + osURL; |
| 197 |
if (VSIStatL(osURL, &sStat) != 0) |
| 198 |
break; |
| 199 |
} |
| 200 |
*panMaxHeight = (i + 1) * nTileSize; |
| 201 |
} |
| 202 |
|
| 203 |
/************************************************************************/ |
| 204 |
/* feat2kml() */ |
| 205 |
/************************************************************************/ |
| 206 |
|
| 207 |
FeaturePtr feat2kml(OGRLIBKMLDataSource *poOgrDS, OGRLIBKMLLayer *poOgrLayer, |
| 208 |
OGRFeature *poOgrFeat, KmlFactory *poKmlFactory, |
| 209 |
int bUseSimpleField) |
| 210 |
{ |
| 211 |
FeaturePtr poKmlFeature = nullptr; |
| 212 |
const auto &oFC = poOgrLayer->GetFieldConfig(); |
| 213 |
|
| 214 |
/***** geometry *****/ |
| 215 |
OGRGeometry *poOgrGeom = poOgrFeat->GetGeometryRef(); |
| 216 |
const int iHeading = poOgrFeat->GetFieldIndex(oFC.headingfield); |
| 217 |
const int iTilt = poOgrFeat->GetFieldIndex(oFC.tiltfield); |
| 218 |
const int iRoll = poOgrFeat->GetFieldIndex(oFC.rollfield); |
| 219 |
const int iModel = poOgrFeat->GetFieldIndex(oFC.modelfield); |
| 220 |
const int iNetworkLink = poOgrFeat->GetFieldIndex(oFC.networklinkfield); |
| 221 |
const int iPhotoOverlay = poOgrFeat->GetFieldIndex(oFC.photooverlayfield); |
| 222 |
CameraPtr camera = nullptr; |
| 223 |
|
| 224 |
// PhotoOverlay. |
| 225 |
if (iPhotoOverlay >= 0 && poOgrFeat->IsFieldSetAndNotNull(iPhotoOverlay) && |
| 226 |
poOgrGeom != nullptr && !poOgrGeom->IsEmpty() && |
| 227 |
wkbFlatten(poOgrGeom->getGeometryType()) == wkbPoint && |
| 228 |
(camera = feat2kmlcamera(oFC, iHeading, iTilt, iRoll, poOgrFeat, |
| 229 |
poKmlFactory))) |
| 230 |
{ |
| 231 |
const int iLeftFovField = poOgrFeat->GetFieldIndex(oFC.leftfovfield); |
| 232 |
const int iRightFovField = poOgrFeat->GetFieldIndex(oFC.rightfovfield); |
| 233 |
const int iBottomFovField = |
| 234 |
poOgrFeat->GetFieldIndex(oFC.bottomfovfield); |
| 235 |
const int iTopFovField = poOgrFeat->GetFieldIndex(oFC.topfovfield); |
| 236 |
const int iNearField = poOgrFeat->GetFieldIndex(oFC.nearfield); |
| 237 |
|
| 238 |
const char *pszURL = poOgrFeat->GetFieldAsString(iPhotoOverlay); |
| 239 |
const int iImagePyramidTileSize = |
| 240 |
poOgrFeat->GetFieldIndex(oFC.imagepyramid_tilesize_field); |
| 241 |
const int iImagePyramidMaxWidth = |
| 242 |
poOgrFeat->GetFieldIndex(oFC.imagepyramid_maxwidth_field); |
| 243 |
const int iImagePyramidMaxHeight = |
| 244 |
poOgrFeat->GetFieldIndex(oFC.imagepyramid_maxheight_field); |
| 245 |
const int iImagePyramidGridOrigin = |
| 246 |
poOgrFeat->GetFieldIndex(oFC.imagepyramid_gridorigin_field); |
| 247 |
|
| 248 |
int nTileSize = 0; |
| 249 |
int nMaxWidth = 0; |
| 250 |
int nMaxHeight = 0; |
| 251 |
bool bIsTiledPhotoOverlay = false; |
| 252 |
bool bGridOriginIsUpperLeft = true; |
| 253 |
// OGC KML Abstract Test Case (ATC) 52 and 62 |
| 254 |
if (strstr(pszURL, "$[x]") && strstr(pszURL, "$[y]") && |
| 255 |
strstr(pszURL, "$[level]")) |
| 256 |
{ |
| 257 |
bIsTiledPhotoOverlay = true; |
| 258 |
bool bErrorEmitted = false; |
| 259 |
if (iImagePyramidTileSize < 0 || |
| 260 |
!poOgrFeat->IsFieldSetAndNotNull(iImagePyramidTileSize)) |
| 261 |
{ |
| 262 |
CPLDebug("LIBKML", |
| 263 |
"Missing ImagePyramid tileSize. Computing it"); |
| 264 |
CPLString osURL = OGRLIBKMLReplaceLevelXYInURL(pszURL, 0, 0, 0); |
| 265 |
if (strstr(osURL, ".kmz/")) |
| 266 |
osURL = "/vsizip/" + osURL; |
| 267 |
GDALDatasetH hDS = GDALOpen(osURL, GA_ReadOnly); |
| 268 |
if (hDS != nullptr) |
| 269 |
{ |
| 270 |
nTileSize = GDALGetRasterXSize(hDS); |
| 271 |
if (nTileSize != GDALGetRasterYSize(hDS)) |
| 272 |
{ |
| 273 |
CPLError(CE_Failure, CPLE_AppDefined, |
| 274 |
"Non square tile : %dx%d", |
| 275 |
GDALGetRasterXSize(hDS), |
| 276 |
GDALGetRasterYSize(hDS)); |
| 277 |
nTileSize = 0; |
| 278 |
bErrorEmitted = true; |
| 279 |
} |
| 280 |
GDALClose(hDS); |
| 281 |
} |
| 282 |
else |
| 283 |
{ |
| 284 |
CPLError(CE_Failure, CPLE_AppDefined, "Cannot open %s", |
| 285 |
osURL.c_str()); |
| 286 |
bErrorEmitted = true; |
| 287 |
} |
| 288 |
} |
| 289 |
else |
| 290 |
{ |
| 291 |
nTileSize = poOgrFeat->GetFieldAsInteger(iImagePyramidTileSize); |
| 292 |
} |
| 293 |
if (!bErrorEmitted && (nTileSize <= 1 || !IsPowerOf2(nTileSize))) |
| 294 |
{ |
| 295 |
CPLError(CE_Failure, CPLE_AppDefined, |
| 296 |
"Tile size is not a power of two: %d", nTileSize); |
| 297 |
nTileSize = 0; |
| 298 |
} |
| 299 |
|
| 300 |
if (nTileSize > 0) |
| 301 |
{ |
| 302 |
if (iImagePyramidMaxWidth < 0 || |
| 303 |
!poOgrFeat->IsFieldSetAndNotNull(iImagePyramidMaxWidth) || |
| 304 |
iImagePyramidMaxHeight < 0 || |
| 305 |
!poOgrFeat->IsFieldSetAndNotNull(iImagePyramidMaxHeight)) |
| 306 |
{ |
| 307 |
CPLDebug("LIBKML", |
| 308 |
"Missing ImagePyramid maxWidth and/or maxHeight. " |
| 309 |
"Computing it"); |
| 310 |
OGRLIBKMLGetMaxDimensions(pszURL, nTileSize, &nMaxWidth, |
| 311 |
&nMaxHeight); |
| 312 |
} |
| 313 |
else |
| 314 |
{ |
| 315 |
nMaxWidth = |
| 316 |
poOgrFeat->GetFieldAsInteger(iImagePyramidMaxWidth); |
| 317 |
nMaxHeight = |
| 318 |
poOgrFeat->GetFieldAsInteger(iImagePyramidMaxHeight); |
| 319 |
} |
| 320 |
|
| 321 |
if (nMaxWidth <= 0 || nMaxHeight <= 0) |
| 322 |
{ |
| 323 |
CPLError( |
| 324 |
CE_Failure, CPLE_AppDefined, |
| 325 |
"Cannot generate PhotoOverlay object since there are " |
| 326 |
"missing information to generate ImagePyramid element"); |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
if (iImagePyramidGridOrigin >= 0 && |
| 331 |
poOgrFeat->IsFieldSetAndNotNull(iImagePyramidGridOrigin)) |
| 332 |
{ |
| 333 |
const char *pszGridOrigin = |
| 334 |
poOgrFeat->GetFieldAsString(iImagePyramidGridOrigin); |
| 335 |
if (EQUAL(pszGridOrigin, "UpperLeft")) |
| 336 |
{ |
| 337 |
bGridOriginIsUpperLeft = true; |
| 338 |
} |
| 339 |
else if (EQUAL(pszGridOrigin, "BottomLeft")) |
| 340 |
{ |
| 341 |
bGridOriginIsUpperLeft = false; |
| 342 |
} |
| 343 |
else |
| 344 |
{ |
| 345 |
CPLError( |
| 346 |
CE_Failure, CPLE_AppDefined, |
| 347 |
"Unhandled value for imagepyramid_gridorigin : %s. " |
| 348 |
"Assuming UpperLeft", |
| 349 |
pszGridOrigin); |
| 350 |
} |
| 351 |
} |
| 352 |
} |
| 353 |
else |
| 354 |
{ |
| 355 |
if ((iImagePyramidTileSize >= 0 && |
| 356 |
poOgrFeat->IsFieldSetAndNotNull(iImagePyramidTileSize)) || |
| 357 |
(iImagePyramidMaxWidth >= 0 && |
| 358 |
poOgrFeat->IsFieldSetAndNotNull(iImagePyramidMaxWidth)) || |
| 359 |
(iImagePyramidMaxHeight >= 0 && |
| 360 |
poOgrFeat->IsFieldSetAndNotNull(iImagePyramidMaxHeight)) || |
| 361 |
(iImagePyramidGridOrigin >= 0 && |
| 362 |
poOgrFeat->IsFieldSetAndNotNull(iImagePyramidGridOrigin))) |
| 363 |
{ |
| 364 |
CPLError( |
| 365 |
CE_Warning, CPLE_AppDefined, |
| 366 |
"Ignoring any ImagePyramid information since the URL does " |
| 367 |
"not include $[x] and/or $[y] and/or $[level]"); |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
// OGC KML Abstract Test Case (ATC) 19 & 35. |
| 372 |
double dfNear = 0.0; |
| 373 |
|
| 374 |
if ((!bIsTiledPhotoOverlay || |
| 375 |
(nTileSize > 0 && nMaxWidth > 0 && nMaxHeight > 0)) && |
| 376 |
iLeftFovField >= 0 && |
| 377 |
poOgrFeat->IsFieldSetAndNotNull(iLeftFovField) && |
| 378 |
iRightFovField >= 0 && |
| 379 |
poOgrFeat->IsFieldSetAndNotNull(iRightFovField) && |
| 380 |
iBottomFovField >= 0 && |
| 381 |
poOgrFeat->IsFieldSetAndNotNull(iBottomFovField) && |
| 382 |
iTopFovField >= 0 && |
| 383 |
poOgrFeat->IsFieldSetAndNotNull(iTopFovField) && iNearField >= 0 && |
| 384 |
(dfNear = poOgrFeat->GetFieldAsDouble(iNearField)) > 0) |
| 385 |
{ |
| 386 |
const PhotoOverlayPtr poKmlPhotoOverlay = |
| 387 |
poKmlFactory->CreatePhotoOverlay(); |
| 388 |
poKmlFeature = poKmlPhotoOverlay; |
| 389 |
|
| 390 |
const IconPtr poKmlIcon = poKmlFactory->CreateIcon(); |
| 391 |
poKmlPhotoOverlay->set_icon(poKmlIcon); |
| 392 |
poKmlIcon->set_href(pszURL); |
| 393 |
|
| 394 |
const ViewVolumePtr poKmlViewVolume = |
| 395 |
poKmlFactory->CreateViewVolume(); |
| 396 |
poKmlPhotoOverlay->set_viewvolume(poKmlViewVolume); |
| 397 |
|
| 398 |
const double dfLeftFov = poOgrFeat->GetFieldAsDouble(iLeftFovField); |
| 399 |
const double dfRightFov = |
| 400 |
poOgrFeat->GetFieldAsDouble(iRightFovField); |
| 401 |
const double dfBottomFov = |
| 402 |
poOgrFeat->GetFieldAsDouble(iBottomFovField); |
| 403 |
const double dfTopFov = poOgrFeat->GetFieldAsDouble(iTopFovField); |
| 404 |
|
| 405 |
poKmlViewVolume->set_leftfov(dfLeftFov); |
| 406 |
poKmlViewVolume->set_rightfov(dfRightFov); |
| 407 |
poKmlViewVolume->set_bottomfov(dfBottomFov); |
| 408 |
poKmlViewVolume->set_topfov(dfTopFov); |
| 409 |
poKmlViewVolume->set_near(dfNear); |
| 410 |
|
| 411 |
if (bIsTiledPhotoOverlay) |
| 412 |
{ |
| 413 |
const ImagePyramidPtr poKmlImagePyramid = |
| 414 |
poKmlFactory->CreateImagePyramid(); |
| 415 |
poKmlPhotoOverlay->set_imagepyramid(poKmlImagePyramid); |
| 416 |
|
| 417 |
poKmlImagePyramid->set_tilesize(nTileSize); |
| 418 |
poKmlImagePyramid->set_maxwidth(nMaxWidth); |
| 419 |
poKmlImagePyramid->set_maxheight(nMaxHeight); |
| 420 |
poKmlImagePyramid->set_gridorigin( |
| 421 |
bGridOriginIsUpperLeft ? kmldom::GRIDORIGIN_UPPERLEFT |
| 422 |
: kmldom::GRIDORIGIN_LOWERLEFT); |
| 423 |
} |
| 424 |
|
| 425 |
const int iPhotoOverlayShapeField = |
| 426 |
poOgrFeat->GetFieldIndex(oFC.photooverlay_shape_field); |
| 427 |
if (iPhotoOverlayShapeField >= 0 && |
| 428 |
poOgrFeat->IsFieldSetAndNotNull(iPhotoOverlayShapeField)) |
| 429 |
{ |
| 430 |
const char *pszShape = |
| 431 |
poOgrFeat->GetFieldAsString(iPhotoOverlayShapeField); |
| 432 |
if (EQUAL(pszShape, "rectangle")) |
| 433 |
poKmlPhotoOverlay->set_shape(kmldom::SHAPE_RECTANGLE); |
| 434 |
else if (EQUAL(pszShape, "cylinder")) |
| 435 |
poKmlPhotoOverlay->set_shape(kmldom::SHAPE_CYLINDER); |
| 436 |
else if (EQUAL(pszShape, "sphere")) |
| 437 |
poKmlPhotoOverlay->set_shape(kmldom::SHAPE_SPHERE); |
| 438 |
} |
| 439 |
|
| 440 |
ElementPtr poKmlElement = geom2kml(poOgrGeom, -1, poKmlFactory); |
| 441 |
if (!poKmlElement) |
| 442 |
return nullptr; |
| 443 |
|
| 444 |
poKmlPhotoOverlay->set_point(AsPoint(std::move(poKmlElement))); |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
// NetworkLink. |
| 449 |
if (!poKmlFeature && iNetworkLink >= 0 && |
| 450 |
poOgrFeat->IsFieldSetAndNotNull(iNetworkLink)) |
| 451 |
{ |
| 452 |
const NetworkLinkPtr poKmlNetworkLink = |
| 453 |
poKmlFactory->CreateNetworkLink(); |
| 454 |
poKmlFeature = poKmlNetworkLink; |
| 455 |
|
| 456 |
const int iRefreshVisibility = |
| 457 |
poOgrFeat->GetFieldIndex(oFC.networklink_refreshvisibility_field); |
| 458 |
|
| 459 |
if (iRefreshVisibility >= 0 && |
| 460 |
poOgrFeat->IsFieldSetAndNotNull(iRefreshVisibility)) |
| 461 |
{ |
| 462 |
poKmlNetworkLink->set_refreshvisibility( |
| 463 |
CPL_TO_BOOL(poOgrFeat->GetFieldAsInteger(iRefreshVisibility))); |
| 464 |
} |
| 465 |
|
| 466 |
const int iFlyToView = |
| 467 |
poOgrFeat->GetFieldIndex(oFC.networklink_flytoview_field); |
| 468 |
|
| 469 |
if (iFlyToView >= 0 && poOgrFeat->IsFieldSetAndNotNull(iFlyToView)) |
| 470 |
poKmlNetworkLink->set_flytoview( |
| 471 |
CPL_TO_BOOL(poOgrFeat->GetFieldAsInteger(iFlyToView))); |
| 472 |
|
| 473 |
const LinkPtr poKmlLink = poKmlFactory->CreateLink(); |
| 474 |
poKmlLink->set_href(poOgrFeat->GetFieldAsString(iNetworkLink)); |
| 475 |
poKmlNetworkLink->set_link(poKmlLink); |
| 476 |
|
| 477 |
const int iRefreshMode = |
| 478 |
poOgrFeat->GetFieldIndex(oFC.networklink_refreshMode_field); |
| 479 |
const int iRefreshInterval = |
| 480 |
poOgrFeat->GetFieldIndex(oFC.networklink_refreshInterval_field); |
| 481 |
const int iViewRefreshMode = |
| 482 |
poOgrFeat->GetFieldIndex(oFC.networklink_viewRefreshMode_field); |
| 483 |
const int iViewRefreshTime = |
| 484 |
poOgrFeat->GetFieldIndex(oFC.networklink_viewRefreshTime_field); |
| 485 |
const int iViewBoundScale = |
| 486 |
poOgrFeat->GetFieldIndex(oFC.networklink_viewBoundScale_field); |
| 487 |
const int iViewFormat = |
| 488 |
poOgrFeat->GetFieldIndex(oFC.networklink_viewFormat_field); |
| 489 |
const int iHttpQuery = |
| 490 |
poOgrFeat->GetFieldIndex(oFC.networklink_httpQuery_field); |
| 491 |
|
| 492 |
double dfRefreshInterval = 0.0; |
| 493 |
if (iRefreshInterval >= 0 && |
| 494 |
poOgrFeat->IsFieldSetAndNotNull(iRefreshInterval)) |
| 495 |
{ |
| 496 |
dfRefreshInterval = poOgrFeat->GetFieldAsDouble(iRefreshInterval); |
| 497 |
if (dfRefreshInterval < 0) |
| 498 |
dfRefreshInterval = 0.0; |
| 499 |
} |
| 500 |
|
| 501 |
double dfViewRefreshTime = 0.0; |
| 502 |
if (iViewRefreshTime >= 0 && |
| 503 |
poOgrFeat->IsFieldSetAndNotNull(iViewRefreshTime)) |
| 504 |
{ |
| 505 |
dfViewRefreshTime = poOgrFeat->GetFieldAsDouble(iViewRefreshTime); |
| 506 |
if (dfViewRefreshTime < 0) |
| 507 |
dfViewRefreshTime = 0.0; |
| 508 |
} |
| 509 |
|
| 510 |
if (dfRefreshInterval > 0) // ATC 51 |
| 511 |
poKmlLink->set_refreshmode(kmldom::REFRESHMODE_ONINTERVAL); |
| 512 |
else if (iRefreshMode >= 0 && |
| 513 |
poOgrFeat->IsFieldSetAndNotNull(iRefreshMode)) |
| 514 |
{ |
| 515 |
const char *const pszRefreshMode = |
| 516 |
poOgrFeat->GetFieldAsString(iRefreshMode); |
| 517 |
if (EQUAL(pszRefreshMode, "onChange")) |
| 518 |
poKmlLink->set_refreshmode(kmldom::REFRESHMODE_ONCHANGE); |
| 519 |
else if (EQUAL(pszRefreshMode, "onInterval")) |
| 520 |
poKmlLink->set_refreshmode(kmldom::REFRESHMODE_ONINTERVAL); |
| 521 |
else if (EQUAL(pszRefreshMode, "onExpire")) |
| 522 |
poKmlLink->set_refreshmode(kmldom::REFRESHMODE_ONEXPIRE); |
| 523 |
} |
| 524 |
|
| 525 |
if (dfRefreshInterval > 0) // ATC 9 |
| 526 |
poKmlLink->set_refreshinterval(dfRefreshInterval); |
| 527 |
|
| 528 |
if (dfViewRefreshTime > 0) // ATC 51 |
| 529 |
poKmlLink->set_viewrefreshmode(kmldom::VIEWREFRESHMODE_ONSTOP); |
| 530 |
else if (iViewRefreshMode >= 0 && |
| 531 |
poOgrFeat->IsFieldSetAndNotNull(iViewRefreshMode)) |
| 532 |
{ |
| 533 |
const char *const pszViewRefreshMode = |
| 534 |
poOgrFeat->GetFieldAsString(iViewRefreshMode); |
| 535 |
if (EQUAL(pszViewRefreshMode, "never")) |
| 536 |
poKmlLink->set_viewrefreshmode(kmldom::VIEWREFRESHMODE_NEVER); |
| 537 |
else if (EQUAL(pszViewRefreshMode, "onRequest")) |
| 538 |
poKmlLink->set_viewrefreshmode( |
| 539 |
kmldom::VIEWREFRESHMODE_ONREQUEST); |
| 540 |
else if (EQUAL(pszViewRefreshMode, "onStop")) |
| 541 |
poKmlLink->set_viewrefreshmode(kmldom::VIEWREFRESHMODE_ONSTOP); |
| 542 |
else if (EQUAL(pszViewRefreshMode, "onRegion")) |
| 543 |
poKmlLink->set_viewrefreshmode( |
| 544 |
kmldom::VIEWREFRESHMODE_ONREGION); |
| 545 |
} |
| 546 |
|
| 547 |
if (dfViewRefreshTime > 0) // ATC 9 |
| 548 |
poKmlLink->set_viewrefreshtime(dfViewRefreshTime); |
| 549 |
|
| 550 |
if (iViewBoundScale >= 0 && |
| 551 |
poOgrFeat->IsFieldSetAndNotNull(iViewBoundScale)) |
| 552 |
{ |
| 553 |
const double dfViewBoundScale = |
| 554 |
poOgrFeat->GetFieldAsDouble(iViewBoundScale); |
| 555 |
if (dfViewBoundScale > 0) // ATC 9 |
| 556 |
poKmlLink->set_viewboundscale(dfViewBoundScale); |
| 557 |
} |
| 558 |
|
| 559 |
if (iViewFormat >= 0 && poOgrFeat->IsFieldSetAndNotNull(iViewFormat)) |
| 560 |
{ |
| 561 |
const char *const pszViewFormat = |
| 562 |
poOgrFeat->GetFieldAsString(iViewFormat); |
| 563 |
if (pszViewFormat[0] != '\0') // ATC 46 |
| 564 |
poKmlLink->set_viewformat(pszViewFormat); |
| 565 |
} |
| 566 |
|
| 567 |
if (iHttpQuery >= 0 && poOgrFeat->IsFieldSetAndNotNull(iHttpQuery)) |
| 568 |
{ |
| 569 |
const char *const pszHttpQuery = |
| 570 |
poOgrFeat->GetFieldAsString(iHttpQuery); |
| 571 |
if (strstr(pszHttpQuery, "[clientVersion]") != nullptr || |
| 572 |
strstr(pszHttpQuery, "[kmlVersion]") != nullptr || |
| 573 |
strstr(pszHttpQuery, "[clientName]") != nullptr || |
| 574 |
strstr(pszHttpQuery, "[language]") != nullptr) // ATC 47 |
| 575 |
{ |
| 576 |
poKmlLink->set_httpquery(pszHttpQuery); |
| 577 |
} |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
// Model. |
| 582 |
else if (!poKmlFeature && iModel >= 0 && |
| 583 |
poOgrFeat->IsFieldSetAndNotNull(iModel) && poOgrGeom != nullptr && |
| 584 |
!poOgrGeom->IsEmpty() && |
| 585 |
wkbFlatten(poOgrGeom->getGeometryType()) == wkbPoint) |
| 586 |
{ |
| 587 |
const PlacemarkPtr poKmlPlacemark = poKmlFactory->CreatePlacemark(); |
| 588 |
poKmlFeature = poKmlPlacemark; |
| 589 |
|
| 590 |
const OGRPoint *const poOgrPoint = poOgrGeom->toPoint(); |
| 591 |
ModelPtr model = poKmlFactory->CreateModel(); |
| 592 |
|
| 593 |
LocationPtr location = poKmlFactory->CreateLocation(); |
| 594 |
model->set_location(location); |
| 595 |
location->set_latitude(poOgrPoint->getY()); |
| 596 |
location->set_longitude(poOgrPoint->getX()); |
| 597 |
if (poOgrPoint->getCoordinateDimension() == 3) |
| 598 |
location->set_altitude(poOgrPoint->getZ()); |
| 599 |
|
| 600 |
int isGX = FALSE; |
| 601 |
const int iAltitudeMode = |
| 602 |
poOgrFeat->GetFieldIndex(oFC.altitudeModefield); |
| 603 |
if (poOgrFeat->IsFieldSetAndNotNull(iAltitudeMode)) |
| 604 |
{ |
| 605 |
const int nAltitudeMode = kmlAltitudeModeFromString( |
| 606 |
poOgrFeat->GetFieldAsString(iAltitudeMode), isGX); |
| 607 |
model->set_altitudemode(nAltitudeMode); |
| 608 |
|
| 609 |
// ATC 55 |
| 610 |
if (nAltitudeMode != kmldom::ALTITUDEMODE_CLAMPTOGROUND && |
| 611 |
poOgrPoint->getCoordinateDimension() != 3) |
| 612 |
{ |
| 613 |
if (CPLTestBool( |
| 614 |
CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE"))) |
| 615 |
CPLError(CE_Warning, CPLE_AppDefined, |
| 616 |
"Altitude should be defined"); |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
if ((iHeading >= 0 && poOgrFeat->IsFieldSetAndNotNull(iHeading)) || |
| 621 |
(iTilt >= 0 && poOgrFeat->IsFieldSetAndNotNull(iTilt)) || |
| 622 |
(iRoll >= 0 && poOgrFeat->IsFieldSetAndNotNull(iRoll))) |
| 623 |
{ |
| 624 |
OrientationPtr const orientation = |
| 625 |
poKmlFactory->CreateOrientation(); |
| 626 |
model->set_orientation(orientation); |
| 627 |
if (iHeading >= 0 && poOgrFeat->IsFieldSetAndNotNull(iHeading)) |
| 628 |
orientation->set_heading(poOgrFeat->GetFieldAsDouble(iHeading)); |
| 629 |
else |
| 630 |
orientation->set_heading(0); |
| 631 |
if (iTilt >= 0 && poOgrFeat->IsFieldSetAndNotNull(iTilt)) |
| 632 |
orientation->set_tilt(poOgrFeat->GetFieldAsDouble(iTilt)); |
| 633 |
else |
| 634 |
orientation->set_tilt(0); |
| 635 |
if (iRoll >= 0 && poOgrFeat->IsFieldSetAndNotNull(iRoll)) |
| 636 |
orientation->set_roll(poOgrFeat->GetFieldAsDouble(iRoll)); |
| 637 |
else |
| 638 |
orientation->set_roll(0); |
| 639 |
} |
| 640 |
const int iScaleX = poOgrFeat->GetFieldIndex(oFC.scalexfield); |
| 641 |
const int iScaleY = poOgrFeat->GetFieldIndex(oFC.scaleyfield); |
| 642 |
const int iScaleZ = poOgrFeat->GetFieldIndex(oFC.scalezfield); |
| 643 |
|
| 644 |
const ScalePtr scale = poKmlFactory->CreateScale(); |
| 645 |
model->set_scale(scale); |
| 646 |
if (iScaleX >= 0 && poOgrFeat->IsFieldSetAndNotNull(iScaleX)) |
| 647 |
scale->set_x(poOgrFeat->GetFieldAsDouble(iScaleX)); |
| 648 |
else |
| 649 |
scale->set_x(1.0); |
| 650 |
if (iScaleY >= 0 && poOgrFeat->IsFieldSetAndNotNull(iScaleY)) |
| 651 |
scale->set_y(poOgrFeat->GetFieldAsDouble(iScaleY)); |
| 652 |
else |
| 653 |
scale->set_y(1.0); |
| 654 |
if (iScaleZ >= 0 && poOgrFeat->IsFieldSetAndNotNull(iScaleZ)) |
| 655 |
scale->set_z(poOgrFeat->GetFieldAsDouble(iScaleZ)); |
| 656 |
else |
| 657 |
scale->set_z(1.0); |
| 658 |
|
| 659 |
const LinkPtr link = poKmlFactory->CreateLink(); |
| 660 |
model->set_link(link); |
| 661 |
const char *const pszURL = poOgrFeat->GetFieldAsString(oFC.modelfield); |
| 662 |
link->set_href(pszURL); |
| 663 |
|
| 664 |
// Collada 3D file? |
| 665 |
if (EQUAL(CPLGetExtensionSafe(pszURL).c_str(), "dae") && |
| 666 |
CPLTestBool(CPLGetConfigOption("LIBKML_ADD_RESOURCE_MAP", "TRUE"))) |
| 667 |
{ |
| 668 |
VSILFILE *fp = nullptr; |
| 669 |
bool bIsURL = false; |
| 670 |
if (STARTS_WITH_CI(pszURL, "http://") || |
| 671 |
STARTS_WITH_CI(pszURL, "https://")) |
| 672 |
{ |
| 673 |
bIsURL = true; |
| 674 |
fp = VSIFOpenL(CPLSPrintf("/vsicurl/%s", pszURL), "rb"); |
| 675 |
} |
| 676 |
else if (strstr(pszURL, ".kmz/") != nullptr) |
| 677 |
{ |
| 678 |
fp = VSIFOpenL(CPLSPrintf("/vsizip/%s", pszURL), "rb"); |
| 679 |
} |
| 680 |
else |
| 681 |
{ |
| 682 |
fp = VSIFOpenL(pszURL, "rb"); |
| 683 |
} |
| 684 |
if (fp != nullptr) |
| 685 |
{ |
| 686 |
ResourceMapPtr resourceMap = nullptr; |
| 687 |
const char *pszLine = nullptr; |
| 688 |
while ((pszLine = CPLReadLineL(fp)) != nullptr) |
| 689 |
{ |
| 690 |
const char *pszInitFrom = strstr(pszLine, "<init_from>"); |
| 691 |
if (pszInitFrom) |
| 692 |
{ |
| 693 |
pszInitFrom += strlen("<init_from>"); |
| 694 |
const char *const pszInitFromEnd = |
| 695 |
strstr(pszInitFrom, "</init_from>"); |
| 696 |
if (pszInitFromEnd) |
| 697 |
{ |
| 698 |
CPLString osImage(pszInitFrom); |
| 699 |
osImage.resize(pszInitFromEnd - pszInitFrom); |
| 700 |
const std::string osExtension = |
| 701 |
CPLGetExtensionSafe(osImage); |
| 702 |
if (EQUAL(osExtension.c_str(), "jpg") || |
| 703 |
EQUAL(osExtension.c_str(), "jpeg") || |
| 704 |
EQUAL(osExtension.c_str(), "png") || |
| 705 |
EQUAL(osExtension.c_str(), "gif")) |
| 706 |
{ |
| 707 |
if (!resourceMap) |
| 708 |
resourceMap = |
| 709 |
poKmlFactory->CreateResourceMap(); |
| 710 |
const AliasPtr alias = |
| 711 |
poKmlFactory->CreateAlias(); |
| 712 |
if (bIsURL && CPLIsFilenameRelative(osImage)) |
| 713 |
{ |
| 714 |
if (STARTS_WITH(pszURL, "http")) |
| 715 |
alias->set_targethref(CPLSPrintf( |
| 716 |
"%s/%s", |
| 717 |
CPLGetPathSafe(pszURL).c_str(), |
| 718 |
osImage.c_str())); |
| 719 |
else |
| 720 |
alias->set_targethref( |
| 721 |
CPLFormFilenameSafe( |
| 722 |
CPLGetPathSafe(pszURL).c_str(), |
| 723 |
osImage, nullptr)); |
| 724 |
} |
| 725 |
else |
| 726 |
alias->set_targethref(osImage); |
| 727 |
alias->set_sourcehref(osImage); |
| 728 |
resourceMap->add_alias(alias); |
| 729 |
} |
| 730 |
} |
| 731 |
} |
| 732 |
} |
| 733 |
if (resourceMap) |
| 734 |
model->set_resourcemap(resourceMap); |
| 735 |
VSIFCloseL(fp); |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
poKmlPlacemark->set_geometry(AsGeometry(model)); |
| 740 |
} |
| 741 |
|
| 742 |
// Camera. |
| 743 |
else if (!poKmlFeature && poOgrGeom != nullptr && !poOgrGeom->IsEmpty() && |
| 744 |
wkbFlatten(poOgrGeom->getGeometryType()) == wkbPoint && |
| 745 |
poOgrFeat->GetFieldIndex(oFC.camera_longitude_field) < 0 && |
| 746 |
((iHeading >= 0 && poOgrFeat->IsFieldSetAndNotNull(iHeading)) || |
| 747 |
(iTilt >= 0 && poOgrFeat->IsFieldSetAndNotNull(iTilt)) || |
| 748 |
(iRoll >= 0 && poOgrFeat->IsFieldSetAndNotNull(iRoll)))) |
| 749 |
{ |
| 750 |
const PlacemarkPtr poKmlPlacemark = poKmlFactory->CreatePlacemark(); |
| 751 |
poKmlFeature = poKmlPlacemark; |
| 752 |
|
| 753 |
const OGRPoint *const poOgrPoint = poOgrGeom->toPoint(); |
| 754 |
camera = poKmlFactory->CreateCamera(); |
| 755 |
camera->set_latitude(poOgrPoint->getY()); |
| 756 |
camera->set_longitude(poOgrPoint->getX()); |
| 757 |
int isGX = FALSE; |
| 758 |
const int iAltitudeMode = |
| 759 |
poOgrFeat->GetFieldIndex(oFC.altitudeModefield); |
| 760 |
if (poOgrFeat->IsFieldSetAndNotNull(iAltitudeMode)) |
| 761 |
{ |
| 762 |
const int nAltitudeMode = kmlAltitudeModeFromString( |
| 763 |
poOgrFeat->GetFieldAsString(iAltitudeMode), isGX); |
| 764 |
camera->set_altitudemode(nAltitudeMode); |
| 765 |
} |
| 766 |
else if (CPLTestBool( |
| 767 |
CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE"))) |
| 768 |
{ |
| 769 |
CPLError(CE_Warning, CPLE_AppDefined, |
| 770 |
"Camera should define altitudeMode != 'clampToGround'"); |
| 771 |
} |
| 772 |
|
| 773 |
if (poOgrPoint->getCoordinateDimension() == 3) |
| 774 |
{ |
| 775 |
camera->set_altitude(poOgrPoint->getZ()); |
| 776 |
} |
| 777 |
else if (CPLTestBool( |
| 778 |
CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE"))) |
| 779 |
{ |
| 780 |
CPLError(CE_Warning, CPLE_AppDefined, |
| 781 |
"Camera should have an altitude/Z"); |
| 782 |
camera->set_altitude(0.0); |
| 783 |
} |
| 784 |
|
| 785 |
if (iHeading >= 0 && poOgrFeat->IsFieldSetAndNotNull(iHeading)) |
| 786 |
camera->set_heading(poOgrFeat->GetFieldAsDouble(iHeading)); |
| 787 |
if (iTilt >= 0 && poOgrFeat->IsFieldSetAndNotNull(iTilt)) |
| 788 |
camera->set_tilt(poOgrFeat->GetFieldAsDouble(iTilt)); |
| 789 |
if (iRoll >= 0 && poOgrFeat->IsFieldSetAndNotNull(iRoll)) |
| 790 |
camera->set_roll(poOgrFeat->GetFieldAsDouble(iRoll)); |
| 791 |
poKmlPlacemark->set_abstractview(camera); |
| 792 |
} |
| 793 |
else if (!poKmlFeature) |
| 794 |
{ |
| 795 |
const PlacemarkPtr poKmlPlacemark = poKmlFactory->CreatePlacemark(); |
| 796 |
poKmlFeature = poKmlPlacemark; |
| 797 |
|
| 798 |
if (poOgrGeom) |
| 799 |
{ |
| 800 |
ElementPtr poKmlElement = geom2kml(poOgrGeom, -1, poKmlFactory); |
| 801 |
if (!poKmlElement) |
| 802 |
{ |
| 803 |
CPLError(CE_Failure, CPLE_AppDefined, |
| 804 |
"Cannot translate feature: %s", |
| 805 |
poOgrFeat->DumpReadableAsString().c_str()); |
| 806 |
return nullptr; |
| 807 |
} |
| 808 |
|
| 809 |
poKmlPlacemark->set_geometry(AsGeometry(std::move(poKmlElement))); |
| 810 |
} |
| 811 |
} |
| 812 |
|
| 813 |
if (!camera) |
| 814 |
camera = feat2kmlcamera(oFC, iHeading, iTilt, iRoll, poOgrFeat, |
| 815 |
poKmlFactory); |
| 816 |
if (camera) |
| 817 |
poKmlFeature->set_abstractview(camera); |
| 818 |
|
| 819 |
/***** style *****/ |
| 820 |
featurestyle2kml(poOgrDS, poOgrLayer, poOgrFeat, poKmlFactory, |
| 821 |
poKmlFeature); |
| 822 |
|
| 823 |
/***** fields *****/ |
| 824 |
field2kml(poOgrFeat, poOgrLayer, poKmlFactory, poKmlFeature, |
| 825 |
bUseSimpleField, oFC); |
| 826 |
|
| 827 |
return poKmlFeature; |
| 828 |
} |
| 829 |
|
| 830 |
OGRFeature * |
| 831 |
kml2feat(PlacemarkPtr poKmlPlacemark, OGRLIBKMLDataSource *poOgrDS, |
| 832 |
OGRLIBKMLLayer *poOgrLayer, OGRFeatureDefn *poOgrFeatDefn, |
| 833 |
OGRSpatialReference *poOgrSRS, |
| 834 |
const std::map<std::string, int> &mapSimpleFieldNameToOgrFieldIx) |
| 835 |
{ |
| 836 |
OGRFeature *poOgrFeat = new OGRFeature(poOgrFeatDefn); |
| 837 |
|
| 838 |
/***** style *****/ |
| 839 |
kml2featurestyle(poKmlPlacemark, poOgrDS, poOgrLayer, poOgrFeat); |
| 840 |
|
| 841 |
/***** geometry *****/ |
| 842 |
if (poKmlPlacemark->has_geometry()) |
| 843 |
{ |
| 844 |
OGRGeometry *const poOgrGeom = |
| 845 |
kml2geom(poKmlPlacemark->get_geometry(), poOgrSRS); |
| 846 |
poOgrFeat->SetGeometryDirectly(poOgrGeom); |
| 847 |
} |
| 848 |
else if (poKmlPlacemark->has_abstractview() && |
| 849 |
poKmlPlacemark->get_abstractview()->IsA(kmldom::Type_Camera)) |
| 850 |
{ |
| 851 |
const CameraPtr &camera = AsCamera(poKmlPlacemark->get_abstractview()); |
| 852 |
if (camera->has_longitude() && camera->has_latitude()) |
| 853 |
{ |
| 854 |
if (camera->has_altitude()) |
| 855 |
poOgrFeat->SetGeometryDirectly(new OGRPoint( |
| 856 |
camera->get_longitude(), camera->get_latitude(), |
| 857 |
camera->get_altitude())); |
| 858 |
else |
| 859 |
poOgrFeat->SetGeometryDirectly(new OGRPoint( |
| 860 |
camera->get_longitude(), camera->get_latitude())); |
| 861 |
poOgrFeat->GetGeometryRef()->assignSpatialReference(poOgrSRS); |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
/***** fields *****/ |
| 866 |
kml2field(poOgrFeat, AsFeature(poKmlPlacemark), |
| 867 |
poOgrLayer->GetFieldConfig(), mapSimpleFieldNameToOgrFieldIx); |
| 868 |
|
| 869 |
return poOgrFeat; |
| 870 |
} |
| 871 |
|
| 872 |
OGRFeature *kmlgroundoverlay2feat( |
| 873 |
GroundOverlayPtr poKmlOverlay, OGRLIBKMLDataSource * /* poOgrDS */, |
| 874 |
OGRLIBKMLLayer *poOgrLayer, OGRFeatureDefn *poOgrFeatDefn, |
| 875 |
OGRSpatialReference *poOgrSRS, |
| 876 |
const std::map<std::string, int> &mapSimpleFieldNameToOgrFieldIx) |
| 877 |
{ |
| 878 |
OGRFeature *poOgrFeat = new OGRFeature(poOgrFeatDefn); |
| 879 |
|
| 880 |
/***** geometry *****/ |
| 881 |
if (poKmlOverlay->has_latlonbox()) |
| 882 |
{ |
| 883 |
OGRGeometry *const poOgrGeom = |
| 884 |
kml2geom_latlonbox(poKmlOverlay->get_latlonbox(), poOgrSRS); |
| 885 |
poOgrFeat->SetGeometryDirectly(poOgrGeom); |
| 886 |
} |
| 887 |
else if (poKmlOverlay->has_gx_latlonquad()) |
| 888 |
{ |
| 889 |
OGRGeometry *const poOgrGeom = |
| 890 |
kml2geom_latlonquad(poKmlOverlay->get_gx_latlonquad(), poOgrSRS); |
| 891 |
poOgrFeat->SetGeometryDirectly(poOgrGeom); |
| 892 |
} |
| 893 |
|
| 894 |
/***** fields *****/ |
| 895 |
kml2field(poOgrFeat, AsFeature(poKmlOverlay), poOgrLayer->GetFieldConfig(), |
| 896 |
mapSimpleFieldNameToOgrFieldIx); |
| 897 |
|
| 898 |
return poOgrFeat; |
| 899 |
} |