コード例 #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);
        }
コード例 #2
0
        public Point ToScreenPoint(GISVertex onevertex)
        {
            double ScreenX = MapWindowSize.Width / 2 - (CurrentMapExtent.MapCenter.x - onevertex.x) / ScaleX;
            double ScreenY = MapWindowSize.Height / 2 - (onevertex.y - CurrentMapExtent.MapCenter.y) / ScaleY;

            return(new Point((int)ScreenX, (int)ScreenY));
        }
コード例 #3
0
        public GISExtent RectToExtent(Rectangle rect)
        {
            GISVertex bottomleft = ToMapVertex(new Point(rect.X, rect.Y + rect.Height));
            GISVertex upright    = ToMapVertex(new Point(rect.X + rect.Width, rect.Y));

            return(new GISExtent(bottomleft, upright));
        }
コード例 #4
0
        private static double CrossProduct(GISVertex A, GISVertex B, GISVertex C)
        {
            GISVertex AB = new GISVertex(B.x - A.x, B.y - A.y);
            GISVertex AC = new GISVertex(C.x - A.x, C.y - A.y);

            return(AB.x * AC.y - AB.y * AC.x);
        }
コード例 #5
0
        private static double Distance(GISVertex A, GISVertex B)
        {
            double d1 = A.x - B.x;
            double d2 = A.y - B.y;

            return(Math.Sqrt(d1 * d1 + d2 * d2));
        }
コード例 #6
0
        private static double DotProduct(GISVertex A, GISVertex B, GISVertex C)
        {
            GISVertex AB = new GISVertex(B.x - A.x, B.y - C.y);
            GISVertex BC = new GISVertex(C.x - B.x, C.y - B.y);

            return(AB.x * BC.x + AB.y * BC.y);
        }
コード例 #7
0
 public bool WithInDistance(GISVertex vertex, double dist)
 {
     return(((vertex.x + dist) > MinX) &&
            ((vertex.y + dist) > MinY) &&
            ((vertex.x - dist) < MaxX) &&
            ((vertex.y - dist) < MaxY));
 }
コード例 #8
0
        public void draw(Graphics graphics, GISView view, GISVertex location, int index)
        {
            Point screenpoint = view.ToScreenPoint(location);

            graphics.DrawString(values[index].ToString(),
                                new Font("宋体", 20),
                                new SolidBrush(Color.Green),
                                new PointF(screenpoint.X, screenpoint.Y));
        }
コード例 #9
0
        public double Distance(GISVertex vertex)
        {
            double distance = Double.MaxValue;

            for (int i = 0; i < Vertexes.Count - 1; i++)
            {
                distance = Math.Min(GISVertex.PointToSegment(Vertexes[i], Vertexes[i + 1], vertex), distance);
            }
            return(distance);
        }
コード例 #10
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);
            }
        }
コード例 #11
0
        static List <GISFeature> ReadFeatures(BinaryReader br, SHAPETYPE ShapeType, List <GISField> Fields, int FeatureCount)
        {
            List <GISFeature> Features = new List <GISFeature>();

            for (int featureindex = 0; featureindex < FeatureCount; featureindex++)
            {
                GISFeature feature = new GISFeature(null, null);
                if (ShapeType == SHAPETYPE.POINT)
                {
                    GISVertex _location = ReadVertex(br);
                    feature.spatialpart = new GISPoint(_location);
                }
                else if (ShapeType == SHAPETYPE.LINE)
                {
                    List <GISVertex> vs = new List <GISVertex>();
                    int vcount          = br.ReadInt32();
                    for (int vc = 0; vc < vcount; vc++)
                    {
                        vs.Add(ReadVertex(br));
                    }
                    feature.spatialpart = new GISLine(vs);
                }
                else if (ShapeType == SHAPETYPE.POLYGON)
                {
                    List <GISVertex> vs = new List <GISVertex>();
                    int vcount          = br.ReadInt32();
                    for (int vc = 0; vc < vcount; vc++)
                    {
                        vs.Add(ReadVertex(br));
                    }
                    feature.spatialpart = new GISPolygon(vs);
                }
                GISAttribute ga = new GISAttribute();
                for (int fieldindex = 0; fieldindex < Fields.Count; fieldindex++)
                {
                    GISField field = Fields[fieldindex];
                    if (field.datatype == typeof(int))
                    {
                        ga.AddValue(br.ReadInt32());
                    }
                    else if (field.datatype == typeof(double))
                    {
                        ga.AddValue(br.ReadDouble());
                    }
                    else if (field.datatype == typeof(string))
                    {
                        ga.AddValue(ReadString(br));
                    }
                }
                feature.attributepart = ga;
                Features.Add(feature);
            }
            return(Features);
        }
コード例 #12
0
 public void SetValue(GISVertex _bottomleft, GISVertex _upright)
 {
     upright    = _upright;
     bottomleft = _bottomleft;
     MinX       = bottomleft.getX();
     MinY       = bottomleft.getY();
     MaxX       = upright.getX();
     MaxY       = upright.getY();
     Width      = upright.getX() - bottomleft.getX();
     Height     = upright.getY() - bottomleft.getY();
     MapCenter  = new GISVertex((MinX + MaxX) / 2, (MinY + MaxY) / 2);
 }
