How to cast Features?

Oct 30, 2012 at 2: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".

Thanks.

Developer
Oct 31, 2012 at 6: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 9:01 PM

OK, Thanks!