コード例 #1
0
        //For "poly" type geometries, this function returns an array of the multipoint parts of a record.
        //This multipoint part array is used in the construction of the "poly" type geometry.
        private static Multipoint[] GetMultipointParts(byte[] recordContents)
        {
            //Get the number of parts and number of points and stored inside the PolyRecordFields struct.
            PolyRecordFields recordNums = new PolyRecordFields(recordContents);

            //Get all the points in the record.
            Point[] points = GetPolyPoints(recordNums.NumPoints, recordNums.NumParts, recordContents);

            //The points will be divided up into parts and assigned an index here.
            Multipoint[] multiparts = new Multipoint[recordNums.NumParts];

            //Get the index of each part.
            int[] partIndex = GetRecordPartOffsets(recordNums.NumParts, recordContents);

            //Loop through all the parts indicies and copy the points of that part to the multipart array.
            for (int n = 0; n < partIndex.Length; n++)
            {
                //Find the number of points between the current index and the next index.
                //If this is the last index then find the number of points between it and the length of the point array.
                int numPointsInPart = n < partIndex.Length - 1 ? partIndex[n + 1] - partIndex[n] : recordNums.NumPoints - partIndex[n];

                //Copy points to new point array sized for that part.
                Point[] partPoints = new Point[numPointsInPart];
                partPoints = points.Skip(partIndex[n]).Take(numPointsInPart).ToArray <Point>();

                //Create a new multipoint object from the new point array and store it at the current part index.
                multiparts[n] = new Multipoint(partPoints);
            }
            return(multiparts);
        }
コード例 #2
0
        /// <summary>
        /// 解析多点要素
        /// </summary>
        /// <param name="recordContents"></param>
        /// <returns></returns>
        private static List <PolyLine> GetMultiPolyLineParts(byte[] recordContents)
        {
            //获取几何分了几部分,以及所有坐标点的数量
            PolyRecordFields recordNums = new PolyRecordFields(recordContents);
            //获取记录中的所有的坐标点
            var points = GetPolyPoints(recordNums.NumPoints, recordNums.NumParts, recordContents);

            //按照部分划分这些点
            List <PolyLine> multiparts = new List <PolyLine>();

            //获取每部分点的开始索引
            int[] partIndex = GetRecordPartOffsets(recordNums.NumParts, recordContents);
            var   partsNum  = partIndex.Length;

            //循环以生成各个部分的点
            for (int n = 0; n < partsNum; n++)
            {
                //判断这是不是最后一部分点,并计算本部分点共有多少个
                int numPointsInPart =
                    n < partsNum - 1
                    ? partIndex[n + 1] - partIndex[n]
                    : recordNums.NumPoints - partIndex[n];

                //取出当前这部分的点
                var partPoints =
                    points.Skip(partIndex[n]).Take(numPointsInPart).ToList();

                PolyLine multiPoint = new PolyLine(partPoints);
                multiparts.Add(multiPoint);
            }

            return(multiparts);
        }