Beispiel #1
0
        public void CopyFrom(GISExtent extent)
        {
            GISVertex _bottomleft = new GISVertex(extent.MinX, extent.MinY);
            GISVertex _upright    = new GISVertex(extent.MaxX, extent.MaxY);

            SetValue(_bottomleft, _upright);
        }
Beispiel #2
0
 public GISLayer(string _name, SHAPETYPE _shapetype, GISExtent _extent, List <GISField> _fields)
 {
     Name      = _name;
     ShapeType = _shapetype;
     Extent    = _extent;
     Fields    = _fields;
 }
Beispiel #3
0
 public void SetValue(GISExtent _extent, Rectangle _rectangle)
 {
     CurrentMapExtent = _extent;
     MapWindowSize    = _rectangle;
     ScaleX           = CurrentMapExtent.Width / MapWindowSize.Width;
     ScaleY           = CurrentMapExtent.Height / MapWindowSize.Height;
     ScaleX           = Math.Max(ScaleX, ScaleY);
     ScaleY           = ScaleX;
 }
Beispiel #4
0
        public void Merge(GISExtent extent)
        {
            double newminx = Math.Min(MinX, extent.MinX);
            double newminy = Math.Min(MinY, extent.MinY);
            double newmaxx = Math.Max(MaxX, extent.MaxX);
            double newmaxy = Math.Max(MaxY, extent.MaxY);

            SetValue(new GISVertex(newminx, newminy), new GISVertex(newmaxx, newmaxy));
        }
Beispiel #5
0
 public void draw(Graphics graphics, GISView view, GISExtent extent)
 {
     for (int i = 0; i < Features.Count; i++)
     {
         if (Features[i].spatialpart.extent.Outside(extent) == false)
         {
             Features[i].draw(graphics, view, DrawAttributeOrNot, 0);
         }
     }
 }
Beispiel #6
0
        public void draw(Graphics graphics, GISView view)
        {
            GISVertex v1            = view.ToMapVertex(new Point(0, view.MapWindowSize.Height - 1));
            GISVertex v2            = view.ToMapVertex(new Point(view.MapWindowSize.Width - 1, 0));
            GISExtent displayextent = new GISExtent(v1, v2);

            for (int i = 0; i < layers.Count; i++)
            {
                layers[i].draw(graphics, view, displayextent);
            }
        }
Beispiel #7
0
        public List <GISFeature> SelectByExtent(GISExtent extent)
        {
            List <GISFeature> features = new List <GISFeature>();

            for (int i = 0; i < Features.Count; i++)
            {
                if (extent.Include(Features[i].spatialpart.extent))
                {
                    features.Add(Features[i]);
                }
            }
            return(features);
        }
Beispiel #8
0
 private void UpdateExtent()
 {
     if (layers.Count == 0)
     {
         extent = null;
         return;
     }
     extent = new GISExtent(new GISVertex(0, 0), new GISVertex(1, 1));
     extent.CopyFrom(layers[0].Extent);
     for (int i = 1; i < layers.Count; i++)
     {
         extent.Merge(layers[i].Extent);
     }
 }
Beispiel #9
0
        public static GISLayer ReadFile(string filename)
        {
            FileStream      fsr       = new FileStream(filename, FileMode.Open);
            BinaryReader    br        = new BinaryReader(fsr);
            MyFileHeader    mfh       = (MyFileHeader)(FromBytes(br, typeof(MyFileHeader)));
            SHAPETYPE       ShapeType = IntToShapeType(mfh.ShapeType);
            GISExtent       Extent    = new GISExtent(new GISVertex(mfh.MinX, mfh.MinY), new GISVertex(mfh.MaxX, mfh.MaxY));
            string          layername = ReadString(br);
            List <GISField> Fields    = ReadFields(br, mfh.FieldCount);
            GISLayer        layer     = new GISLayer(layername, ShapeType, Extent, Fields);

            layer.DrawAttributeOrNot = (mfh.DrawAttributeOrNot == 1);
            layer.Features           = ReadFeatures(br, ShapeType, Fields, mfh.FeatureCount);
            br.Close();
            fsr.Close();
            return(layer);
        }
Beispiel #10
0
 public GISView(GISExtent _extent, Rectangle _rectangle)
 {
     SetValue(_extent, _rectangle);
 }
Beispiel #11
0
 public GISPoint(GISVertex onevertex)
 {
     Location = onevertex;
     centroid = onevertex;
     extent   = new GISExtent(onevertex, onevertex);
 }
Beispiel #12
0
 public bool Include(GISExtent extent)
 {
     return((MinX < extent.MinX) && (MaxX > extent.MaxX) &&
            (MinY < extent.MinY) && (MaxY > extent.MaxY));
 }
Beispiel #13
0
 public bool Outside(GISExtent extent)
 {
     return(MaxX < extent.MinX || MinX > extent.MaxX ||
            MaxY < extent.MinY || MinY > extent.MaxY);
 }
Beispiel #14
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);
        }