Beispiel #1
0
        /// <summary>
        /// If a Shape has multiple parts, this will create a separate polyline for each part.
        /// </summary>
        /// <param name="mwShape">A MapWinGIS.Shape that should be a PolyLine shape type</param>
        /// <returns>A List of Polylines derived from the various shapes</returns>
        public static List <PolyLine> mwShape_To_PolyLines(MapWinGIS.Shape mwShape)
        {
            if (Adapter.GetCategory(mwShape) != ShapeCategories.Line)
            {
                throw new ArgumentException("The Split method only takes Polyline shape types.");
            }
            List <PolyLine> newLines = new List <PolyLine>();

            if (mwShape.NumParts <= 1)
            {
                PolyLine Part = new PolyLine();
                for (int I = 0; I < mwShape.numPoints; I++)
                {
                    Part.Add_Point(mwShape.get_Point(I));
                }
                newLines.Add(Part);
                return(newLines);
            }
            int PartIndex = 0;

            for (int P = 0; P < mwShape.NumParts; P++)
            {
                PolyLine Part  = new PolyLine();
                int      Pnext = mwShape.get_Part(P);
                for (int I = PartIndex; I < Pnext; I++)
                {
                    Part.Add_Point(mwShape.get_Point(I));
                }
                newLines.Add(Part);
            }
            return(newLines);
        }
Beispiel #2
0
        /// <summary>
        /// Converts a list of polylines into a single multi-part shape
        /// </summary>
        /// <param name="Polylines"></param>
        /// <returns></returns>
        public static MapWinGIS.Shape PolyLines_To_mwShape(List <PolyLine> Polylines)
        {
            MapWinGIS.Shape mwShape = new MapWinGIS.Shape();
            bool            res;

            res = mwShape.Create(MapWinGIS.ShpfileType.SHP_POLYLINEZ);
            if (res != true)
            {
                throw new ApplicationException(mwShape.get_ErrorMsg(mwShape.LastErrorCode));
            }
            int idx = 0;

            for (int iPart = 0; iPart < Polylines.Count; iPart++)
            {
                PolyLine Part = Polylines[iPart];
                // we only cal set_part if we have multiple polylines
                if (Polylines.Count > 0)
                {
                    mwShape.set_Part(iPart, idx);
                }
                for (int iPoint = 0; iPoint < Part.Points.Count; iPoint++)
                {
                    mwShape.InsertPoint(Part.Points[iPoint].To_mwPoint(), ref idx);
                    idx++;
                }
            }
            return(mwShape);
        } // End PolyLines_To_mwShape
Beispiel #3
0
        /// <summary>
        /// Determines the shortest distance to any of the lines in the polyline.
        /// </summary>
        /// <param name="PolyLn">The polyline to investigate</param>
        /// <returns>Double, the distance to the closest segment</returns>
        public double DistanceTo(PolyLine PolyLn)
        {
            //I'm not sure yet how to do this faster.  Extents won't really help here.
            List <Segment> Segs = PolyLn.ToSegments();
            double         dist = double.PositiveInfinity;

            for (int iSeg = 0; iSeg < Segs.Count; iSeg++)
            {
                double test = Segs[iSeg].DistanceTo(this);
                if (test < dist)
                {
                    dist = test;
                }
            }
            return(dist);
        }