private static GeoPolygon getPolygonBuffer(GeoPolygon geoPolygon, double angleDistance, int pointsPerCircle, bool allowParallels) { geoPolygon = (GeoPolygon)geoPolygon.Clone(); double minAngle = Math.Sin(Math.Abs(angleDistance)) * Math.Sin(Math.PI / pointsPerCircle); geoPolygon.ReduceSegments(minAngle); geoPolygon.Densify(minAngle); GnomonicProjection projection; IGeometry geometry; projectGeography(geoPolygon, out projection, out geometry); Polygon planePolygon = (Polygon)geometry; Polygon boundaryBuffer = getBoundsBuffer(geoPolygon, projection, angleDistance, pointsPerCircle, allowParallels); ICollection <IGeometry> result; if (angleDistance > 0) { result = planePolygon.Union(boundaryBuffer); } else { result = planePolygon.Difference(boundaryBuffer); } GeographyCollection geographyCollection = GeometrySpreader.GetGeographies(result, projection); foreach (IGeography g in geographyCollection) { if (g is GeoPolygon) { return((GeoPolygon)g); } } return(new GeoPolygon()); }
private static GeoPolygon getPolygonBuffer(GeoPolygon geoPolygon, double angleDistance, int pointsPerCircle, bool allowParallels) { geoPolygon = (GeoPolygon)geoPolygon.Clone(); double minAngle = Math.Sin(Math.Abs(angleDistance)) * Math.Sin(Math.PI / pointsPerCircle); geoPolygon.ReduceSegments(minAngle); geoPolygon.Densify(minAngle); GnomonicProjection projection; IGeometry geometry; projectGeography(geoPolygon, out projection, out geometry); Polygon planePolygon = (Polygon)geometry; Polygon boundaryBuffer = getBoundsBuffer(geoPolygon, projection, angleDistance, pointsPerCircle, allowParallels); ICollection<IGeometry> result; if (angleDistance > 0) result = planePolygon.Union(boundaryBuffer); else result = planePolygon.Difference(boundaryBuffer); GeographyCollection geographyCollection = GeometrySpreader.GetGeographies(result, projection); foreach (IGeography g in geographyCollection) if (g is GeoPolygon) return (GeoPolygon)g; return new GeoPolygon(); }