Example #1
0
        public GISFeature SelectPointByVertex(GISVertex vertex, double mindist)
        {
            Double distance = Double.MaxValue;
            int    id       = -1;

            for (int i = 0; i < Features.Count; i++)
            {
                if (Features[i].spatialpart.extent.WithInDistance(vertex, mindist) == false)
                {
                    continue;
                }
                GISPoint point = (GISPoint)(Features[i].spatialpart);
                double   dist  = point.Distance(vertex);
                if (dist < distance)
                {
                    distance = dist;
                    id       = i;
                }
            }
            return((distance < mindist) ? Features[id] : null);
        }
Example #2
0
        public static GISLayer ReadShapeFile(string shpfilename)
        {
            FileStream      fsr       = new FileStream(shpfilename, FileMode.Open);
            BinaryReader    br        = new BinaryReader(fsr);
            ShapeFileHeader sfh       = ReadFileHeader(br);
            SHAPETYPE       ShapeType = SHAPETYPE.POINT;

            if (sfh.ShapeType == 1)
            {
                ShapeType = SHAPETYPE.POINT;
            }
            else if (sfh.ShapeType == 3)
            {
                ShapeType = SHAPETYPE.LINE;
            }
            else if (sfh.ShapeType == 5)
            {
                ShapeType = SHAPETYPE.POLYGON;
            }
            else
            {
                return(null);
            }
            GISExtent extent = new GISExtent(new GISVertex(sfh.Xmin, sfh.Ymin), new GISVertex(sfh.Xmax, sfh.Ymax));

            string    dbffilename = shpfilename.Replace(".shp", ".dbf");
            DataTable table       = ReadDBF(dbffilename);
            GISLayer  layer       = new GISLayer(shpfilename, ShapeType, extent, ReadFields(table));
            int       rowindex    = 0;

            while (br.PeekChar() != -1)
            {
                RecordHeader rh            = ReadRecordHeader(br);
                int          RecordLength  = FromBigToLittle(rh.RecordLength);
                byte[]       RecordContent = br.ReadBytes(RecordLength * 2 - 4);
                if (ShapeType == SHAPETYPE.POINT)
                {
                    GISPoint   onepoint   = ReadPoint(RecordContent);
                    GISFeature onefeature = new GISFeature(onepoint, ReadAttribute(table, rowindex));
                    layer.Features.Add(onefeature);
                }
                if (ShapeType == SHAPETYPE.LINE)
                {
                    List <GISLine> lines = ReadLines(RecordContent);
                    for (int i = 0; i < lines.Count; i++)
                    {
                        GISFeature onefeature = new GISFeature(lines[i], ReadAttribute(table, rowindex));
                        layer.Features.Add(onefeature);
                    }
                }
                if (ShapeType == SHAPETYPE.POLYGON)
                {
                    List <GISPolygon> polygons = ReadPolygons(RecordContent);
                    for (int i = 0; i < polygons.Count; i++)
                    {
                        GISFeature onefeature = new GISFeature(polygons[i], ReadAttribute(table, rowindex));
                        layer.Features.Add(onefeature);
                    }
                }
                rowindex++;

                //其它代码,用于处理RecordContent
            }
            br.Close();
            fsr.Close();
            return(layer);
        }