Пример #1
0
        internal Polyline[] CollectPolygon(string pathToShapefile)
        {
            string       filepath    = System.IO.Path.HasExtension(pathToShapefile) ? pathToShapefile.Substring(0, pathToShapefile.Length - (System.IO.Path.GetExtension(pathToShapefile).Length)) : pathToShapefile;
            string       shpfilepath = filepath + ".shp";
            FileStream   fs          = new FileStream(shpfilepath, FileMode.Open, FileAccess.Read);
            BinaryReader binaryFile  = new BinaryReader(fs);

            binaryFile.BaseStream.Seek(100, SeekOrigin.Current);
            MainRecord mainrecords = new MainRecord();
            int        shapeCount  = mainrecords.GetNumRecords(pathToShapefile);

            for (int i = 0; i < shapeCount; i++)
            {
                Polyline polygon = new Polyline();
                binaryFile.ReadBytes(12);
                polygon.Box[0] = binaryFile.ReadDouble();
                polygon.Box[1] = binaryFile.ReadDouble();
                polygon.Box[2] = binaryFile.ReadDouble();
                polygon.Box[3] = binaryFile.ReadDouble();

                int numParts  = binaryFile.ReadInt32();
                int numPoints = binaryFile.ReadInt32();


                for (int j = 0; j < numParts; j++)
                {
                    int parts = binaryFile.ReadInt32();
                    polygon.Parts.Add(parts);
                }

                for (int k = 0; k < numPoints; k++)
                {
                    Point tempPoint = new Point();
                    tempPoint.X = binaryFile.ReadDouble();
                    tempPoint.Y = binaryFile.ReadDouble();
                    polygon.Points.Add(tempPoint);
                }
                polygons.Add(polygon);
            }
            return(polygons.ToArray());
        }
Пример #2
0
        internal Point[] CollectPoint(string pathToShapefile)
        {
            string       filepath    = System.IO.Path.HasExtension(pathToShapefile) ? pathToShapefile.Substring(0, pathToShapefile.Length - (System.IO.Path.GetExtension(pathToShapefile).Length)) : pathToShapefile;
            string       shpfilepath = filepath + ".shp";
            FileStream   fs          = new FileStream(shpfilepath, FileMode.Open, FileAccess.Read);
            BinaryReader binaryFile  = new BinaryReader(fs);

            binaryFile.BaseStream.Seek(100, SeekOrigin.Current);
            binaryFile.ReadBytes(100);
            MainRecord mainrecords = new MainRecord();
            int        shapeCount  = mainrecords.GetNumRecords(pathToShapefile);

            for (int i = 0; i < shapeCount; i++)
            {
                Point point = new Point();
                //记录头8个字节和一个int(4个字节)的shapetype
                //binaryFile.BaseStream.Seek(12,fs);
                binaryFile.ReadBytes(12);
                point.X = binaryFile.ReadDouble();
                point.Y = binaryFile.ReadDouble();
                points.Add(point);
            }
            return(points.ToArray());
        }