/// <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); }
/// <summary> /// Calculates an overlay of two geographies. /// </summary> /// <param name="geography1">First geography</param> /// <param name="geography2">Second geography</param> /// <param name="operation">Overlay type</param> /// <returns>A resulting overlay of two geographies</returns> public ICollection <IGeography> CalculateOverlay(IGeography geography1, IGeography geography2, OverlayType operation) { if (!(geography1 is GeoPolygon)) { if (!(geography1 is GeoPolyline)) { if (!(geography1 is GeoPoint)) { if (!(geography1 is GeoMultiPoint)) { throw new NotSupportedException(string.Format("Overlay calculations for \"{0}\" is not supported.", geography1.GetType().FullName)); } } } } if (!(geography2 is GeoPolygon)) { if (!(geography2 is GeoPolyline)) { if (!(geography2 is GeoPoint)) { if (!(geography2 is GeoMultiPoint)) { throw new NotSupportedException(string.Format("Overlay calculations for \"{0}\" is not supported.", geography2.GetType().FullName)); } } } } return(calculateOverlay(geography1, geography2, operation, false)); }
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); }
/// <summary> /// Builds a buffer for the specified geography. /// </summary> /// <param name="geography">A geography to build a buffer</param> /// <param name="angleDistance">An angle distance of buffer (in radians)</param> /// <param name="pointsPerCircle">The number of points in a polygon approximating a circle of a point object buffer</param> /// <param name="allowParallels">The value indicating whether the parallel computing will be used when possible</param> /// <returns>A geography that represents the resulting buffer</returns> public static IGeography GetBuffer(IGeography geography, double angleDistance, int pointsPerCircle, bool allowParallels) { if (!(geography is GeoPoint) && !(geography is GeoPolyline) && !(geography is GeoPolygon)) { throw new NotSupportedException("Buffer calculation for \"" + geography.GetType().FullName + "\" is not supported."); } if (angleDistance == 0) { return((IGeography)geography.Clone()); } if (pointsPerCircle <= 2) { throw new ArgumentOutOfRangeException("pointsPerCircle"); } if (geography is GeoPolygon) { return(getPolygonBuffer((GeoPolygon)geography, angleDistance, pointsPerCircle, allowParallels)); } if (angleDistance < 0) { throw new ArgumentException("Buffer value should not be negative for this geography", "distance"); } if (geography is GeoPoint) { return(getPointBuffer((GeoPoint)geography, angleDistance, pointsPerCircle)); } if (geography is GeoPolyline) { return(getPolylineBuffer((GeoPolyline)geography, angleDistance, pointsPerCircle, allowParallels)); } throw new InvalidOperationException("Internal error"); }
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> /// Calculates an overlay of two geographies. /// </summary> /// <param name="geography1">First geography</param> /// <param name="geography2">Second geography</param> /// <param name="operation">Overlay type</param> /// <returns>A resulting overlay of two geographies</returns> public ICollection<IGeography> CalculateOverlay(IGeography geography1, IGeography geography2, OverlayType operation) { if (!(geography1 is GeoPolygon)) if (!(geography1 is GeoPolyline)) if (!(geography1 is GeoPoint)) if (!(geography1 is GeoMultiPoint)) throw new NotSupportedException(string.Format("Overlay calculations for \"{0}\" is not supported.", geography1.GetType().FullName)); if (!(geography2 is GeoPolygon)) if (!(geography2 is GeoPolyline)) if (!(geography2 is GeoPoint)) if (!(geography2 is GeoMultiPoint)) throw new NotSupportedException(string.Format("Overlay calculations for \"{0}\" is not supported.", geography2.GetType().FullName)); return calculateOverlay(geography1, geography2, operation, false); }
/// <summary> /// Calculates a symmetric difference of two geographies. /// </summary> /// <param name="geography1">First geography</param> /// <param name="geography2">Second geography</param> /// <returns>A symmetric difference of two geographies</returns> public ICollection<IGeography> SymmetricDifference(IGeography geography1, IGeography geography2) { return CalculateOverlay(geography1, geography2, OverlayType.SymmetricDifference); }
/// <summary> /// Calculates an intersection of two geographies. /// </summary> /// <param name="geography1">First geography</param> /// <param name="geography2">Second geography</param> /// <returns>An intersection of two geographies</returns> public ICollection<IGeography> Intersection(IGeography geography1, IGeography geography2) { return CalculateOverlay(geography1, geography2, OverlayType.Intersection); }
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; }
/// <summary> /// Calculates a symmetric difference of two geographies. /// </summary> /// <param name="geography1">First geography</param> /// <param name="geography2">Second geography</param> /// <returns>A symmetric difference of two geographies</returns> public ICollection <IGeography> SymmetricDifference(IGeography geography1, IGeography geography2) { return(CalculateOverlay(geography1, geography2, OverlayType.SymmetricDifference)); }
/// <summary> /// Calculates an intersection of two geographies. /// </summary> /// <param name="geography1">First geography</param> /// <param name="geography2">Second geography</param> /// <returns>An intersection of two geographies</returns> public ICollection <IGeography> Intersection(IGeography geography1, IGeography geography2) { return(CalculateOverlay(geography1, geography2, OverlayType.Intersection)); }
/// <summary> /// Initializes a new instance of the <see cref="Geography_InfoViewModel" /> class. /// </summary> /// <param name="dialogService">The Dialog Service.</param> /// <param name="navigationService">The Navigation Service.</param> /// <param name="geography">The Geography.</param> public Geography_InfoViewModel(IDialogService dialogService, INavigationService navigationService, IGeography geography) { _dialogService = dialogService; _navigationService = navigationService; _geography = geography; }
/// <summary> /// Builds a buffer for the specified geography. /// </summary> /// <param name="geography">A geography to build a buffer</param> /// <param name="angleDistance">An angle distance of buffer (in radians)</param> /// <param name="pointsPerCircle">The number of points in a polygon approximating a circle of a point object buffer</param> /// <param name="allowParallels">The value indicating whether the parallel computing will be used when possible</param> /// <returns>A geography that represents the resulting buffer</returns> public static IGeography GetBuffer(IGeography geography, double angleDistance, int pointsPerCircle, bool allowParallels) { if (!(geography is GeoPoint) && !(geography is GeoPolyline) && !(geography is GeoPolygon)) throw new NotSupportedException("Buffer calculation for \"" + geography.GetType().FullName + "\" is not supported."); if (angleDistance == 0) return (IGeography)geography.Clone(); if (pointsPerCircle <= 2) throw new ArgumentOutOfRangeException("pointsPerCircle"); if (geography is GeoPolygon) return getPolygonBuffer((GeoPolygon)geography, angleDistance, pointsPerCircle, allowParallels); if (angleDistance < 0) throw new ArgumentException("Buffer value should not be negative for this geography", "distance"); if (geography is GeoPoint) return getPointBuffer((GeoPoint)geography, angleDistance, pointsPerCircle); if (geography is GeoPolyline) return getPolylineBuffer((GeoPolyline)geography, angleDistance, pointsPerCircle, allowParallels); throw new InvalidOperationException("Internal error"); }
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; }