public void PolygonTests() { var polygon = new Polygon(new LinearRing(new[] { new Coordinate(0, 0), new Coordinate(5, 0), new Coordinate(0, 5) })); Console.WriteLine(polygon.ToWktString()); AssertThatIndexPropertyIsGenerated(polygon); AssertTrue(polygon, SpatialRelation.Within, new Circle(0, 0, 600000)); AssertFalse(polygon, SpatialRelation.Within, new Circle(0, 160, 600000)); AssertTrue(polygon, SpatialRelation.Intersects, new Circle(0, 0, 110000)); AssertFalse(polygon, SpatialRelation.Intersects, new Circle(0, 160, 110000)); }
public void PointOutsidePolygon() { var bermudaTriangle = new Polygon( new Coordinate( 25.774, -80.190 ), new Coordinate( 18.446, -66.118 ), new Coordinate( 32.321, -64.757 ), new Coordinate( 25.774, -80.190 ) ); var point = new Coordinate( 25.282622, -80.433723 ); Assert.IsFalse( bermudaTriangle.Contains( point ) ); }
public void PointInsidePolygon() { var bermudaTriangle = new Polygon( new Coordinate( 25.774, -80.190 ), new Coordinate( 18.446, -66.118 ), new Coordinate( 32.321, -64.757 ), new Coordinate( 25.774, -80.190 ) ); var point = new Coordinate( 25.123574, -76.149055 ); Assert.IsTrue( bermudaTriangle.Contains( point ) ); }
private bool TryParsePolygon(JsonObject obj, out object result) { var coordinates = obj["coordinates"] as JsonArray; Coordinate[][] temp; if (coordinates != null && coordinates.Count > 0 && TryParseCoordinateArrayArray(coordinates, out temp)) { result = new Polygon(new LinearRing(temp[0]), temp.Skip(1).Select(x => new LinearRing(x))); return true; } result = null; return false; }
private void AppendPolygonInner(StringBuilder builder, Polygon polygon) { if (polygon.IsEmpty) { builder.Append("EMPTY"); return; } builder.Append("("); AppendLineStringInner(builder, polygon.Shell.Coordinates); for (var i = 0; i < polygon.Holes.Count; i++) { builder.Append(", "); AppendLineStringInner(builder, polygon.Holes[i].Coordinates); } builder.Append(")"); }
private void AppendPolygon(StringBuilder builder, Polygon polygon) { builder.Append("POLYGON"); AppendDimensions(builder, polygon); builder.Append(" "); AppendPolygonInner(builder, polygon); }
private void WritePolygonInner(Polygon polygon, WkbBinaryWriter writer) { if (polygon.IsEmpty) { writer.Write(0u); } else { writer.Write((uint)(1 + polygon.Holes.Count)); WriteCoordinates(polygon.Shell.Coordinates, writer); foreach (var hole in polygon.Holes) WriteCoordinates(hole.Coordinates, writer); } }
private void WritePolygon(Polygon polygon, WkbBinaryWriter writer) { WriteEncoding(writer, _settings.Encoding); WriteGeometryType(polygon, WkbGeometryType.Polygon, writer); WritePolygonInner(polygon, writer); }
private void WritePolygon(Polygon polygon, WkbBinaryWriter writer) { WriteGeometryType(polygon, WkbGeometryType.Polygon, writer); WritePolygonInner(polygon, writer); }
private IEnumerable<IEnumerable<double[]>> WriteCoordinates(Polygon polygon) { yield return WriteCoordinates(polygon.Shell.Coordinates); foreach (var hole in polygon.Holes) yield return WriteCoordinates(hole.Coordinates); }
private Dictionary<string, object> WritePolygon(Polygon polygon) { return new Dictionary<string, object> { { "type", "Polygon" }, { "coordinates", WriteCoordinates(polygon) } }; }
public void Polygon() { var reader = new GeoJsonReader(); var geo = new Polygon(new LinearRing(new Coordinate(0, 0), new Coordinate(1, 1), new Coordinate(2, 0), new Coordinate(0, 0))); Assert.AreEqual(@"{""type"":""Polygon"",""coordinates"":[[[0,0],[1,1],[0,2],[0,0]]]}", geo.ToGeoJson()); Assert.AreEqual(geo, reader.Read(geo.ToGeoJson())); }