/// <summary> /// Converts a collection of geometric shapes on the surface of the ellipsoid /// to the collection of geometric figures in the plane in line with the given projection. /// </summary> /// <param name="geometries">Enumerator geometric shapes on the surface of the ellipsoid</param> /// <param name="projection">Projection</param> /// <returns>Collection of geometric figures in the plane</returns> public static GeographyCollection GetGeographies(IEnumerable <IGeometry> geometries, GnomonicProjection projection) { GeographyCollection result = new GeographyCollection(); IGeography geometry = null; foreach (IGeometry g in geometries) { if (g is PointD) { geometry = unprojectPoint((PointD)g, projection); } else if (g is Polyline) { geometry = unprojectPolyline((Polyline)g, projection); } else if (g is Polygon) { geometry = unprojectPolygon((Polygon)g, projection); } else if (g is MultiPoint) { geometry = unprojectMultiPoint((MultiPoint)g, projection); } else { throw new NotImplementedException("Geometry \"" + g.GetType().FullName + "\" is not supported."); } result.Add(geometry); } return(result); }
private ICollection <IGeography> calculateOverlay(IGeography geometry1, IGeography geometry2, OverlayType operation, bool p) { GeographyCollection egc = new GeographyCollection(); egc.Add(geometry1); egc.Add(geometry2); GnomonicProjection projection = GeometrySpreader.GetProjection(egc); GeometryCollection gc = GeometrySpreader.GetGeometries(egc, projection); OverlayCalculator oc = new OverlayCalculator(); ICollection <IGeometry> planarResult = oc.CalculateOverlay(gc[0], gc[1], operation); egc = GeometrySpreader.GetGeographies(planarResult, projection); return(egc); }
private static Polygon getBoundsBuffer(GeoPolygon polygon, GnomonicProjection projection, double distance, int pointsPerCircle, bool allowParallels) { Polygon temp = new Polygon(); List <Polygon> partialBuffers = new List <Polygon>(); GeographyCollection geographyCollection = new GeographyCollection(); ICollection <IGeometry> unionResult = null; int c = 0; foreach (GeoContour contour in polygon.Contours) { for (int i = 0; i < contour.Vertices.Count; i++) { GeoPoint p = contour.Vertices[i]; GeoPolygon tempPolygon = getPointBuffer(p, Math.Abs(distance), pointsPerCircle); geographyCollection.Clear(); geographyCollection.Add(tempPolygon); GeometryCollection gc = GeometrySpreader.GetGeometries(geographyCollection, projection); if (gc[0] is Polygon) { unionResult = temp.Union((Polygon)gc[0]); } if (unionResult.Count > 0) { temp = (Polygon)((GeometryCollection)unionResult)[0]; } c++; if (c == 3) { partialBuffers.Add(temp); temp = new Polygon(); c = 0; } } } if (temp.CoordinateCount > 0) { partialBuffers.Add(temp); } return(mergePartialBuffers(partialBuffers, allowParallels)); }
private static void projectGeography(IGeography geography, out GnomonicProjection projection, out IGeometry geometry) { GeographyCollection geographyCollection = new GeographyCollection(); geographyCollection.Add(geography); double centerLatitude, centerLongitude; GnomonicProjection.GetCenter(geography.ExtractPoints(), out centerLatitude, out centerLongitude); projection = new GnomonicProjection(centerLongitude, centerLatitude); GeometryCollection geometryCollection = GeometrySpreader.GetGeometries(geographyCollection, projection); if (geometryCollection.Count > 0) { geometry = geometryCollection[0]; } else { geometry = null; } }
/// <summary> /// Computes a convex hull of the specified points. /// </summary> /// <param name="points">Enumerator of coordinates for which convex hull should be computed</param> /// <returns>A list containing a sequence of the convex hull points</returns> public static IList <GeoPoint> GetConvexHull(IEnumerable <GeoPoint> points) { GeographyCollection geographyCollection = new GeographyCollection(); foreach (GeoPoint p in points) { geographyCollection.Add(p); } GnomonicProjection projection = GeometrySpreader.GetProjection(geographyCollection); GeometryCollection geometryCollection = GeometrySpreader.GetGeometries(geographyCollection, projection); List <ICoordinate> list = new List <ICoordinate>(); foreach (IGeometry g in geometryCollection) { list.Add(((PointD)g).Coordinate); } IList <ICoordinate> planarResult = PlanimetryAlgorithms.GetConvexHull(list); geometryCollection.Clear(); foreach (ICoordinate p in planarResult) { geometryCollection.Add(new PointD(p)); } geographyCollection = GeometrySpreader.GetGeographies(geometryCollection, projection); List <GeoPoint> result = new List <GeoPoint>(); foreach (GeoPoint p in geographyCollection) { result.Add(p); } return(result); }
private static GeoPolygon getPolylineBuffer(GeoPolyline geoPolyline, double angleDistance, int pointsPerCircle, bool allowParallels) { geoPolyline = (GeoPolyline)geoPolyline.Clone(); double minAngle = Math.Sin(Math.Abs(angleDistance)) * Math.Sin(Math.PI / pointsPerCircle); geoPolyline.ReduceSegments(minAngle); geoPolyline.Densify(minAngle); GnomonicProjection projection; IGeometry geometry; projectGeography(geoPolyline, out projection, out geometry); Polyline planePolyline = (Polyline)geometry; GeographyCollection geographyCollection = new GeographyCollection(); Polygon temp = new Polygon(); List <Polygon> partialBuffers = new List <Polygon>(); ICollection <IGeometry> unionResult = null; int c = 0; foreach (GeoPath path in geoPolyline.Paths) { for (int i = 0; i < path.Vertices.Count - 1; i++) { GeoPoint p = path.Vertices[i]; GeoPolygon tempPolygon = getPointBuffer(p, angleDistance, pointsPerCircle); geographyCollection.Clear(); geographyCollection.Add(tempPolygon); GeometryCollection gc = GeometrySpreader.GetGeometries(geographyCollection, projection); if (gc[0] is Polygon) { unionResult = temp.Union((Polygon)gc[0]); } if (unionResult.Count > 0) { temp = (Polygon)((GeometryCollection)unionResult)[0]; } c++; if (c == 3) { partialBuffers.Add(temp); temp = new Polygon(); c = 0; } } } if (temp.CoordinateCount > 0) { partialBuffers.Add(temp); } Polygon planeBuffer = mergePartialBuffers(partialBuffers, allowParallels); GeometryCollection geometryCollection = new GeometryCollection(); geometryCollection.Add(planeBuffer); geographyCollection = GeometrySpreader.GetGeographies(geometryCollection, projection); foreach (IGeography g in geographyCollection) { if (g is GeoPolygon) { return((GeoPolygon)g); } } return(new GeoPolygon()); }
/// <summary> /// Computes a convex hull of the specified points. /// </summary> /// <param name="points">Enumerator of coordinates for which convex hull should be computed</param> /// <returns>A list containing a sequence of the convex hull points</returns> public static IList<GeoPoint> GetConvexHull(IEnumerable<GeoPoint> points) { GeographyCollection geographyCollection = new GeographyCollection(); foreach (GeoPoint p in points) geographyCollection.Add(p); GnomonicProjection projection = GeometrySpreader.GetProjection(geographyCollection); GeometryCollection geometryCollection = GeometrySpreader.GetGeometries(geographyCollection, projection); List<ICoordinate> list = new List<ICoordinate>(); foreach(IGeometry g in geometryCollection) list.Add(((PointD)g).Coordinate); IList<ICoordinate> planarResult = PlanimetryAlgorithms.GetConvexHull(list); geometryCollection.Clear(); foreach (ICoordinate p in planarResult) geometryCollection.Add(new PointD(p)); geographyCollection = GeometrySpreader.GetGeographies(geometryCollection, projection); List<GeoPoint> result = new List<GeoPoint>(); foreach (GeoPoint p in geographyCollection) result.Add(p); return result; }
/// <summary> /// Converts a collection of geometric shapes on the surface of the ellipsoid /// to the collection of geometric figures in the plane in line with the given projection. /// </summary> /// <param name="geometries">Enumerator geometric shapes on the surface of the ellipsoid</param> /// <param name="projection">Projection</param> /// <returns>Collection of geometric figures in the plane</returns> public static GeographyCollection GetGeographies(IEnumerable<IGeometry> geometries, GnomonicProjection projection) { GeographyCollection result = new GeographyCollection(); IGeography geometry = null; foreach (IGeometry g in geometries) { if (g is PointD) { geometry = unprojectPoint((PointD)g, projection); } else if (g is Polyline) { geometry = unprojectPolyline((Polyline)g, projection); } else if (g is Polygon) { geometry = unprojectPolygon((Polygon)g, projection); } else if (g is MultiPoint) { geometry = unprojectMultiPoint((MultiPoint)g, projection); } else throw new NotImplementedException("Geometry \"" + g.GetType().FullName + "\" is not supported."); result.Add(geometry); } return result; }
private ICollection<IGeography> calculateOverlay(IGeography geometry1, IGeography geometry2, OverlayType operation, bool p) { GeographyCollection egc = new GeographyCollection(); egc.Add(geometry1); egc.Add(geometry2); GnomonicProjection projection = GeometrySpreader.GetProjection(egc); GeometryCollection gc = GeometrySpreader.GetGeometries(egc, projection); OverlayCalculator oc = new OverlayCalculator(); ICollection<IGeometry> planarResult = oc.CalculateOverlay(gc[0], gc[1], operation); egc = GeometrySpreader.GetGeographies(planarResult, projection); return egc; }
private static GeoPolygon getPolylineBuffer(GeoPolyline geoPolyline, double angleDistance, int pointsPerCircle, bool allowParallels) { geoPolyline = (GeoPolyline)geoPolyline.Clone(); double minAngle = Math.Sin(Math.Abs(angleDistance)) * Math.Sin(Math.PI / pointsPerCircle); geoPolyline.ReduceSegments(minAngle); geoPolyline.Densify(minAngle); GnomonicProjection projection; IGeometry geometry; projectGeography(geoPolyline, out projection, out geometry); Polyline planePolyline = (Polyline)geometry; GeographyCollection geographyCollection = new GeographyCollection(); Polygon temp = new Polygon(); List<Polygon> partialBuffers = new List<Polygon>(); ICollection<IGeometry> unionResult = null; int c = 0; foreach (GeoPath path in geoPolyline.Paths) { for (int i = 0; i < path.Vertices.Count - 1; i++) { GeoPoint p = path.Vertices[i]; GeoPolygon tempPolygon = getPointBuffer(p, angleDistance, pointsPerCircle); geographyCollection.Clear(); geographyCollection.Add(tempPolygon); GeometryCollection gc = GeometrySpreader.GetGeometries(geographyCollection, projection); if (gc[0] is Polygon) unionResult = temp.Union((Polygon)gc[0]); if (unionResult.Count > 0) temp = (Polygon)((GeometryCollection)unionResult)[0]; c++; if (c == 3) { partialBuffers.Add(temp); temp = new Polygon(); c = 0; } } } if (temp.CoordinateCount > 0) partialBuffers.Add(temp); Polygon planeBuffer = mergePartialBuffers(partialBuffers, allowParallels); GeometryCollection geometryCollection = new GeometryCollection(); geometryCollection.Add(planeBuffer); geographyCollection = GeometrySpreader.GetGeographies(geometryCollection, projection); foreach (IGeography g in geographyCollection) if (g is GeoPolygon) return (GeoPolygon)g; return new GeoPolygon(); }
private static void projectGeography(IGeography geography, out GnomonicProjection projection, out IGeometry geometry) { GeographyCollection geographyCollection = new GeographyCollection(); geographyCollection.Add(geography); double centerLatitude, centerLongitude; GnomonicProjection.GetCenter(geography.ExtractPoints(), out centerLatitude, out centerLongitude); projection = new GnomonicProjection(centerLongitude, centerLatitude); GeometryCollection geometryCollection = GeometrySpreader.GetGeometries(geographyCollection, projection); if (geometryCollection.Count > 0) geometry = geometryCollection[0]; else geometry = null; }
private static Polygon getBoundsBuffer(GeoPolygon polygon, GnomonicProjection projection, double distance, int pointsPerCircle, bool allowParallels) { Polygon temp = new Polygon(); List<Polygon> partialBuffers = new List<Polygon>(); GeographyCollection geographyCollection = new GeographyCollection(); ICollection<IGeometry> unionResult = null; int c = 0; foreach (GeoContour contour in polygon.Contours) { for (int i = 0; i < contour.Vertices.Count; i++) { GeoPoint p = contour.Vertices[i]; GeoPolygon tempPolygon = getPointBuffer(p, Math.Abs(distance), pointsPerCircle); geographyCollection.Clear(); geographyCollection.Add(tempPolygon); GeometryCollection gc = GeometrySpreader.GetGeometries(geographyCollection, projection); if(gc[0] is Polygon) unionResult = temp.Union((Polygon)gc[0]); if (unionResult.Count > 0) temp = (Polygon)((GeometryCollection)unionResult)[0]; c++; if (c == 3) { partialBuffers.Add(temp); temp = new Polygon(); c = 0; } } } if (temp.CoordinateCount > 0) partialBuffers.Add(temp); return mergePartialBuffers(partialBuffers, allowParallels); }