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()); }
public OGCMultiPoint(com.epl.geometry.ogc.OGCPoint startPoint, com.epl.geometry.ogc.OGCPoint endPoint) { multiPoint = new com.epl.geometry.MultiPoint(); multiPoint.Add((com.epl.geometry.Point)startPoint.GetEsriGeometry()); multiPoint.Add((com.epl.geometry.Point)endPoint.GetEsriGeometry()); esriSR = startPoint.esriSR; }
public virtual void TestOGCPoint() { com.epl.geometry.Point p = new com.epl.geometry.Point(10.0, 20.0); com.epl.geometry.ogc.OGCGeometry ogcPoint = new com.epl.geometry.ogc.OGCPoint(p, null); string result = ogcPoint.AsGeoJson(); NUnit.Framework.Assert.AreEqual("{\"type\":\"Point\",\"coordinates\":[10,20],\"crs\":null}", result); }
public static com.epl.geometry.ogc.OGCGeometry CreateFromOGCStructure(com.epl.geometry.OGCStructure ogcStructure, com.epl.geometry.SpatialReference sr) { System.Collections.Generic.List <com.epl.geometry.ogc.OGCConcreteGeometryCollection> collectionStack = new System.Collections.Generic.List <com.epl.geometry.ogc.OGCConcreteGeometryCollection>(0); System.Collections.Generic.List <com.epl.geometry.OGCStructure> structureStack = new System.Collections.Generic.List <com.epl.geometry.OGCStructure>(0); System.Collections.Generic.List <int> indices = new System.Collections.Generic.List <int>(0); com.epl.geometry.ogc.OGCGeometry[] geometries = new com.epl.geometry.ogc.OGCGeometry[1]; com.epl.geometry.ogc.OGCConcreteGeometryCollection root = new com.epl.geometry.ogc.OGCConcreteGeometryCollection(java.util.Arrays.AsList(geometries), sr); structureStack.Add(ogcStructure); collectionStack.Add(root); indices.Add(0); while (!structureStack.IsEmpty()) { com.epl.geometry.OGCStructure lastStructure = structureStack[structureStack.Count - 1]; if (indices[indices.Count - 1] == lastStructure.m_structures.Count) { structureStack.Remove(structureStack.Count - 1); collectionStack.Remove(collectionStack.Count - 1); indices.Remove(indices.Count - 1); continue; } com.epl.geometry.ogc.OGCConcreteGeometryCollection lastCollection = collectionStack[collectionStack.Count - 1]; com.epl.geometry.ogc.OGCGeometry g; int i = indices[indices.Count - 1]; int type = lastStructure.m_structures[i].m_type; switch (type) { case 1: { g = new com.epl.geometry.ogc.OGCPoint((com.epl.geometry.Point)lastStructure.m_structures[i].m_geometry, sr); lastCollection.geometries[i] = g; indices[indices.Count - 1] = i + 1; break; } case 2: { g = new com.epl.geometry.ogc.OGCLineString((com.epl.geometry.Polyline)lastStructure.m_structures[i].m_geometry, 0, sr); lastCollection.geometries[i] = g; indices[indices.Count - 1] = i + 1; break; } case 3: { g = new com.epl.geometry.ogc.OGCPolygon((com.epl.geometry.Polygon)lastStructure.m_structures[i].m_geometry, 0, sr); lastCollection.geometries[i] = g; indices[indices.Count - 1] = i + 1; break; } case 4: { g = new com.epl.geometry.ogc.OGCMultiPoint((com.epl.geometry.MultiPoint)lastStructure.m_structures[i].m_geometry, sr); lastCollection.geometries[i] = g; indices[indices.Count - 1] = i + 1; break; } case 5: { g = new com.epl.geometry.ogc.OGCMultiLineString((com.epl.geometry.Polyline)lastStructure.m_structures[i].m_geometry, sr); lastCollection.geometries[i] = g; indices[indices.Count - 1] = i + 1; break; } case 6: { g = new com.epl.geometry.ogc.OGCMultiPolygon((com.epl.geometry.Polygon)lastStructure.m_structures[i].m_geometry, sr); lastCollection.geometries[i] = g; indices[indices.Count - 1] = i + 1; break; } case 7: { geometries = new com.epl.geometry.ogc.OGCGeometry[lastStructure.m_structures[i].m_structures.Count]; g = new com.epl.geometry.ogc.OGCConcreteGeometryCollection(java.util.Arrays.AsList(geometries), sr); lastCollection.geometries[i] = g; indices[indices.Count - 1] = i + 1; structureStack.Add(lastStructure.m_structures[i]); collectionStack.Add((com.epl.geometry.ogc.OGCConcreteGeometryCollection)g); indices.Add(0); break; } default: { throw new System.NotSupportedException(); } } } return(root.geometries[0]); }