含内环图形在OpenLayers中展示时空洞被填充

问题产生背景

在一次arcgis中图形转到OpenLayers中展示时,发先含有空洞的一个面在展示时,有部分空洞被自动填充了。展示状况如下:

arcgis中显示:

含内环图形在OpenLayers中展示时空洞被填充_第1张图片

 OpenLayers中展示:

含内环图形在OpenLayers中展示时空洞被填充_第2张图片

可见右侧空洞被填充了,明显不太合理。于是去百度了下,得知Geojson格式要求对于Polygon有一个以上的环,第一个必须是外环,其他的必须是内环。 外环与表面形成边界,内环(如果存在)与表面形成边界孔。

此时产看了下本地Arcgis中的面环,确实第一个环是内环:

含内环图形在OpenLayers中展示时空洞被填充_第3张图片

可见就是环顺序导致的前端展示错误,于是就想着调整环顺序解决。

解决方式如下

第一种方式:

 用AE接口将Geometry中的环顺序调整后在展示:

        public static string ChangeRingsOrder(IGeometry pGeometry)
        {
            ITopologicalOperator topo = pGeometry as ITopologicalOperator;
            topo.Simplify();
            IPolygon4 pGeoPolygon = pGeometry as IPolygon4;
            GeometryBag geoBag = pGeoPolygon.ExteriorRingBag as GeometryBag;
            IGeometryCollection geoCollection2 = new PolygonClass();
            IGeometryCollection geoCollection = geoBag as IGeometryCollection;
            List rings1 = new List();
            for (int j = 0; j < geoCollection.GeometryCount; j++)
            {
                IGeometry geo = geoCollection.get_Geometry(j);
                geoCollection2.AddGeometry(geo);

                IGeometryBag InteriorBag = (pGeometry as ESRI.ArcGIS.Geometry.IPolygon4).get_InteriorRingBag(geo as IRing);
                if (InteriorBag != null)
                {
                    IGeometryCollection InteriorRingGeometryCollection = InteriorBag as IGeometryCollection;
                    for (int IR = 0; IR < InteriorRingGeometryCollection.GeometryCount; IR++)
                    {
                        geoCollection2.AddGeometry(InteriorRingGeometryCollection.get_Geometry(IR));
                        rings1.Add(InteriorRingGeometryCollection.get_Geometry(IR));
                    }
                }
            }
            IGeometry geo2 = geoCollection2 as IGeometry;
            geo2.Project(pGeometry.SpatialReference);

            ESRI.ArcGIS.esriSystem.IJSONWriter jsonWriter = new ESRI.ArcGIS.esriSystem.JSONWriterClass();
            jsonWriter.WriteToString();
            ESRI.ArcGIS.Geometry.JSONConverterGeometryClass jsonCon = new ESRI.ArcGIS.Geometry.JSONConverterGeometryClass();
            jsonCon.WriteGeometry(jsonWriter, null, geo2, false);
            string rings= Encoding.UTF8.GetString(jsonWriter.GetStringBuffer());
            return rings;
        }

最总展示效果:

含内环图形在OpenLayers中展示时空洞被填充_第4张图片

你可能感兴趣的:(GIS)