Esempio n. 1
0
        internal static SharpMap.Geometries.Polygon ToSharpMapPolygon(GisSharpBlog.NetTopologySuite.Geometries.Polygon polygon)
        {
            SharpMap.Geometries.LinearRing exteriorRing = ToSharpMapLinearRing((GisSharpBlog.NetTopologySuite.Geometries.LinearRing)polygon.ExteriorRing);
            Collection <SharpMap.Geometries.LinearRing> interiorRings = new Collection <SharpMap.Geometries.LinearRing>();

            foreach (GisSharpBlog.NetTopologySuite.Geometries.LineString interiorRing in polygon.InteriorRings)
            {
                interiorRings.Add(ToSharpMapLinearRing((GisSharpBlog.NetTopologySuite.Geometries.LinearRing)interiorRing));
            }
            return(new SharpMap.Geometries.Polygon(exteriorRing, interiorRings));
        }
Esempio n. 2
0
        internal static GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon ToNTSMultiPolygon(SharpMap.Geometries.MultiPolygon multiPolygon,
                                                                                                GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory)
        {
            GisSharpBlog.NetTopologySuite.Geometries.Polygon[] polygons = new GisSharpBlog.NetTopologySuite.Geometries.Polygon[multiPolygon.Polygons.Count];
            int index = 0;

            foreach (SharpMap.Geometries.Polygon polygon in multiPolygon.Polygons)
            {
                polygons[index++] = ToNTSPolygon(polygon, factory);
            }
            return(factory.CreateMultiPolygon(polygons) as GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon);
        }
Esempio n. 3
0
 internal static GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon ToNTSMultiPolygon(SharpMap.Geometries.MultiPolygon multiPolygon,
     GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory)
 {
     GisSharpBlog.NetTopologySuite.Geometries.Polygon[] polygons = new GisSharpBlog.NetTopologySuite.Geometries.Polygon[multiPolygon.Polygons.Count];
     int index = 0;
     foreach (SharpMap.Geometries.Polygon polygon in multiPolygon.Polygons)
         polygons[index++] = ToNTSPolygon(polygon, factory);
     return factory.CreateMultiPolygon(polygons);
 }
Esempio n. 4
0
        public static GeoAPI.Geometries.IMultiPolygon ConvertTo(ESRI.ArcGIS.Geometry.IPolygon4 polygon)
        {
            GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon output = null;
            List <GeoAPI.Geometries.IPolygon> list = new List <GeoAPI.Geometries.IPolygon>();

            //IPolygon4.ExteriorRingBag should be used instead of IPolygon.QueryExteriorRings,
            //which does not work in .NET because of C-Style Arrays
            IGeometryBag exteriorRings = polygon.ExteriorRingBag;

            //For each exterior rings find the number of interior rings associated with it and print it
            IEnumGeometry exteriorRingsEnum = exteriorRings as IEnumGeometry;

            exteriorRingsEnum.Reset();
            IRing currentExteriorRing = exteriorRingsEnum.Next() as IRing;

            while (currentExteriorRing != null)
            {
                GeoAPI.Geometries.ILinearRing        shell = ConvertTo(currentExteriorRing);
                List <GeoAPI.Geometries.ILinearRing> holes = null;

                //IPolygon4.get_InteriorRingBag should be used instead of IPolygon.QueryInteriorRings,
                //which does not work in .NET because of C-Style Arrays
                IGeometryBag        interiorRings          = polygon.get_InteriorRingBag(currentExteriorRing);
                IGeometryCollection interiorRingCollection = interiorRings as IGeometryCollection;
                if (interiorRingCollection != null && interiorRingCollection.GeometryCount > 0)
                {
                    holes = new List <GeoAPI.Geometries.ILinearRing>();
                    int interiorRingsTotal = interiorRingCollection.GeometryCount;
                    for (int interiorRingIndex = 0; interiorRingIndex < interiorRingsTotal; interiorRingIndex++)
                    {
                        IRing currentInteriorRing = interiorRingCollection.get_Geometry(interiorRingIndex) as IRing;
                        if (currentInteriorRing != null)
                        {
                            holes.Add(ConvertTo(currentInteriorRing));
                        }
                    }

                    ////Note we do nothing with the interiorRings, but you can use them the same way as the IGeometryBag exteriorRings
                    //IRing currentInteriorRing = exteriorRingsEnum.Next() as IRing;
                    //while (currentInteriorRing != null)
                    //{
                    //    holes.Add(ConvertTo(currentInteriorRing));
                    //    currentInteriorRing = exteriorRingsEnum.Next() as IRing;
                    //}
                }

                GeoAPI.Geometries.IPolygon entry;
                if (holes != null && holes.Count > 0)
                {
                    entry = new GisSharpBlog.NetTopologySuite.Geometries.Polygon(shell, holes.ToArray());
                }
                else
                {
                    entry = new GisSharpBlog.NetTopologySuite.Geometries.Polygon(shell, null);
                }

                list.Add(entry);
                currentExteriorRing = exteriorRingsEnum.Next() as IRing;
            }

            if (list != null && list.Count > 0)
            {
                output = new GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon(list.ToArray());
            }

            return(output);
        }