Esempio n. 1
0
        private GeometryCollection EditGeometryCollection(GeometryCollection collection,
                                                          IGeometryEdit operation)
        {
            GeometryCollection newCollection =
                (GeometryCollection)operation.Edit(collection, m_objFactory);

            GeometryList geometries = new GeometryList();

            for (int i = 0; i < newCollection.NumGeometries; i++)
            {
                Geometry geometry = Edit(newCollection.GetGeometry(i), operation);

                if (geometry.IsEmpty)
                {
                    continue;
                }

                geometries.Add(geometry);
            }

            GeometryType geomType = newCollection.GeometryType;

            if (geomType == GeometryType.MultiPoint)
            {
                return(m_objFactory.CreateMultiPoint(geometries.ToPointArray()));
            }

            if (geomType == GeometryType.MultiLineString)
            {
                return(m_objFactory.CreateMultiLineString(
                           geometries.ToLineStringArray()));
            }

            if (geomType == GeometryType.MultiPolygon)
            {
                return(m_objFactory.CreateMultiPolygon(geometries.ToPolygonArray()));
            }

            return(m_objFactory.CreateGeometryCollection(geometries.ToArray()));
        }
Esempio n. 2
0
        /// <summary>
        /// Build an appropriate Geometry, MultiGeometry, or GeometryCollection
        /// to contain the <see cref="Geometry"/> instances in it.
        /// </summary>
        /// <param name="geometryList"> the <see cref="Geometry"/> instances to combine
        /// </param>
        /// <returns>           a Geometry of the "smallest", "most
        /// type-specific" class that can contain the elements of geomList.
        /// </returns>
        /// <remarks>
        /// For example:
        /// <list type="number">
        /// <item>
        /// <description>
        /// If geomList Contains a single Polygon, the Polygon is returned.
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// If geomList Contains several Polygons, a MultiPolygon is returned.
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// If geomList Contains some Polygons and some LineStrings, a GeometryCollection is
        /// returned.
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// If geomList is empty, an empty GeometryCollection is returned.
        /// </description>
        /// </item>
        /// </list>
        /// Note that this method does not "flatten" Geometries in the input, and hence if
        /// any MultiGeometries are contained in the input a GeometryCollection containing
        /// them will be returned.
        /// </remarks>
        public virtual Geometry BuildGeometry(GeometryList geometryList)
        {
            if (geometryList == null)
            {
                throw new ArgumentNullException("geometryList");
            }

            GeometryType geomClass       = GeometryType.None;
            bool         isHeterogeneous = false;

            int nCount = geometryList.Count;

            for (int i = 0; i < nCount; i++)
            {
                Geometry     geom      = geometryList[i];
                GeometryType partClass = geom.GeometryType;
                if (geomClass == GeometryType.None)
                {
                    geomClass = partClass;
                }

                if (partClass != geomClass)
                {
                    isHeterogeneous = true;
                }
            }

            // for the empty geometry, return an empty GeometryCollection
            if (geomClass == GeometryType.None)
            {
                return(CreateGeometryCollection(null));
            }

            if (isHeterogeneous)
            {
                return(CreateGeometryCollection(geometryList.ToArray()));
            }
            // at this point we know the collection is hetereogenous.
            // Determine the type of the result from the first Geometry in the list
            // this should always return a geometry, since otherwise an empty collection would have already been returned
//			IGeometryEnumerator iTemp = geometryList.GetEnumerator();
//			iTemp.MoveNext();
//			Geometry geom0 = iTemp.Current;
            Geometry geom0        = geometryList[0];
            bool     isCollection = nCount > 1;

            if (isCollection)
            {
                GeometryType geomType = geom0.GeometryType;

                if (geomType == GeometryType.Polygon)
                {
                    return(CreateMultiPolygon(geometryList.ToPolygonArray()));
                }
                else if (geomType == GeometryType.LineString ||
                         geomType == GeometryType.LinearRing)
                {
                    return(CreateMultiLineString(geometryList.ToLineStringArray()));
                }
                else if (geomType == GeometryType.Point)
                {
                    return(CreateMultiPoint(geometryList.ToPointArray()));
                }
                Debug.Assert(false, "Should never reach here");
            }

            return(geom0);
        }