Example #1
0
        public virtual void TestGeometryCollection()
        {
            com.epl.geometry.SpatialReference sr         = com.epl.geometry.SpatialReference.Create(4326);
            System.Text.StringBuilder         geometrySb = new System.Text.StringBuilder();
            geometrySb.Append("{\"type\" : \"GeometryCollection\", \"geometries\" : [");
            com.epl.geometry.ogc.OGCPoint point = new com.epl.geometry.ogc.OGCPoint(new com.epl.geometry.Point(1.0, 1.0), sr);
            NUnit.Framework.Assert.AreEqual("{\"x\":1,\"y\":1,\"spatialReference\":{\"wkid\":4326}}", point.AsJson());
            NUnit.Framework.Assert.AreEqual("{\"type\":\"Point\",\"coordinates\":[1,1],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", point.AsGeoJson());
            geometrySb.Append(point.AsGeoJson()).Append(", ");
            com.epl.geometry.ogc.OGCLineString line = new com.epl.geometry.ogc.OGCLineString(new com.epl.geometry.Polyline(new com.epl.geometry.Point(1.0, 1.0), new com.epl.geometry.Point(2.0, 2.0)), 0, sr);
            NUnit.Framework.Assert.AreEqual("{\"paths\":[[[1,1],[2,2]]],\"spatialReference\":{\"wkid\":4326}}", line.AsJson());
            NUnit.Framework.Assert.AreEqual("{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", line.AsGeoJson());
            geometrySb.Append(line.AsGeoJson()).Append(", ");
            com.epl.geometry.Polygon p = new com.epl.geometry.Polygon();
            p.StartPath(1.0, 1.0);
            p.LineTo(2.0, 2.0);
            p.LineTo(3.0, 1.0);
            p.LineTo(2.0, 0.0);
            com.epl.geometry.ogc.OGCPolygon polygon = new com.epl.geometry.ogc.OGCPolygon(p, sr);
            NUnit.Framework.Assert.AreEqual("{\"rings\":[[[1,1],[2,2],[3,1],[2,0],[1,1]]],\"spatialReference\":{\"wkid\":4326}}", polygon.AsJson());
            NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[1,1],[2,0],[3,1],[2,2],[1,1]]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", polygon.AsGeoJson());
            geometrySb.Append(polygon.AsGeoJson()).Append("]}");
            System.Collections.Generic.IList <com.epl.geometry.ogc.OGCGeometry> geoms = new System.Collections.Generic.List <com.epl.geometry.ogc.OGCGeometry>(3);
            geoms.Add(point);
            geoms.Add(line);
            geoms.Add(polygon);
            com.epl.geometry.ogc.OGCConcreteGeometryCollection collection = new com.epl.geometry.ogc.OGCConcreteGeometryCollection(geoms, sr);
            string s2 = collection.AsGeoJson();

            NUnit.Framework.Assert.AreEqual("{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[1,1]},{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]]},{\"type\":\"Polygon\",\"coordinates\":[[[1,1],[2,0],[3,1],[2,2],[1,1]]]}],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}"
                                            , collection.AsGeoJson());
        }
Example #2
0
        public virtual void TestOGCPolygon()
        {
            com.epl.geometry.Polygon p = new com.epl.geometry.Polygon();
            p.StartPath(100.0, 0.0);
            p.LineTo(101.0, 0.0);
            p.LineTo(101.0, 1.0);
            p.LineTo(100.0, 1.0);
            p.ClosePathWithLine();
            com.epl.geometry.ogc.OGCPolygon ogcPolygon = new com.epl.geometry.ogc.OGCPolygon(p, null);
            string result = ogcPolygon.AsGeoJson();

            NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[100,1],[101,1],[101,0],[100,0]]],\"crs\":null}", result);
        }