Beispiel #1
0
        /// <summary>
        /// 简化几何形状
        /// 对传入的几何形状直接进行简化
        /// 主要在编辑时使用
        /// </summary>
        /// <param name="geometry">需要被简化的几何形状</param>
        public static void Simplify(IGeometry geometry)
        {
            if (geometry != null)
            {
                if (geometry is ITopologicalOperator2)
                {
                    ITopologicalOperator2 topoOp = geometry as ITopologicalOperator2;
                    topoOp.IsKnownSimple_2 = false;
                    switch (geometry.GeometryType)
                    {
                    case esriGeometryType.esriGeometryPolygon:
                    {
                        IPolygon poly = (IPolygon)geometry;
                        poly.SimplifyPreserveFromTo();
                        break;
                    }

                    case esriGeometryType.esriGeometryPolyline:
                    {
                        IPolyline polyLineGeom = (IPolyline)geometry;
                        polyLineGeom.SimplifyNetwork();
                        break;
                    }

                    default:
                    {
                        topoOp.Simplify();
                        break;
                    }
                    }
                }
            }
        }
Beispiel #2
0
        private static IGeometry GetErrorGeometry(
            [NotNull] IPolyline consecutiveErrorSegments)
        {
            IPoint fromPoint = consecutiveErrorSegments.FromPoint;

            consecutiveErrorSegments.SimplifyNetwork();

            return(consecutiveErrorSegments.IsEmpty
                                       ? (IGeometry)fromPoint
                                       : consecutiveErrorSegments);
        }
Beispiel #3
0
        /// <summary>
        /// 简化几何形状
        /// 不直接对传入的几何形状进行简化,而是克隆传入参数再进行简化出结果
        /// 主要在编辑时使用
        /// </summary>
        /// <param name="geometry">需要被简化的几何形状</param>
        /// <returns>简化后的几何形状</returns>
        public static IGeometry QuerySimplify(IGeometry geometry)
        {
            if (geometry == null)
            {
                return(null);
            }
            else
            {
                IGeometry geom = (geometry as IClone).Clone() as IGeometry;
                if (geom is ITopologicalOperator2)
                {
                    ITopologicalOperator2 topoOp = geom as ITopologicalOperator2;
                    topoOp.IsKnownSimple_2 = false;

                    switch (geom.GeometryType)
                    {
                    case esriGeometryType.esriGeometryPolygon:
                    {
                        IPolygon poly = (IPolygon)geom;
                        poly.SimplifyPreserveFromTo();
                        return(poly);
                    }

                    case esriGeometryType.esriGeometryPolyline:
                    {
                        IPolyline polyLineGeom = (IPolyline)geom;
                        polyLineGeom.SimplifyNetwork();
                        return(polyLineGeom);
                    }

                    default:
                    {
                        topoOp.Simplify();
                        return((IGeometry)topoOp);
                    }
                    }
                }
                else
                {
                    return(geometry);
                }
            }
        }
        private static IPolyline CreatePolyline([NotNull] IEnumerable <IRing> rings,
                                                [NotNull] ISpatialReference spatialReference)
        {
            const bool makeZAware = true;
            const bool makeMAware = false;
            IPolyline  result     = GeometryFactory.CreatePolyline(spatialReference,
                                                                   makeZAware, makeMAware);

            var tooSmallRingSegments = (ISegmentCollection)result;

            foreach (IRing ring in rings)
            {
                tooSmallRingSegments.AddSegmentCollection(
                    (ISegmentCollection)GeometryFactory.Clone(ring));
            }

            // don't split at intersections/overlaps
            // merge paths where an end point is shared (without merging: IPolyline6.SimplifyNonPlanar())
            result.SimplifyNetwork();

            return(result.IsEmpty
                                       ? null
                                       : result);
        }
