public static bool GetIsIntersects(GeographyPoint point, GeographyPolygon polygon) { if (point == null) { throw new ArgumentNullException("point"); } if (polygon == null) { throw new ArgumentNullException("polygon"); } return point.Intersects(polygon).Value; }
static ODataSpatialTypeUtil() { // Geometry type values. GeometryValue = GeometryFactory.Point(32.0, -10.0).Build(); GeometryPointValue = GeometryFactory.Point(33.1, -11.0).Build(); GeometryLineStringValue = GeometryFactory.LineString(33.1, -11.5).LineTo(35.97, -11).Build(); GeometryPolygonValue = GeometryFactory.Polygon().Ring(33.1, -13.6).LineTo(35.97, -11.15).LineTo(11.45, 87.75).Ring(35.97, -11).LineTo(36.97, -11.15).LineTo(45.23, 23.18).Build(); GeometryCollectionValue = GeometryFactory.Collection().Point(-19.99, -12.0).Build(); GeometryMultiPointValue = GeometryFactory.MultiPoint().Point(10.2, 11.2).Point(11.9, 11.6).Build(); GeometryMultiLineStringValue = GeometryFactory.MultiLineString().LineString(10.2, 11.2).LineTo(11.9, 11.6).LineString(16.2, 17.2).LineTo(18.9, 19.6).Build(); GeometryMultiPolygonValue = GeometryFactory.MultiPolygon().Polygon().Ring(10.2, 11.2).LineTo(11.9, 11.6).LineTo(11.45, 87.75).Ring(16.2, 17.2).LineTo(18.9, 19.6).LineTo(11.45, 87.75).Build(); // Geography type values. GeographyValue = GeographyFactory.Point(32.0, -100.0).Build(); GeographyPointValue = GeographyFactory.Point(33.1, -110.0).Build(); GeographyLineStringValue = GeographyFactory.LineString(33.1, -110.0).LineTo(35.97, -110).Build(); GeographyPolygonValue = GeographyFactory.Polygon().Ring(33.1, -110.0).LineTo(35.97, -110.15).LineTo(11.45, 87.75).Ring(35.97, -110).LineTo(36.97, -110.15).LineTo(45.23, 23.18).Build(); GeographyCollectionValue = GeographyFactory.Collection().Point(-19.99, -12.0).Build(); GeographyMultiPointValue = GeographyFactory.MultiPoint().Point(10.2, 11.2).Point(11.9, 11.6).Build(); GeographyMultiLineStringValue = GeographyFactory.MultiLineString().LineString(10.2, 11.2).LineTo(11.9, 11.6).LineString(16.2, 17.2).LineTo(18.9, 19.6).Build(); GeographyMultiPolygonValue = GeographyFactory.MultiPolygon().Polygon().Ring(10.2, 11.2).LineTo(11.9, 11.6).LineTo(11.45, 87.75).Ring(16.2, 17.2).LineTo(18.9, 19.6).LineTo(11.45, 87.75).Build(); }
public bool Equals(GeographyPolygon other) { return(this.BaseEquals(other) ?? this.Rings.SequenceEqual(other.Rings)); }
private IEnumerable<Customer> DoGeoIntersections(IEnumerable<Customer> customers, IEdmProperty property, GeographyPolygon polygon) { PropertyInfo propertyInfo = typeof(Customer).GetProperty(property.Name); foreach (var customer in customers) { GeographyPoint point = propertyInfo.GetValue(customer) as GeographyPoint; if (point == null) { continue; } bool isIntersection = IsIntersection(point, polygon); if (isIntersection) { yield return customer; } } }
// just for simplicity, assume: // it's x-y plane // polygon hasn't inner rings, it is a rectangle private bool IsIntersection(GeographyPoint point, GeographyPolygon polygon) { var outRing = polygon.Rings.First(); //int pointNum = outRing.Points.Count; double maxLat = double.MinValue; double maxLon = double.MinValue; double minLat = double.MaxValue; double minLon = double.MaxValue; foreach (var pt in outRing.Points) { if (maxLat < pt.Latitude) { maxLat = pt.Latitude; } if (maxLon < pt.Longitude) { maxLon = pt.Longitude; } if (minLat > pt.Latitude) { minLat = pt.Latitude; } if (minLon > pt.Longitude) { minLon = pt.Longitude; } } if (point.Latitude < minLat || point.Latitude > maxLat || point.Longitude < minLon || point.Longitude > maxLon) return false; return true; }
public bool Equals(GeographyPolygon other) { return this.BaseEquals(other) ?? this.Rings.SequenceEqual(other.Rings); }