private static IGeometry UnionGeometry(List <IGeometry> geoLst, ISpatialReference SpatialReference)
        {
            IGeometry geo = null;

            using (ComReleaser comReleaser = new ComReleaser())
            {
                ESRI.ArcGIS.Geometry.IGeometry geometryBag = new ESRI.ArcGIS.Geometry.GeometryBagClass();
                geometryBag.SpatialReference = SpatialReference;
                ESRI.ArcGIS.Geometry.IGeometryCollection geometryCollection = geometryBag as ESRI.ArcGIS.Geometry.IGeometryCollection;
                object missing = Type.Missing;
                foreach (IGeometry item in geoLst)
                {
                    geometryCollection.AddGeometry(item, ref missing, ref missing);
                }
                ITopologicalOperator unionedPolygon = new PolygonClass();
                unionedPolygon.ConstructUnion(geometryBag as IEnumGeometry);
                geo = unionedPolygon as IGeometry;

                comReleaser.ManageLifetime(geometryBag);
                comReleaser.ManageLifetime(geometryCollection);
            }
            return(geo);
        }
Exemple #2
0
        private string serializeGeo(ESRI.ArcGIS.Geometry.IGeometry geo, Boolean ESRISerialize)
        {
            if (ESRISerialize)
            {
                System.String xmlNodeName = "NodeName";
                System.String elementURI  = "http://www.esri.com/schemas/ArcGIS/10";

                // Create xml writer
                ESRI.ArcGIS.esriSystem.IXMLWriter xmlWriter = new ESRI.ArcGIS.esriSystem.XMLWriterClass();

                // Create xml stream
                ESRI.ArcGIS.esriSystem.IXMLStream xmlStream = new ESRI.ArcGIS.esriSystem.XMLStreamClass();

                // Explicit Cast for IStream and then write to stream
                xmlWriter.WriteTo((ESRI.ArcGIS.esriSystem.IStream)xmlStream);

                // Serialize
                ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializer = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();


                xmlSerializer.WriteObject(xmlWriter, null, null, xmlNodeName, elementURI, geo);

                return(xmlStream.SaveToString());
            }
            else
            {
                switch (geo.GeometryType)
                {
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                {
                    ESRI.ArcGIS.Geometry.IPoint pPnt = (ESRI.ArcGIS.Geometry.IPoint)geo;

                    return("<Point><X>" + pPnt.X + "</X><Y>" + pPnt.Y + "</Y></Point>");

                    //break;
                }

                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                {
                    string lineString = "<PathArray>";
                    ESRI.ArcGIS.Geometry.IPolyline           pPly = (ESRI.ArcGIS.Geometry.IPolyline)geo;
                    ESRI.ArcGIS.Geometry.IGeometryCollection pGC  = (ESRI.ArcGIS.Geometry.IGeometryCollection)pPly;
                    for (int i = 0; i < pGC.GeometryCount; i++)
                    {
                        lineString = lineString + "<Path><PointArray>";
                        //ESRI.ArcGIS.Geometry.IGeometry pGeo2 = pGC.get_Geometry(i);
                        // ESRI.ArcGIS.Geometry.IPath pPath = (ESRI.ArcGIS.Geometry.IPath)pGC.get_Geometry(i);
                        ESRI.ArcGIS.Geometry.IPointCollection pPointCol = (ESRI.ArcGIS.Geometry.IPointCollection)pGC.get_Geometry(i);
                        for (int j = 0; j < pPointCol.PointCount; j++)
                        {
                            ESRI.ArcGIS.Geometry.IPoint pPathPoint = pPointCol.get_Point(j);

                            lineString = lineString + "<Point><X>" + pPathPoint.X + "</X><Y>" + pPathPoint.Y + "</Y></Point>";
                        }
                        // string tr = pGeo2.GeometryType.ToString();
                        lineString = lineString + "</PointArray></Path>";
                    }
                    lineString = lineString + "</PathArray>";
                    return(lineString);

                    // return "<Point><X>" + pPnt.X + "</X><Y>" + pPnt.Y + "</Y></Point>";
                    //     break;
                }

                default:
                {
                    return("");
                    //   break;
                }
                }
            }
        }