Inheritance: Geo.Abstractions.OgcGeometry, ISurface, IGeoJsonGeometry
Exemple #1
0
 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));
 }
Exemple #2
0
        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 ) );
        }
Exemple #3
0
        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 ) );
        }
Exemple #4
0
        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;
        }
Exemple #5
0
        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(")");
        }
Exemple #6
0
 private void AppendPolygon(StringBuilder builder, Polygon polygon)
 {
     builder.Append("POLYGON");
     AppendDimensions(builder, polygon);
     builder.Append(" ");
     AppendPolygonInner(builder, polygon);
 }
Exemple #7
0
        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);
            }
        }
Exemple #8
0
 private void WritePolygon(Polygon polygon, WkbBinaryWriter writer)
 {
     WriteEncoding(writer, _settings.Encoding);
     WriteGeometryType(polygon, WkbGeometryType.Polygon, writer);
     WritePolygonInner(polygon, writer);
 }
Exemple #9
0
 private void WritePolygon(Polygon polygon, WkbBinaryWriter writer)
 {
     WriteGeometryType(polygon, WkbGeometryType.Polygon, writer);
     WritePolygonInner(polygon, writer);
 }
Exemple #10
0
 private IEnumerable<IEnumerable<double[]>> WriteCoordinates(Polygon polygon)
 {
     yield return WriteCoordinates(polygon.Shell.Coordinates);
     foreach (var hole in polygon.Holes)
         yield return WriteCoordinates(hole.Coordinates);
 }
Exemple #11
0
 private Dictionary<string, object> WritePolygon(Polygon polygon)
 {
     return new Dictionary<string, object>
     {
         { "type", "Polygon" },
         { "coordinates", WriteCoordinates(polygon) }
     };
 }
Exemple #12
0
 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()));
 }