diff -b -u libkml_trunk/drv_libkml.htm libkml/drv_libkml.htm
--- libkml_trunk/drv_libkml.htm Fri Jul 6 11:30:22 2012
+++ libkml/drv_libkml.htm Fri Jul 6 17:09:49 2012
@@ -103,9 +103,19 @@
An OGR feature
translates to kml as a
- <Placemark>.
+ <Placemark>, and vice-versa.
+
+
+ GroundOverlay
+
+
+ KML
+
+ <GroundOverlay> elements are supported for reading. There are icon and drawOrder
+ fields.
+
Style
@@ -216,6 +226,18 @@
<visibility>. The name of the ogr field can be changed with the
enviroment variable LIBKML_VISIBILITY_FIELD .
+
+
icon
+ This string field maps to the kml tag
+
+ <icon>. The name of the ogr field can be changed with the
+ enviroment variable LIBKML_ICON_FIELD .
+
+ drawOrder
+ This integer field maps to the kml tag
+
+ <drawOrder>. The name of the ogr field can be changed with the
+ enviroment variable LIBKML_DRAWORDER_FIELD .
OGR_STYLE
This string feild maps to a features style string, OGR reads this field
diff -b -u libkml_trunk/ogrlibkmldatasource.cpp libkml/ogrlibkmldatasource.cpp
--- libkml_trunk/ogrlibkmldatasource.cpp Fri Jul 6 11:31:55 2012
+++ libkml/ogrlibkmldatasource.cpp Fri Jul 6 11:41:23 2012
@@ -729,12 +729,12 @@
if ( poKmlFeat->IsA ( kmldom::Type_Container ) )
poKmlContainer = AsContainer ( poKmlFeat );
- else if ( poKmlFeat->IsA ( kmldom::Type_Placemark ) )
+ else if ( poKmlFeat->IsA ( kmldom::Type_Placemark ) ||
+ poKmlFeat->IsA ( kmldom::Type_GroundOverlay ) )
{
poKmlContainer = m_poKmlFactory->CreateDocument ( );
poKmlContainer->add_feature ( kmldom::AsFeature(kmlengine::Clone(poKmlFeat)) );
}
-
}
}
diff -b -u libkml_trunk/ogrlibkmlfeature.cpp libkml/ogrlibkmlfeature.cpp
--- libkml_trunk/ogrlibkmlfeature.cpp Fri Jul 6 11:32:32 2012
+++ libkml/ogrlibkmlfeature.cpp Wed Jun 6 14:43:19 2012
@@ -36,6 +36,8 @@
using kmldom::ElementPtr;
using kmldom::GeometryPtr;
using kmldom::Geometry;
+using kmldom::GroundOverlayPtr;
+using kmldom::LatLonBoxPtr;
#include "ogr_libkml.h"
@@ -99,7 +101,37 @@
/***** fields *****/
- kml2field ( poOgrFeat, poKmlPlacemark );
+ kml2field ( poOgrFeat, AsFeature ( poKmlPlacemark ) );
+
+ return poOgrFeat;
+}
+
+OGRFeature *kmlgroundoverlay2feat (
+ GroundOverlayPtr poKmlOverlay,
+ OGRLIBKMLDataSource * poOgrDS,
+ OGRLayer * poOgrLayer,
+ OGRFeatureDefn * poOgrFeatDefn,
+ OGRSpatialReference *poOgrSRS)
+{
+
+ OGRFeature *poOgrFeat = new OGRFeature ( poOgrFeatDefn );
+
+ /***** style *****/
+
+ //kml2featurestyle ( poKmlPlacemark, poOgrDS, poOgrLayer, poOgrFeat );
+
+ /***** geometry *****/
+
+ if ( poKmlOverlay->has_latlonbox ( ) ) {
+ OGRGeometry *poOgrGeom =
+ kml2latlongeom ( poKmlOverlay->get_latlonbox ( ), poOgrSRS );
+ poOgrFeat->SetGeometryDirectly ( poOgrGeom );
+
+ }
+
+ /***** fields *****/
+
+ kml2field ( poOgrFeat, AsFeature ( poKmlOverlay ) );
return poOgrFeat;
}
diff -b -u libkml_trunk/ogrlibkmlfeature.h libkml/ogrlibkmlfeature.h
--- libkml_trunk/ogrlibkmlfeature.h Fri Jul 6 11:32:42 2012
+++ libkml/ogrlibkmlfeature.h Wed Jun 6 14:42:15 2012
@@ -54,3 +54,10 @@
OGRLayer * poOgrLayer,
OGRFeatureDefn * poOgrFeatDefn,
OGRSpatialReference *poOgrSRS);
+
+OGRFeature *kmlgroundoverlay2feat (
+ GroundOverlayPtr poKmlOverlay,
+ OGRLIBKMLDataSource * poOgrDS,
+ OGRLayer * poOgrLayer,
+ OGRFeatureDefn * poOgrFeatDefn,
+ OGRSpatialReference *poOgrSRS);
diff -b -u libkml_trunk/ogrlibkmlfield.cpp libkml/ogrlibkmlfield.cpp
--- libkml_trunk/ogrlibkmlfield.cpp Fri Jul 6 11:33:29 2012
+++ libkml/ogrlibkmlfield.cpp Wed Jun 6 14:48:44 2012
@@ -49,6 +49,9 @@
using kmldom::MultiGeometryPtr;
using kmldom::GeometryPtr;
+using kmldom::FeaturePtr;
+using kmldom::GroundOverlayPtr;
+using kmldom::IconPtr;
#include "ogr_libkml.h"
@@ -967,7 +970,7 @@
void kml2field (
OGRFeature * poOgrFeat,
- PlacemarkPtr poKmlPlacemark )
+ FeaturePtr poKmlFeature )
{
const char *namefield = CPLGetConfigOption ( "LIBKML_NAME_FIELD", "Name" );
@@ -986,11 +989,15 @@
CPLGetConfigOption ( "LIBKML_EXTRUDE_FIELD", "extrude" );
const char *visibilityfield =
CPLGetConfigOption ( "LIBKML_VISIBILITY_FIELD", "visibility" );
+ const char *drawOrderfield =
+ CPLGetConfigOption ( "LIBKML_DRAWORDER_FIELD", "drawOrder" );
+ const char *iconfield =
+ CPLGetConfigOption ( "LIBKML_ICON_FIELD", "icon" );
/***** name *****/
- if ( poKmlPlacemark->has_name ( ) ) {
- const std::string oKmlName = poKmlPlacemark->get_name ( );
+ if ( poKmlFeature->has_name ( ) ) {
+ const std::string oKmlName = poKmlFeature->get_name ( );
int iField = poOgrFeat->GetFieldIndex ( namefield );
if ( iField > -1 )
@@ -999,17 +1006,17 @@
/***** description *****/
- if ( poKmlPlacemark->has_description ( ) ) {
- const std::string oKmlDesc = poKmlPlacemark->get_description ( );
+ if ( poKmlFeature->has_description ( ) ) {
+ const std::string oKmlDesc = poKmlFeature->get_description ( );
int iField = poOgrFeat->GetFieldIndex ( descfield );
if ( iField > -1 )
poOgrFeat->SetField ( iField, oKmlDesc.c_str ( ) );
}
- if ( poKmlPlacemark->has_timeprimitive ( ) ) {
+ if ( poKmlFeature->has_timeprimitive ( ) ) {
TimePrimitivePtr poKmlTimePrimitive =
- poKmlPlacemark->get_timeprimitive ( );
+ poKmlFeature->get_timeprimitive ( );
/***** timestamp *****/
@@ -1101,7 +1108,10 @@
}
- if ( poKmlPlacemark->has_geometry ( ) ) {
+ /***** placemark *****/
+ PlacemarkPtr poKmlPlacemark = AsPlacemark ( poKmlFeature );
+ GroundOverlayPtr poKmlGroundOverlay = AsGroundOverlay ( poKmlFeature );
+ if ( poKmlPlacemark && poKmlPlacemark->has_geometry ( ) ) {
GeometryPtr poKmlGeometry = poKmlPlacemark->get_geometry ( );
/***** altitudeMode *****/
@@ -1173,12 +1183,76 @@
}
+ /***** ground overlay *****/
+
+ else if ( poKmlGroundOverlay ) {
+
+ /***** icon *****/
+
+ int iField = poOgrFeat->GetFieldIndex ( iconfield );
+ if ( iField > -1 ) {
+
+ if ( poKmlGroundOverlay->has_icon ( ) ) {
+ IconPtr icon = poKmlGroundOverlay->get_icon ( );
+ if ( icon->has_href ( ) ) {
+ poOgrFeat->SetField ( iField, icon->get_href ( ).c_str ( ) );
+ }
+ }
+ }
+
+ /***** drawOrder *****/
+
+
+ iField = poOgrFeat->GetFieldIndex ( drawOrderfield );
+ if ( iField > -1 ) {
+
+ if ( poKmlGroundOverlay->has_draworder ( ) ) {
+ poOgrFeat->SetField ( iField, poKmlGroundOverlay->get_draworder ( ) );
+ }
+ }
+
+ /***** altitudeMode *****/
+
+ iField = poOgrFeat->GetFieldIndex ( altitudeModefield );
+
+ if ( iField > -1 ) {
+
+ if ( poKmlGroundOverlay->has_altitudemode ( ) ) {
+ switch ( poKmlGroundOverlay->get_altitudemode ( ) ) {
+ case kmldom::ALTITUDEMODE_CLAMPTOGROUND:
+ poOgrFeat->SetField ( iField, "clampToGround" );
+ break;
+
+ case kmldom::ALTITUDEMODE_RELATIVETOGROUND:
+ poOgrFeat->SetField ( iField, "relativeToGround" );
+ break;
+
+ case kmldom::ALTITUDEMODE_ABSOLUTE:
+ poOgrFeat->SetField ( iField, "absolute" );
+ break;
+
+ }
+ } else if ( poKmlGroundOverlay->has_gx_altitudemode ( ) ) {
+ switch ( poKmlGroundOverlay->get_gx_altitudemode ( ) ) {
+ case kmldom::GX_ALTITUDEMODE_RELATIVETOSEAFLOOR:
+ poOgrFeat->SetField ( iField, "relativeToSeaFloor" );
+ break;
+
+ case kmldom::GX_ALTITUDEMODE_CLAMPTOSEAFLOOR:
+ poOgrFeat->SetField ( iField, "clampToSeaFloor" );
+ break;
+ }
+ }
+
+ }
+ }
+
/***** visibility *****/
int nVisibility = -1;
- if ( poKmlPlacemark->has_visibility ( ) )
- nVisibility = poKmlPlacemark->get_visibility ( );
+ if ( poKmlFeature->has_visibility ( ) )
+ nVisibility = poKmlFeature->get_visibility ( );
int iField = poOgrFeat->GetFieldIndex ( visibilityfield );
@@ -1187,8 +1261,8 @@
ExtendedDataPtr poKmlExtendedData = NULL;
- if ( poKmlPlacemark->has_extendeddata ( ) ) {
- poKmlExtendedData = poKmlPlacemark->get_extendeddata ( );
+ if ( poKmlFeature->has_extendeddata ( ) ) {
+ poKmlExtendedData = poKmlFeature->get_extendeddata ( );
/***** loop over the schemadata_arrays *****/
diff -b -u libkml_trunk/ogrlibkmlfield.h libkml/ogrlibkmlfield.h
--- libkml_trunk/ogrlibkmlfield.h Fri Jul 6 11:33:40 2012
+++ libkml/ogrlibkmlfield.h Wed Jun 6 14:27:49 2012
@@ -29,6 +29,7 @@
using kmldom::SimpleFieldPtr;
using kmldom::SchemaPtr;
using kmldom::KmlFactory;
+using kmldom::FeaturePtr;
using kmldom::PlacemarkPtr;
/******************************************************************************
@@ -65,7 +66,7 @@
void kml2field (
OGRFeature * poOgrFeat,
- PlacemarkPtr poKmlPlacemark );
+ FeaturePtr poKmlFeature );
/******************************************************************************
function create a simplefield from a FieldDefn
diff -b -u libkml_trunk/ogrlibkmlgeometry.cpp libkml/ogrlibkmlgeometry.cpp
--- libkml_trunk/ogrlibkmlgeometry.cpp Fri Jul 6 11:33:54 2012
+++ libkml/ogrlibkmlgeometry.cpp Wed Jun 13 09:57:15 2012
@@ -33,6 +33,7 @@
using kmldom::KmlFactory;
using kmldom::CoordinatesPtr;
using kmldom::PointPtr;
+using kmldom::LatLonBoxPtr;
using kmldom::LineStringPtr;
using kmldom::LinearRingPtr;
using kmldom::OuterBoundaryIsPtr;
@@ -529,6 +530,37 @@
return poOgrGeometry;
}
+OGRGeometry *kml2geom_rec (
+ LatLonBoxPtr poKmlLatLonBox,
+ OGRSpatialReference *poOgrSRS)
+
+{
+ OGRPolygon *poOgrPolygon;
+ double north, south, east, west;
+ poOgrPolygon = new OGRPolygon ( );
+ if ( !poKmlLatLonBox->has_north ( ) ||
+ !poKmlLatLonBox->has_south ( ) ||
+ !poKmlLatLonBox->has_east ( ) ||
+ !poKmlLatLonBox->has_west ( ) ) {
+
+ return NULL;
+ }
+ north = poKmlLatLonBox->get_north ( );
+ south = poKmlLatLonBox->get_south ( );
+ east = poKmlLatLonBox->get_east ( );
+ west = poKmlLatLonBox->get_west ( );
+ OGRLinearRing* poOgrRing = new OGRLinearRing ( );
+ poOgrRing->addPoint ( north, east, 0.0 );
+ poOgrRing->addPoint ( south, east, 0.0 );
+ poOgrRing->addPoint ( south, west, 0.0 );
+ poOgrRing->addPoint ( north, west, 0.0 );
+ poOgrPolygon->
+ addRingDirectly ( poOgrRing );
+ poOgrPolygon->assignSpatialReference(poOgrSRS);
+
+ return poOgrPolygon;
+}
+
/******************************************************************************
main function to read a kml geometry and translate to ogr
@@ -579,3 +611,42 @@
return poOgrGeometry;
}
+
+OGRGeometry *kml2latlongeom (
+ LatLonBoxPtr poKmlLatLonBox,
+ OGRSpatialReference *poOgrSRS)
+
+{
+
+ /***** get the geometry *****/
+
+ OGRGeometry *poOgrGeometry = kml2geom_rec (poKmlLatLonBox, poOgrSRS);
+
+ /***** split the geometry at the dateline? *****/
+
+ const char *pszWrap = CPLGetConfigOption ( "LIBKML_WRAPDATELINE", "no" );
+ if (CSLTestBoolean(pszWrap)) {
+
+ char **papszTransformOptions = NULL;
+ papszTransformOptions = CSLAddString( papszTransformOptions,
+ "WRAPDATELINE=YES");
+
+ /***** transform *****/
+
+ OGRGeometry *poOgrDstGeometry =
+ OGRGeometryFactory::transformWithOptions(poOgrGeometry,
+ NULL,
+ papszTransformOptions);
+
+ /***** replace the original geom *****/
+
+ if (poOgrDstGeometry) {
+ delete poOgrGeometry;
+ poOgrGeometry = poOgrDstGeometry;
+ }
+
+ CSLDestroy(papszTransformOptions);
+ }
+
+ return poOgrGeometry;
+}
diff -b -u libkml_trunk/ogrlibkmlgeometry.h libkml/ogrlibkmlgeometry.h
--- libkml_trunk/ogrlibkmlgeometry.h Fri Jul 6 11:34:05 2012
+++ libkml/ogrlibkmlgeometry.h Wed Jun 6 14:50:22 2012
@@ -62,3 +62,7 @@
OGRGeometry *kml2geom (
GeometryPtr poKmlGeometry,
OGRSpatialReference *poOgrSRS);
+
+OGRGeometry *kml2latlongeom (
+ LatLonBoxPtr poKmlLatLonBox,
+ OGRSpatialReference *poOgrSRS);
\ No newline at end of file
diff -b -u libkml_trunk/ogrlibkmllayer.cpp libkml/ogrlibkmllayer.cpp
--- libkml_trunk/ogrlibkmllayer.cpp Fri Jul 6 11:34:17 2012
+++ libkml/ogrlibkmllayer.cpp Thu Jul 5 14:18:51 2012
@@ -39,6 +39,7 @@
using kmldom::DocumentPtr;
using kmldom::ContainerPtr;
using kmldom::FeaturePtr;
+using kmldom::GroundOverlayPtr;
using kmldom::KmlPtr;
using kmldom::Kml;
using kmlengine::KmzFile;
@@ -132,6 +133,10 @@
CPLGetConfigOption ( "LIBKML_EXTRUDE_FIELD", "extrude" );
const char *visibilityfield =
CPLGetConfigOption ( "LIBKML_VISIBILITY_FIELD", "visibility" );
+ const char *drawOrderfield =
+ CPLGetConfigOption ( "LIBKML_DRAWORDER_FIELD", "drawOrder" );
+ const char *iconfield =
+ CPLGetConfigOption ( "LIBKML_ICON_FIELD", "icon" );
OGRFieldDefn oOgrFieldName (
namefield,
@@ -187,6 +192,18 @@
m_poOgrFeatureDefn->AddFieldDefn ( &oOgrFieldVisibility );
+ OGRFieldDefn oOgrFieldDrawOrder (
+ drawOrderfield,
+ OFTInteger );
+
+ m_poOgrFeatureDefn->AddFieldDefn ( &oOgrFieldDrawOrder );
+
+ OGRFieldDefn oOgrFieldIcon (
+ iconfield,
+ OFTString );
+
+ m_poOgrFeatureDefn->AddFieldDefn ( &oOgrFieldIcon );
+
/***** get the styles *****/
if ( m_poKmlLayer->IsA ( kmldom::Type_Document ) )
@@ -382,16 +399,25 @@
poKmlFeature = m_poKmlLayer->get_feature_array_at ( iFeature++ );
- } while ( poKmlFeature->Type ( ) != kmldom::Type_Placemark );
+ } while ( poKmlFeature->Type ( ) != kmldom::Type_Placemark &&
+ poKmlFeature->Type ( ) != kmldom::Type_GroundOverlay );
- if ( iFeature <= nFeatures && poKmlFeature
- && poKmlFeature->Type ( ) == kmldom::Type_Placemark ) {
+ if ( iFeature <= nFeatures && poKmlFeature )
+ {
+ if (poKmlFeature->Type ( ) == kmldom::Type_Placemark ) {
poOgrFeature =
kml2feat ( AsPlacemark ( poKmlFeature ), m_poOgrDS, this,
m_poOgrFeatureDefn, m_poOgrSRS );
poOgrFeature->SetFID(nFID ++);
}
+ else if ( poKmlFeature->Type ( ) == kmldom::Type_GroundOverlay ) {
+ poOgrFeature =
+ kmlgroundoverlay2feat ( AsGroundOverlay ( poKmlFeature ), m_poOgrDS, this,
+ m_poOgrFeatureDefn, m_poOgrSRS );
+ poOgrFeature->SetFID(nFID ++);
+ }
+ }
return poOgrFeature;
}
@@ -453,8 +479,8 @@
size_t nKmlFeatures = m_poKmlLayer->get_feature_array_size ( );
for ( iKmlFeature = 0; iKmlFeature < nKmlFeatures; iKmlFeature++ ) {
- if ( m_poKmlLayer->get_feature_array_at ( iKmlFeature )->
- IsA ( kmldom::Type_Placemark ) ) {
+ const kmldom::FeaturePtr& f(m_poKmlLayer->get_feature_array_at ( iKmlFeature ));
+ if ( f->IsA( kmldom::Type_Placemark ) || f->IsA( kmldom::Type_GroundOverlay ) ) {
i++;
}
}