Exemple #1
0
        public void Parse_GeometryCollectionString_SuccessfulParse()
        {
            string          strGeometry = "{ \"type\": \"GeometryCollection\", \"geometries\": [{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0]}, { \"type\": \"LineString\", \"coordinates\": [ [101.0, 0.0], [102.0, 1.0] ]}]}";
            IGeometryObject geometry    = JsonConvert.DeserializeObject <IGeometryObject>(strGeometry, new GeometryConverter());

            Assert.AreEqual(GeoJSONObjectType.GeometryCollection, geometry.Type);
            GeometryCollection geometryCollection = (GeometryCollection)geometry;

            Assert.AreEqual(2, geometryCollection.Geometries.Count);

            // Geometry1 - Point
            Point point = (Point)geometryCollection.Geometries[0];

            GeoJsonAssert.CoordinateAreEqual(100, 0, point.Coordinates);

            // Geometry2 - LineString
            LineString lineString = (LineString)geometryCollection.Geometries[1];

            GeoJsonAssert.CoordinateAreEqual(101, 0, lineString.Coordinates[0]);
            GeoJsonAssert.CoordinateAreEqual(102, 1, lineString.Coordinates[1]);

            // Deserialization without specifying Converter
            GeometryCollection geometryCollection2 = JsonConvert.DeserializeObject <GeometryCollection>(strGeometry);

            Assert.AreEqual(geometryCollection, geometryCollection2);
        }
Exemple #2
0
        public void Parse_MultiPolygonStringWithOnePolygonContainingHole_SuccessfulParse()
        {
            string          strGeometry = "{ \"type\": \"MultiPolygon\", \"coordinates\": [[[[40, 40], [20, 45], [45, 30], [40, 40]]], [[[20, 35], [10, 30], [10, 10], [30, 5], [45, 20], [20, 35]], [[30, 20], [20, 15], [20, 25], [30, 20]]]]}";
            IGeometryObject geometry    = JsonConvert.DeserializeObject <IGeometryObject>(strGeometry, new GeometryConverter());

            Assert.AreEqual(GeoJSONObjectType.MultiPolygon, geometry.Type);
            MultiPolygon multiPolygon = (MultiPolygon)geometry;

            Assert.AreEqual(2, multiPolygon.Coordinates.Count);

            // Polygon1
            GeoJsonAssert.CoordinateAreEqual(40, 40, multiPolygon.Coordinates[0].Coordinates[0].Coordinates[0]);
            GeoJsonAssert.CoordinateAreEqual(20, 45, multiPolygon.Coordinates[0].Coordinates[0].Coordinates[1]);
            GeoJsonAssert.CoordinateAreEqual(45, 30, multiPolygon.Coordinates[0].Coordinates[0].Coordinates[2]);
            GeoJsonAssert.CoordinateAreEqual(40, 40, multiPolygon.Coordinates[0].Coordinates[0].Coordinates[3]);

            // Polygon2
            GeoJsonAssert.CoordinateAreEqual(20, 35, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[0]);
            GeoJsonAssert.CoordinateAreEqual(10, 30, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[1]);
            GeoJsonAssert.CoordinateAreEqual(10, 10, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[2]);
            GeoJsonAssert.CoordinateAreEqual(30, 5, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[3]);
            GeoJsonAssert.CoordinateAreEqual(45, 20, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[4]);
            GeoJsonAssert.CoordinateAreEqual(20, 35, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[5]);

            // Polygon2 - Hole1
            GeoJsonAssert.CoordinateAreEqual(30, 20, multiPolygon.Coordinates[1].Coordinates[1].Coordinates[0]);
            GeoJsonAssert.CoordinateAreEqual(20, 15, multiPolygon.Coordinates[1].Coordinates[1].Coordinates[1]);
            GeoJsonAssert.CoordinateAreEqual(20, 25, multiPolygon.Coordinates[1].Coordinates[1].Coordinates[2]);
            GeoJsonAssert.CoordinateAreEqual(30, 20, multiPolygon.Coordinates[1].Coordinates[1].Coordinates[3]);

            // Deserialization without specifying Converter
            MultiPolygon multiPolygon2 = JsonConvert.DeserializeObject <MultiPolygon>(strGeometry);

            Assert.AreEqual(multiPolygon, multiPolygon2);
        }
