This project has moved and is read-only. For the latest updates, please go here.

How to cast Features?

Oct 30, 2012 at 3:43 PM

When looping through the Features in a KML file, how do you turn the Feature into the Point, LineString, or Polygon that it actually is in the KML file?

Here is what I have tried:

if (kmlFeature is SharpKml.Dom.Point)
    SharpKml.Dom.Point point = kmlFeature as SharpKml.Dom.Point;
else if (kmlFeature is SharpKml.Dom.LineString)
    SharpKml.Dom.LineString line = kmlFeature as SharpKml.Dom.LineString;
else if (kmlFeature is SharpKml.Dom.Polygon)
    SharpKml.Dom.Polygon polygon = kmlFeature as SharpKml.Dom.Polygon;

When I try that it says "Cannot convert type 'SharpKml.Dom.Feature' to 'SharpKml.Dom.Point' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion".


Oct 31, 2012 at 7:55 AM

The Feature in itself is not a Geometry. The Geometry is a property within the Feature. Some code:


Placemark p = ...

if(p.Geometry is SharpKml.Dom.Point)



Oct 31, 2012 at 10:01 PM

OK, Thanks!