Exemple #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());
        }
Exemple #2
0
        public virtual void TestEmptyGeometryCollection()
        {
            com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326);
            com.epl.geometry.ogc.OGCConcreteGeometryCollection collection = new com.epl.geometry.ogc.OGCConcreteGeometryCollection(new System.Collections.Generic.List <com.epl.geometry.ogc.OGCGeometry>(), sr);
            string s2 = collection.AsGeoJson();

            NUnit.Framework.Assert.AreEqual("{\"type\":\"GeometryCollection\",\"geometries\":[],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", collection.AsGeoJson());
        }
Exemple #3
0
 public override bool Equals(object other)
 {
     if (other == null)
     {
         return(false);
     }
     if (other == this)
     {
         return(true);
     }
     if (other.GetType() != GetType())
     {
         return(false);
     }
     com.epl.geometry.ogc.OGCConcreteGeometryCollection another = (com.epl.geometry.ogc.OGCConcreteGeometryCollection)other;
     if (geometries != null)
     {
         if (!geometries.Equals(another.geometries))
         {
             return(false);
         }
     }
     else
     {
         if (another.geometries != null)
         {
             return(false);
         }
     }
     if (esriSR == another.esriSR)
     {
         return(true);
     }
     if (esriSR != null && another.esriSR != null)
     {
         return(esriSR.Equals(another.esriSR));
     }
     return(false);
 }
Exemple #4
0
 public override com.epl.geometry.Geometry Next()
 {
     while (true)
     {
         if (m_curs != null)
         {
             com.epl.geometry.Geometry g = m_curs.Next();
             if (g != null)
             {
                 m_index++;
                 return(g);
             }
             m_curs = null;
         }
         if (m_ind >= m_geoms.Count)
         {
             return(null);
         }
         int i = m_ind;
         m_ind++;
         if (m_geoms[i] == null)
         {
             continue;
         }
         // filter out nulls
         if (!m_geoms[i].IsConcreteGeometryCollection())
         {
             m_index++;
             return(m_geoms[i].GetEsriGeometry());
         }
         else
         {
             com.epl.geometry.ogc.OGCConcreteGeometryCollection gc = (com.epl.geometry.ogc.OGCConcreteGeometryCollection)m_geoms[i];
             m_curs = new com.epl.geometry.ogc.OGCConcreteGeometryCollection.GeometryCursorOGC(gc.geometries);
             return(Next());
         }
     }
 }
        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]);
        }