コード例 #1
0
        public void TestFeatureSerialization()
        {
            // a feature with a point.
            var geometry = (Geometry)new Point(new GeoCoordinate(0, 1));
            var feature = new Feature(geometry);

            var serialized = feature.ToGeoJson();
            serialized = serialized.RemoveWhitespace();

            Assert.AreEqual("{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.0,0.0]}}",
                serialized);

            feature = new Feature(geometry, new SimpleGeometryAttributeCollection(new GeometryAttribute[]
            {
                new GeometryAttribute()
                {
                    Key = "key1",
                    Value = "value1"
                }
            }));

            serialized = feature.ToGeoJson();
            serialized = serialized.RemoveWhitespace();

            Assert.AreEqual("{\"type\":\"Feature\",\"properties\":{\"key1\":\"value1\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.0,0.0]}}",
                serialized);

            // a feature with a linestring.
            geometry = new LineString(
                new GeoCoordinate[]
                {
                    new GeoCoordinate(0, 0),
                    new GeoCoordinate(0, 1),
                    new GeoCoordinate(1, 1),
                    new GeoCoordinate(1, 0)
                });
            feature = new Feature(geometry);

            serialized = feature.ToGeoJson();
            serialized = serialized.RemoveWhitespace();

            Assert.AreEqual("{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0]]}}",
                serialized);

            // a featurer with a linearring.
            geometry = new LineairRing(
                new GeoCoordinate[]
                {
                    new GeoCoordinate(0, 0),
                    new GeoCoordinate(0, 1),
                    new GeoCoordinate(1, 1),
                    new GeoCoordinate(1, 0),
                    new GeoCoordinate(0, 0)
                });
            feature = new Feature(geometry);

            serialized = feature.ToGeoJson();
            serialized = serialized.RemoveWhitespace();

            Assert.AreEqual("{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]]]}}",
                serialized);

            // a featurer with a polygon.
            geometry = new Polygon(new LineairRing(
                new GeoCoordinate[]
                {
                    new GeoCoordinate(0, 0),
                    new GeoCoordinate(0, 1),
                    new GeoCoordinate(1, 1),
                    new GeoCoordinate(1, 0),
                    new GeoCoordinate(0, 0)
                }));
            feature = new Feature(geometry);

            serialized = feature.ToGeoJson();
            serialized = serialized.RemoveWhitespace();

            Assert.AreEqual("{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]]]}}",
                serialized);
        }