/// <summary> /// Checks first coordinate in Geography to see if it contains a valid altitude /// </summary> /// <returns>A boolean indicating if the Shape has a valid altitude</returns> public bool Is3D() { if (this is Point) { return((this as Point).Coordinate.Altitude.HasValue); } else if (this is LineString) { LineString l = (this as LineString); if (l.Vertices.Count > 0) { return(l.Vertices[0].Altitude.HasValue); } return(false); } else if (this is Polygon) { Polygon p = (this as Polygon); if (p.ExteriorRing.Count > 0) { return(p.ExteriorRing[0].Altitude.HasValue); } return(false); } else if (this is MultiPoint) { MultiPoint mp = (this as MultiPoint); if (mp.Geometries.Count > 0) { return(mp.Geometries[0].Coordinate.Altitude.HasValue); } return(false); } else if (this is MultiLineString) { MultiLineString ml = (this as MultiLineString); if (ml.Geometries.Count > 0 && ml.Geometries[0].Vertices.Count > 0) { return(ml.Geometries[0].Vertices[0].Altitude.HasValue); } return(false); } else if (this is MultiPolygon) { MultiPolygon mp = (this as MultiPolygon); if (mp.Geometries.Count > 0 && mp.Geometries[0].ExteriorRing.Count > 0) { return(mp.Geometries[0].ExteriorRing[0].Altitude.HasValue); } return(false); } else if (this is GeometryCollection) { var gc = (this as GeometryCollection); if (gc.Geometries.Count > 0) { return(gc.Geometries[0].Is3D()); } return(false); } return(false); }
/// <summary> /// Returns an approximation of the given Geometry instance produced by /// running polylines and polygons through the vertex reduction algorithm. /// /// The following Geometries are not reduced: /// - Point /// - MultiPoint /// - BoundingBox /// </summary> /// <param name="tolerance"> /// A tolerance is the closest distnace any two points can be /// to each other. The tolerance must be a positive number. /// </param> public async Task Reduce(double tolerance) { if (this is LineString) { LineString l = this as LineString; l.Vertices = await SpatialTools.VertexReductionAsync(l.Vertices, tolerance); } else if (this is Polygon) { Polygon p = this as Polygon; //reduce the extrior ring p.ExteriorRing = await SpatialTools.VertexReductionAsync(p.ExteriorRing, tolerance); //Reduce the interior rings for (int i = 0; i < p.InteriorRings.Count; i++) { p.InteriorRings[i] = await SpatialTools.VertexReductionAsync(p.InteriorRings[i], tolerance); } //Makes sure polygon is valid await p.MakeValidAsync(); } else if (this is MultiLineString) { MultiLineString ml = this as MultiLineString; for (int i = 0; i < ml.Geometries.Count; i++) { ml.Geometries[i].Vertices = await SpatialTools.VertexReductionAsync(ml.Geometries[i].Vertices, tolerance); } } else if (this is MultiPolygon) { MultiPolygon mp = this as MultiPolygon; for (int i = 0; i < mp.Geometries.Count; i++) { //reduce the extrior ring mp.Geometries[i].ExteriorRing = await SpatialTools.VertexReductionAsync(mp.Geometries[i].ExteriorRing, tolerance); //Reduce the interior rings for (int j = 0; j < mp.Geometries[i].InteriorRings.Count; j++) { mp.Geometries[i].InteriorRings[j] = await SpatialTools.VertexReductionAsync(mp.Geometries[i].InteriorRings[j], tolerance); } //Makes sure polygon is valid await mp.Geometries[i].MakeValidAsync(); } } else if (this is GeometryCollection) { GeometryCollection gc = this as GeometryCollection; foreach (Geometry g in gc) { await g.Reduce(tolerance); } } }