private static Envelope ExtractEnvelope(XElement geomElement)
{
if (geomElement == null)
return null;
XNamespace kmlNS = geomElement.Name.Namespace;
double? north = null, south = null, east = null, west = null;
double temp;
XElement boundary;
// Extract box values
boundary = geomElement.Element(kmlNS + "north");
if (boundary != null)
{
if (double.TryParse(boundary.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out temp))
north = temp;
}
boundary = geomElement.Element(kmlNS + "south");
if (boundary != null)
{
if (double.TryParse(boundary.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out temp))
south = temp;
}
boundary = geomElement.Element(kmlNS + "east");
if (boundary != null)
{
if (double.TryParse(boundary.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out temp))
east = temp;
}
boundary = geomElement.Element(kmlNS + "west");
if (boundary != null)
{
if (double.TryParse(boundary.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out temp))
west = temp;
}
return north.HasValue && south.HasValue && east.HasValue && west.HasValue
? new Envelope(west.Value, south.Value, east.Value, north.Value) { SpatialReference = new SpatialReference(4326)}
: null;
}