Exemple #3
0
        public void Parse_MultiLineString_SuccessfulParse()
        {
            string          strGeometry = "{ \"type\": \"MultiLineString\", \"coordinates\": [[[10, 10], [20, 20], [10, 40]], [[40, 40], [30, 30], [40, 20], [30, 10]]]}";
            IGeometryObject geometry    = JsonConvert.DeserializeObject <IGeometryObject>(strGeometry, new GeometryConverter());

            Assert.AreEqual(GeoJSONObjectType.MultiLineString, geometry.Type);
            MultiLineString multiLineString = (MultiLineString)geometry;

            Assert.AreEqual(2, multiLineString.Coordinates.Count);

            // LineString 1
            GeoJsonAssert.CoordinateAreEqual(10, 10, multiLineString.Coordinates[0].Coordinates[0]);
            GeoJsonAssert.CoordinateAreEqual(20, 20, multiLineString.Coordinates[0].Coordinates[1]);
            GeoJsonAssert.CoordinateAreEqual(10, 40, multiLineString.Coordinates[0].Coordinates[2]);

            // LineString 2
            GeoJsonAssert.CoordinateAreEqual(40, 40, multiLineString.Coordinates[1].Coordinates[0]);
            GeoJsonAssert.CoordinateAreEqual(30, 30, multiLineString.Coordinates[1].Coordinates[1]);
            GeoJsonAssert.CoordinateAreEqual(40, 20, multiLineString.Coordinates[1].Coordinates[2]);
            GeoJsonAssert.CoordinateAreEqual(30, 10, multiLineString.Coordinates[1].Coordinates[3]);

            // Deserialization without specifying Converter
            MultiLineString multiLineString2 = JsonConvert.DeserializeObject <MultiLineString>(strGeometry);

            Assert.AreEqual(multiLineString, multiLineString2);
        }
Exemple #4
0
        public void Parse_PolygonStringWithOneHole_SuccessfulParse()
        {
            const string    strGeometry = "{ \"type\": \"Polygon\", \"coordinates\": [[[35, 10], [45, 45], [15, 40], [10, 20], [35, 10]], [[20, 30], [35, 35], [30, 20], [20, 30]]]}";
            IGeometryObject geometry    = JsonConvert.DeserializeObject <IGeometryObject>(strGeometry, new GeometryConverter());

            Assert.AreEqual(GeoJSONObjectType.Polygon, geometry.Type);
            Polygon polygon = (Polygon)geometry;

            Assert.AreEqual(2, polygon.Coordinates.Count);

            // Outer polygon
            Assert.AreEqual(5, polygon.Coordinates[0].Coordinates.Count);
            GeoJsonAssert.CoordinateAreEqual(35, 10, polygon.Coordinates[0].Coordinates[0]);
            GeoJsonAssert.CoordinateAreEqual(45, 45, polygon.Coordinates[0].Coordinates[1]);
            GeoJsonAssert.CoordinateAreEqual(15, 40, polygon.Coordinates[0].Coordinates[2]);
            GeoJsonAssert.CoordinateAreEqual(10, 20, polygon.Coordinates[0].Coordinates[3]);
            GeoJsonAssert.CoordinateAreEqual(35, 10, polygon.Coordinates[0].Coordinates[4]);

            // Hole one
            Assert.AreEqual(4, polygon.Coordinates[1].Coordinates.Count);
            GeoJsonAssert.CoordinateAreEqual(20, 30, polygon.Coordinates[1].Coordinates[0]);
            GeoJsonAssert.CoordinateAreEqual(35, 35, polygon.Coordinates[1].Coordinates[1]);
            GeoJsonAssert.CoordinateAreEqual(30, 20, polygon.Coordinates[1].Coordinates[2]);
            GeoJsonAssert.CoordinateAreEqual(20, 30, polygon.Coordinates[1].Coordinates[3]);

            // Deserialization without specifying Converter
            Polygon polygon2 = JsonConvert.DeserializeObject <Polygon>(strGeometry);

            Assert.AreEqual(polygon, polygon2);
        }