Beispiel #5
0
        /// <summary>
        /// Create a geojson string from the geometry
        /// </summary>
        /// <param name="geometry"></param>
        /// <returns></returns>
        public static GeoJSONGeometry CreateFromIGeometry(IGeometry geometry)
        {
            GeoJSONGeometry jsonGeom = new GeoJSONGeometry();

            jsonGeom.Type = geometry.GeometryType.ToString();
            StringBuilder sb = new StringBuilder();

            if (geometry.GeometryType != esriGeometryType.esriGeometryPoint)
            {
                sb.Append("[");
            }
            //Need to work out how to easily rip the coords out of the IGeometry

            switch (geometry.GeometryType)
            {
            case esriGeometryType.esriGeometryPoint:
                IPoint pt = (IPoint)geometry;
                sb.Append(string.Format("[{0}, {1}]", Math.Round(pt.X, 5), Math.Round(pt.Y, 5)));
                jsonGeom.Type = "Point";
                break;

            case esriGeometryType.esriGeometryLine:
                IPolyline line = geometry as IPolyline;
                if (line == null)
                {
                    return(null);
                }

                line.Densify(-1, -1);   //make sure it's all straight line segments
                line.Weed(20);          //weed out some vertices
                line.SimplifyNetwork(); //make sure it is simple


                IPointCollection points = line as IPointCollection;
                for (int i = 0; i < points.PointCount; i++)
                {
                    IPoint point = points.get_Point(i);
                    if (sb.Length > 1)
                    {
                        sb.Append(",");
                    }
                    sb.Append(string.Format("[{0}, {1}]", Math.Round(point.X, 4), Math.Round(point.Y, 4)));
                }

                jsonGeom.Type = "LineString";
                break;

            case esriGeometryType.esriGeometryPolygon:
                IPolygon4 poly = geometry as IPolygon4;
                if (poly == null)
                {
                    return(null);
                }

                poly.Densify(-1, -1);          //make sure it is all straight line segments
                poly.Weed(20);                 //weed out some vertices
                poly.SimplifyPreserveFromTo(); //make sure it's simple

                //We aren't gonna deal with interior rings right now (ie - no holes in polygons)
                IGeometryBag  multiRing         = poly.ExteriorRingBag;
                IEnumGeometry exteriorRingsEnum = multiRing as IEnumGeometry;
                exteriorRingsEnum.Reset();
                IRing currentExteriorRing = exteriorRingsEnum.Next() as IRing;
                while (currentExteriorRing != null)
                {
                    if (!currentExteriorRing.IsClosed)
                    {
                        currentExteriorRing.Close();
                    }

                    IPointCollection multiRingPoints = currentExteriorRing as IPointCollection;
                    for (int pointIdx = 0; pointIdx < multiRingPoints.PointCount; pointIdx++)
                    {
                        IPoint multiRingPoint = multiRingPoints.get_Point(pointIdx);
                        //coords.Add(new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(Math.Round(multiRingPoint.X, 5), Math.Round(multiRingPoint.Y, 5)));
                        if (sb.Length > 1)
                        {
                            sb.Append(",");
                        }
                        sb.Append(string.Format("[{0}, {1}]", Math.Round(multiRingPoint.X, 4), Math.Round(multiRingPoint.Y, 4)));
                    }

                    currentExteriorRing = exteriorRingsEnum.Next() as IRing;
                }
                jsonGeom.Type = "Polygon";
                break;
            }


            if (geometry.GeometryType != esriGeometryType.esriGeometryPoint)
            {
                sb.Append("]");
            }
            jsonGeom.coordinates = sb.ToString();
            return(jsonGeom);
        }
        public static void MakeHatchesEndsOnly(IPolyline pPL, bool Ends, IPolyline pMajor, IPolyline pMinor, double dHatchLen, double dTxtInterval, double dHatchOffset)
        {
            //���������
            ITopologicalOperator pTopo = pPL as ITopologicalOperator;
            pTopo.Simplify();
            //���ǽ��ڶμ����д洢HATCH
            ISegmentCollection pSCMajor = pMajor as ISegmentCollection;
            ISegmentCollection pSCMinor = pMinor as ISegmentCollection;

            //Break the polyline into parts here ... Ideally, there should be one part
            //per route. In cases where there is mSEETARD than one part, and there is no physical
            // separation in the parts, the results can look like they are wrong (i.e. there
            //appears to be text where there should not be).
            IGeometryCollection pGC = pPL as IGeometryCollection;
            int cnt = pGC.GeometryCount - 1;
            object missing = Type.Missing;
            object distances;
            double dist;
            for (int i = 0; i <= pGC.GeometryCount - 1; i++)
            {
                IPath pPath = pGC.get_Geometry(i) as IPath;
                IGeometryCollection pSubPL = new PolylineClass();
                pSubPL.AddGeometry(pPath, ref missing, ref missing);
                IMAware pMAware = pSubPL as IMAware;
                pMAware.MAware = true;
                IMSegmentation pPLM = pSubPL as IMSegmentation;
                double Mmin = pPLM.MMin;
                double Mmax = pPLM.MMax;
                ISegment pSeg = MakeOneHatch(pSubPL as IPolyline, Mmin, Mmin, 1, dTxtInterval, dHatchLen, dHatchOffset);
                if (pSeg.Length >= ((Math.Abs(dHatchLen) * 0.5) + 0.001))
                    pSCMajor.AddSegment(pSeg, ref  missing, ref missing);
                else
                    pSCMinor.AddSegment(pSeg, ref missing, ref missing);
                distances = pPLM.GetDistancesAtM(false, Mmax);
                IArray pArray = (IArray)distances;
                for (int j = 0; j <= pArray.Count - 1; j++)
                {
                    dist = (double)pArray.get_Element(j);
                    pSeg = MakeOneHatch(pSubPL as IPolyline, dist, Mmax, 1, dTxtInterval, dHatchLen, dHatchOffset);
                    if (pSeg.Length >= (Math.Abs(dHatchLen) * 0.5) + 0.001)
                    {
                        pSCMajor.AddSegment(pSeg, ref missing, ref missing);
                    }
                    else
                    {
                        pSCMinor.AddSegment(pSeg, ref missing, ref missing);
                    }
                }
            }
            pMajor.SimplifyNetwork();
            pMinor.SimplifyNetwork();
        }