コード例 #13
0
 public GISFeature SelectPolygonByVertex(GISVertex vertex)
 {
     for (int i = 0; i < Features.Count; i++)
     {
         if (Features[i].spatialpart.extent.WithInDistance(vertex, 0) == false)
         {
             continue;
         }
         GISPolygon polygon = (GISPolygon)(Features[i].spatialpart);
         if (polygon.Include(vertex))
         {
             return(Features[i]);
         }
     }
     return(null);
 }
コード例 #14
0
        public static double PointToSegment(GISVertex A, GISVertex B, GISVertex C)
        {
            double dot1 = DotProduct(A, B, C);

            if (dot1 > 0)
            {
                return(Distance(B, C));
            }
            double dot2 = DotProduct(B, A, C);

            if (dot2 > 0)
            {
                return(Distance(A, C));
            }
            double dist = CrossProduct(A, B, C) / Distance(A, B);

            return(Math.Abs(dist));
        }
コード例 #15
0
        public GISFeature SelectByClick(Point mousepoint, GISView view)
        {
            GISFeature feature = null;
            GISVertex  vertex  = view.ToMapVertex(mousepoint);
            double     mindist = view.ToMapDistance(MINIMUMSCREENDISTANCE);

            if (ShapeType == SHAPETYPE.POINT)
            {
                feature = SelectPointByVertex(vertex, mindist);
            }
            if (ShapeType == SHAPETYPE.LINE)
            {
                feature = SelectLineByVertex(vertex, mindist);
            }
            if (ShapeType == SHAPETYPE.POLYGON)
            {
                feature = SelectPolygonByVertex(vertex);
            }
            return(feature);
        }
コード例 #16
0
        // 判断射线与线段的关系一相交返回1,不相交返回0,射线起点在线段上返回-1
        public static int IntersactCount(GISVertex p1, GISVertex p2, GISVertex mp)
        {
            double minX = Math.Min(p1.x, p2.x);
            double minY = Math.Min(p1.y, p2.y);
            double maxX = Math.Max(p1.x, p2.x);
            double maxY = Math.Max(p1.y, p2.y);

            if (mp.x > maxX || mp.y > maxY || mp.y < minY)
            {
                return(0);
            }
            if (p1.y == p2.y)
            {
                if (mp.x > minX && mp.x < maxX)//水平线段,则点在线段上返回一1,否则返回0
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            }
            double X0 = p1.x + (mp.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y);

            if (X0 < mp.x)//交点在射线起点左侧(射线与线段不相交)
            {
                return(0);
            }
            else if (X0 == mp.x)//交点与射线起点相同一点在线段上,返回一1
            {
                return(-1);
            }
            else if (mp.y == minY)//如果射线穿过线段下端点则不计数
            {
                return(0);
            }
            else
            {
                return(1);//交点在边的中间点或者上端点,计数
            }
        }
コード例 #17
0
        public GISFeature SelectLineByVertex(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;
                }
                GISLine line = (GISLine)(Features[i].spatialpart);
                double  dist = line.Distance(vertex);
                if (dist < distance)
                {
                    distance = dist;
                    id       = i;
                }
            }
            return((distance < mindist) ? Features[id] : null);
        }
コード例 #18
0
        public bool Include(GISVertex vertex)
        {
            int count = 0;
            int sum   = 0;

            for (int i = 0; i < Vertexes.Count - 1; i++)
            {
                count = GISVertex.IntersactCount(Vertexes[i], Vertexes[i + 1], vertex);
                if (count < 0)
                {
                    return(true);
                }
                sum += count;
            }
            count = GISVertex.IntersactCount(Vertexes[Vertexes.Count - 1], Vertexes[0], vertex);
            if (count < 0)
            {
                return(true);
            }
            sum += count;
            return(sum % 2 != 0);
        }
コード例 #19
0
 public double Distance(GISVertex anothervertex)
 {
     return(Math.Sqrt((x - anothervertex.x) * (x - anothervertex.x) + (y - anothervertex.y) * (y - anothervertex.y)));
 }
コード例 #20
0
 static void WriteVertex(GISVertex v, BinaryWriter bw)
 {
     bw.Write(v.getX());
     bw.Write(v.getY());
 }
コード例 #21
0
 public GISExtent(GISVertex _bottomleft, GISVertex _upright)
 {
     SetValue(_bottomleft, _upright);
 }
コード例 #22
0
 public double Distance(GISVertex anothervertex)
 {
     return(Location.Distance(anothervertex));
 }
コード例 #23
0
 public GISPoint(GISVertex onevertex)
 {
     Location = onevertex;
     centroid = onevertex;
     extent   = new GISExtent(onevertex, onevertex);
 }
コード例 #24
0
 public void SetMapCenter(GISVertex v)
 {
     SetValue(new GISVertex(v.x - Width / 2, v.y - Height / 2),
              new GISVertex(v.x + Width / 2, v.y + Height / 2));
 }