Exemple #5
0
        public void Parse_FeatureCollectionString_SuccessfulParse()
        {
            // prop1 doesn't parse correctly...
            //
            //"properties": {
            // "prop0": "value0",
            // "prop1": {"this": "that"}
            // }
            //const string strFeatureCollection = "{ \"type\": \"FeatureCollection\", \"features\": [ { \"type\": \"Feature\", \"geometry\": { \"type\": \"Point\", \"coordinates\": [102.0, 0.5]}, \"properties\": { \"prop0\": \"value0\"}}, { \"type\": \"Feature\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]]},\"properties\": {\"prop1\": 0.0,\"prop0\": \"value0\"}},{\"type\": \"Feature\",\"geometry\": {\"type\": \"Polygon\",\"coordinates\": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0],[100.0, 0.0]]]},\"properties\": {\"prop1\": {\"this\": \"that\"},\"prop0\": \"value0\"}}]}";
            const string      strFeatureCollection = "{ \"type\": \"FeatureCollection\", \"features\": [ { \"type\": \"Feature\", \"geometry\": { \"type\": \"Point\", \"coordinates\": [102.0, 0.5]}, \"properties\": { \"prop0\": \"value0\"}}, { \"type\": \"Feature\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]]},\"properties\": {\"prop1\": 0.0,\"prop0\": \"value0\"}},{\"type\": \"Feature\",\"geometry\": {\"type\": \"Polygon\",\"coordinates\": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0],[100.0, 0.0]]]},\"properties\": {\"prop0\": \"value0\"}}]}";
            FeatureCollection featureCollection    = JsonConvert.DeserializeObject <FeatureCollection>(strFeatureCollection);

            Assert.AreEqual(3, featureCollection.Features.Count);

            // Feature1
            Feature feature1 = featureCollection.Features[0];

            Assert.AreEqual(GeoJSONObjectType.Point, feature1.Geometry.Type);
            Point point = (Point)feature1.Geometry;

            GeoJsonAssert.CoordinateAreEqual(102, 0.5, point.Coordinates);
            Assert.AreEqual("value0", feature1.Properties["prop0"]);

            // Feature2
            Feature feature2 = featureCollection.Features[1];

            Assert.AreEqual(GeoJSONObjectType.LineString, feature2.Geometry.Type);
            LineString lineString = (LineString)feature2.Geometry;

            GeoJsonAssert.CoordinateAreEqual(102, 0, lineString.Coordinates[0]);
            GeoJsonAssert.CoordinateAreEqual(103, 1, lineString.Coordinates[1]);
            GeoJsonAssert.CoordinateAreEqual(104, 0, lineString.Coordinates[2]);
            GeoJsonAssert.CoordinateAreEqual(105, 1, lineString.Coordinates[3]);
            Assert.AreEqual(0.0, feature2.Properties["prop1"]);
            Assert.AreEqual("value0", feature2.Properties["prop0"]);

            // Feature3
            Feature feature3 = featureCollection.Features[2];

            Assert.AreEqual(GeoJSONObjectType.Polygon, feature3.Geometry.Type);
            Polygon polygon = (Polygon)feature3.Geometry;

            GeoJsonAssert.CoordinateAreEqual(100, 0, polygon.Coordinates[0].Coordinates[0]);
            GeoJsonAssert.CoordinateAreEqual(101, 0, polygon.Coordinates[0].Coordinates[1]);
            GeoJsonAssert.CoordinateAreEqual(101, 1, polygon.Coordinates[0].Coordinates[2]);
            GeoJsonAssert.CoordinateAreEqual(100, 1, polygon.Coordinates[0].Coordinates[3]);
            GeoJsonAssert.CoordinateAreEqual(100, 0, polygon.Coordinates[0].Coordinates[4]);
            //Assert.AreEqual("that", feature2.Properties["prop1"]);
            Assert.AreEqual("value0", feature2.Properties["prop0"]);
        }
Exemple #6
0
        public void Parse_PointStringWithTypeLast_SuccessfulParse()
        {
            string          strGeometry = "{\"coordinates\": [-105.01621,39.57422], \"type\": \"Point\"}";
            IGeometryObject geometry    = JsonConvert.DeserializeObject <IGeometryObject>(strGeometry, new GeometryConverter());

            Assert.AreEqual(GeoJSONObjectType.Point, geometry.Type);
            Point point = (Point)geometry;

            GeoJsonAssert.CoordinateAreEqual(-105.01621, 39.57422, point.Coordinates);

            // Deserialization without specifying Converter
            Point point2 = JsonConvert.DeserializeObject <Point>(strGeometry);

            Assert.AreEqual(point, point2);
        }
Exemple #7
0
        public void Parse_MultiPointStringWithOneElement_SuccessfulParse()
        {
            string          strGeometry = "{ \"type\": \"MultiPoint\", \"coordinates\": [[10, 40]]}";
            IGeometryObject geometry    = JsonConvert.DeserializeObject <IGeometryObject>(strGeometry, new GeometryConverter());

            Assert.AreEqual(GeoJSONObjectType.MultiPoint, geometry.Type);
            MultiPoint multiPoint = (MultiPoint)geometry;

            Assert.AreEqual(1, multiPoint.Coordinates.Count);
            GeoJsonAssert.CoordinateAreEqual(10, 40, multiPoint.Coordinates[0].Coordinates);

            // Deserialization without specifying Converter
            MultiPoint multiPoint2 = JsonConvert.DeserializeObject <MultiPoint>(strGeometry);

            Assert.AreEqual(multiPoint, multiPoint2);
        }
Exemple #8
0
        public void Parse_LineStringWithThreeElements_SuccessfulParse()
        {
            string          strGeometry = "{ \"type\": \"LineString\", \"coordinates\": [ [30, 10], [10, 30], [40, 40] ]}";
            IGeometryObject geometry    = JsonConvert.DeserializeObject <IGeometryObject>(strGeometry, new GeometryConverter());

            Assert.AreEqual(GeoJSONObjectType.LineString, geometry.Type);
            LineString lineString = (LineString)geometry;

            Assert.AreEqual(3, lineString.Coordinates.Count);
            GeoJsonAssert.CoordinateAreEqual(30, 10, lineString.Coordinates[0]);
            GeoJsonAssert.CoordinateAreEqual(10, 30, lineString.Coordinates[1]);
            GeoJsonAssert.CoordinateAreEqual(40, 40, lineString.Coordinates[2]);

            // Deserialization without specifying Converter
            LineString lineString2 = JsonConvert.DeserializeObject <LineString>(strGeometry);

            Assert.AreEqual(lineString, lineString2);
        }