Пример #1
0
        public void TestPointLine2()
        {
            // test when the point being tested in a node on the line
            Coordinate coordLine1  = new Coordinate(5.0, 5.0);
            Coordinate coordLine2  = new Coordinate(10.0, 10.0);
            Coordinate coordPoint1 = new Coordinate(6.0, 6.0);

            Coordinates coordinates = new Coordinates();

            coordinates.Add(coordLine1);
            coordinates.Add(coordLine2);

            Point point1 = _factory.CreatePoint(coordPoint1);

            LineString linestring = _factory.CreateLineString(coordinates);

            Assertion.AssertEquals("intersects", true, point1.Intersects(linestring));
            Assertion.AssertEquals("intersects", true, linestring.Intersects(point1));
            Assertion.AssertEquals("disjoint", false, point1.Disjoint(linestring));
            Assertion.AssertEquals("contains", false, point1.Contains(linestring));
            Assertion.AssertEquals("OppositeContains", true, linestring.Contains(point1));
            Assertion.AssertEquals("within", true, point1.Within(linestring));                          // point1 is within linestring and linestring contains point.

            // always returns false when a point is involves
            Assertion.AssertEquals("crosses", false, point1.Crosses(linestring));

            Assertion.AssertEquals("touches", false, point1.Touches(linestring));                       // false because point is in the interior of linestring and not the boundary. The boundary is the endpoints.

            // always returns false when a point is involved
            Assertion.AssertEquals("overlaps", false, point1.Overlaps(linestring));
        }
Пример #2
0
        }  //获取一个小班距重心最远点

        public static Coordinate getMinPoints(IFeature feature)
        {
            List <Coordinate> coors = new List <Coordinate>(feature.Geometry.Coordinates);

            coors.Add(feature.Geometry.Coordinates[0]);
            double     min     = 1000000;
            Coordinate score   = new Coordinate();
            LineString minLine = null;

            for (int i = 0; i < coors.Count - 1; i++)
            {
                double     dis   = 0;
                LineString line1 = new LineString(new Coordinate[] { coors[i], coors[i + 1] });
                Coordinate pedal = getPedal(line1, feature.Geometry.Centroid.Coordinate);
                LineString line2 = new LineString(new Coordinate[] { feature.Geometry.Centroid.Coordinate, pedal });
                if (line1.Intersects(line2))
                {
                    dis = feature.Geometry.Centroid.Coordinate.Distance(pedal);
                    if (min > dis)
                    {
                        min     = dis;
                        score   = pedal;
                        minLine = line1;
                        continue;
                    }
                }
            }

            return(score);
        }
Пример #3
0
        private void getPolygons(IFeature feature)
        {
            IList <ILineString> lines    = new List <ILineString>();
            Coordinate          centroid = feature.Geometry.Centroid.Coordinate;
            Coordinate          origin   = new Coordinate();

            origin.X = MaxPoints.getMaxVector(feature).Coordinates[1].X - centroid.X;
            origin.Y = MaxPoints.getMaxVector(feature).Coordinates[1].Y - centroid.Y;    //最大点平移到自定义坐标系
            for (int i = 5; i <= 361; i += 5)
            {
                double angle = getAngle(origin);
                double k     = 0;
                angle += i;
                if (angle > 360)  //若角大于360,减去360
                {
                    angle -= 360;
                }
                k = Math.Tan(angle * Math.PI / 180);
                Coordinate point = new Coordinate();  //判定每隔5度的点落在1.4象限,2,3象限,或者X轴上
                if (angle > 90 && angle < 270)
                {
                    point.X = -100000.0;
                    point.Y = k * point.X;
                }
                else if ((angle >= 0 && angle < 90) || (angle > 270 && angle <= 360))
                {
                    point.X = 100000.0;
                    point.Y = k * point.X;
                }
                else if (angle == 90)
                {
                    point.X = 0;
                    point.Y = 100000.0;
                }
                else if (angle == 270)
                {
                    point.X = 0;
                    point.Y = -100000.0;
                }
                point.X += centroid.X; //将点移动回到原空间投影坐标系
                point.Y += centroid.Y;
                Coordinate[] points = new Coordinate[] { centroid, point };
                LineString   line   = new LineString(points);
                if (!line.Intersects(feature.Geometry.Boundary)) //如果所得线段与边界不相交,跳出当前循环,进入下个循环
                {
                    continue;
                }
                lines.Add(line);
            }
            lines.Add(lines[0]);
            for (int i = 0; i < lines.Count - 1; i++)
            {
                Coordinate[] points    = new Coordinate[] { centroid, lines[i].Coordinates[1], lines[i + 1].Coordinates[1], centroid };
                ILinearRing  triangle  = new LinearRing(points);
                Polygon      angleArea = new Polygon(triangle);
                IGeometry    area      = angleArea.Intersection(feature.Geometry);
                Polygens.Add(area);   //两条线与多边形交出的多边形面积
            }
        }
        public override void StartRun(int runSize)
        {
            int nVertices = runSize * DENSIFY_FACTOR;

            _line1 = CreateLine("LINESTRING (0 0, 100 100)", nVertices);
            _line2 = CreateLine("LINESTRING (0 1, 100 99)", nVertices);

            // force compilation of intersects code
            _line1.Intersects(_line2);
        }
Пример #5
0
        /// <summary>
        /// Returns true if the element intersect the rectangle from the parent class.
        /// </summary>
        /// <param name="rect">The rectangle to test must be in the virtual modeling coordinant plane.</param>
        /// <returns>True if the element intersect the rectangle from the parent class.</returns>
        public override bool ElementInRectangle(Rectangle rect)
        {
            Geometry rectanglePoly;

            if ((rect.Height == 0) && (rect.Width == 0))
            {
                rectanglePoly = new NetTopologySuite.Geometries.Point(rect.X, rect.Y);
            }
            else if (rect.Width == 0)
            {
                Coordinate[] rectanglePoints = new Coordinate[2];
                rectanglePoints[0] = new Coordinate(rect.X, rect.Y);
                rectanglePoints[1] = new Coordinate(rect.X, rect.Y + rect.Height);
                rectanglePoly      = new LineString(rectanglePoints);
            }
            else if (rect.Height == 0)
            {
                Coordinate[] rectanglePoints = new Coordinate[2];
                rectanglePoints[0] = new Coordinate(rect.X, rect.Y);
                rectanglePoints[1] = new Coordinate(rect.X + rect.Width, rect.Y);
                rectanglePoly      = new LineString(rectanglePoints);
            }
            else
            {
                Coordinate[] rectanglePoints = new Coordinate[5];
                rectanglePoints[0] = new Coordinate(rect.X, rect.Y);
                rectanglePoints[1] = new Coordinate(rect.X, rect.Y + rect.Height);
                rectanglePoints[2] = new Coordinate(rect.X + rect.Width, rect.Y + rect.Height);
                rectanglePoints[3] = new Coordinate(rect.X + rect.Width, rect.Y);
                rectanglePoints[4] = new Coordinate(rect.X, rect.Y);
                rectanglePoly      = new Polygon(new LinearRing(rectanglePoints));
            }

            if (Shape == ModelShape.Arrow)
            {
                Coordinate[] arrowPoints = new Coordinate[_arrowPath.PointCount];
                for (int i = 0; i < _arrowPath.PointCount; i++)
                {
                    arrowPoints[i] = new Coordinate(_arrowPath.PathPoints[i].X + Location.X, _arrowPath.PathPoints[i].Y + Location.Y);
                }

                LineString arrowLine = new LineString(arrowPoints);
                return(arrowLine.Intersects(rectanglePoly));
            }

            return(false);
        }
Пример #6
0
        public void TestLineLine1()
        {
            // test when the point being tested in a node on the line
            Coordinate coordLine1 = new Coordinate(5.0, 5.0);
            Coordinate coordLine2 = new Coordinate(10.0, 10.0);
            Coordinate coordLine3 = new Coordinate(5.0, 10.0);
            Coordinate coordLine4 = new Coordinate(10.0, 5.0);


            Coordinates coordinates1 = new Coordinates();

            coordinates1.Add(coordLine1);
            coordinates1.Add(coordLine2);


            Coordinates coordinates2 = new Coordinates();

            coordinates2.Add(coordLine3);
            coordinates2.Add(coordLine4);



            LineString linestring1 = _factory.CreateLineString(coordinates1);
            LineString linestring2 = _factory.CreateLineString(coordinates2);

            Geometry pt = linestring1.Intersection(linestring2);

            Assertion.AssertEquals("intersects", true, linestring1.Intersects(linestring2));
            Assertion.AssertEquals("disjoint", false, linestring1.Disjoint(linestring2));
            Assertion.AssertEquals("contains", false, linestring1.Contains(linestring2));
            Assertion.AssertEquals("within", false, linestring1.Within(linestring2));


            Assertion.AssertEquals("crosses", true, linestring1.Crosses(linestring2));

            Assertion.AssertEquals("touches", false, linestring1.Touches(linestring2));

            // always returns false when a point is involved
            Assertion.AssertEquals("overlaps", false, linestring1.Overlaps(linestring2));
        }
        /// <summary>
        ///
        /// </summary>
        public void Start()
        {
            var pointInLine  = Factory.CreatePoint(new Coordinate(20, 10));
            var pointOutLine = Factory.CreatePoint(new Coordinate(20, 31));
            var aLine        = Factory.CreateLineString(new Coordinate[] { new Coordinate(23, 32.2), new Coordinate(922, 11) });
            var anotherLine  = Factory.CreateLineString(new Coordinate[] { new Coordinate(0, 1), new Coordinate(30, 30) });

            try
            {
                Write(line.Area);
                Write(line.Boundary);
                Write(line.BoundaryDimension);
                Write(line.Centroid);
                Write(line.Coordinate);
                Write(line.Coordinates);
                Write(line.CoordinateSequence);
                Write(line.Dimension);
                Write(line.EndPoint);
                Write(line.Envelope);
                Write(line.EnvelopeInternal);
                Write(line.InteriorPoint);
                Write(line.IsClosed);
                Write(line.IsEmpty);
                Write(line.IsRing);
                Write(line.IsSimple);
                Write(line.IsValid);
                Write(line.Length);
                Write(line.NumPoints);
                Write(line.StartPoint);
                if (line.UserData != null)
                {
                    Write(line.UserData);
                }
                else
                {
                    Write("UserData null");
                }

                Write(line.Buffer(10));
                Write(line.Buffer(10, new BufferParameters {
                    EndCapStyle = EndCapStyle.Flat
                }));
                Write(line.Buffer(10, new BufferParameters {
                    EndCapStyle = EndCapStyle.Square
                }));
                Write(line.Buffer(10, 20));
                Write(line.Buffer(10, new BufferParameters(20)
                {
                    EndCapStyle = EndCapStyle.Flat
                }));
                Write(line.Buffer(10, new BufferParameters(20)
                {
                    EndCapStyle = EndCapStyle.Square
                }));
                Write(line.Contains(pointInLine));
                Write(line.Contains(pointOutLine));
                Write(line.Crosses(pointInLine));
                Write(line.Crosses(pointOutLine));
                Write(line.Difference(pointInLine));
                Write(line.Difference(pointOutLine));
                Write(line.Disjoint(pointInLine));
                Write(line.Disjoint(pointOutLine));
                Write(line.Distance(pointInLine));
                Write(line.Distance(pointOutLine));
                Write(line.EqualsTopologically(line.Copy() as LineString));
                Write(line.EqualsExact(line.Copy() as LineString));
                Write(line.ConvexHull());
                Write(line.Intersection(pointInLine));
                Write(line.Intersection(pointOutLine));
                Write(line.Intersection(aLine));
                Write(line.Intersects(pointInLine));
                Write(line.Intersects(pointOutLine));
                Write(line.Intersects(aLine));
                Write(line.IsWithinDistance(pointOutLine, 2));
                Write(line.IsWithinDistance(pointOutLine, 222));
                Write(line.Overlaps(pointInLine));
                Write(line.Overlaps(pointOutLine));
                Write(line.Overlaps(aLine));
                Write(line.Overlaps(anotherLine));
                Write(line.Relate(pointInLine));
                Write(line.Relate(pointOutLine));
                Write(line.Relate(aLine));
                Write(line.Relate(anotherLine));
                Write(line.SymmetricDifference(pointInLine));
                Write(line.SymmetricDifference(pointOutLine));
                Write(line.SymmetricDifference(aLine));
                Write(line.SymmetricDifference(anotherLine));
                Write(line.ToString());
                Write(line.AsText());
                Write(line.Touches(pointInLine));
                Write(line.Touches(pointOutLine));
                Write(line.Touches(aLine));
                Write(line.Touches(anotherLine));
                Write(line.Union(pointInLine));
                Write(line.Union(pointOutLine));
                Write(line.Union(aLine));
                Write(line.Union(anotherLine));
                Write(line.Within(pointInLine));
                Write(line.Within(pointOutLine));
                Write(line.Within(aLine));
                Write(line.Within(anotherLine));

                string linestring         = "LINESTRING (1.2 3.4, 5.6 7.8, 9.1 10.12)";
                string anotherlinestringg = "LINESTRING (12345 3654321, 685 7777.945677, 782 111.1)";
                var    geom1 = Reader.Read(linestring);
                Write(geom1.AsText());
                var geom2 = Reader.Read(anotherlinestringg);
                Write(geom2.AsText());

                byte[] bytes = line.AsBinary();
                var    test1 = new WKBReader().Read(bytes);
                Write(test1.ToString());

                bytes = new GDBWriter().Write(line);
                test1 = new GDBReader().Read(bytes);
                Write(test1.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void RunIntersects()
 {
     Console.WriteLine("Line size: " + _line2.NumPoints);
     //@SuppressWarnings("unused")
     bool isIntersects = _line1.Intersects(_line2);
 }
Пример #9
0
        public static ILineString getMaxVector(IFeature feature)
        {
            double             max    = 0;
            Coordinate         point  = new Coordinate();
            IList <Coordinate> points = new List <Coordinate>();

            IList <Coordinate> featurePoints = new List <Coordinate>();

            foreach (var dian in feature.Geometry.Coordinates)
            {
                featurePoints.Add(dian);
            }

            for (int i = 0; i < feature.Geometry.NumPoints; i++)
            {
                double dis = feature.Geometry.Centroid.Coordinate.Distance(feature.Geometry.Coordinates[i]);
                if (max < dis)
                {
                    max   = dis;
                    point = feature.Geometry.Coordinates[i];
                }
            }
            points.Add(point);
            featurePoints.Remove(point);
            for (int i = 0; i < featurePoints.Count; i++)
            {
                double dis = feature.Geometry.Centroid.Coordinate.Distance(featurePoints[i]);
                if (max == dis)
                {
                    points.Add(featurePoints[i]);
                }
            }

            Coordinate coor = Vector.addVector(points, feature.Geometry.Centroid.Coordinate);

            Coordinate[] coors   = new Coordinate[] { feature.Geometry.Centroid.Coordinate, coor };
            ILineString  maxLine = new LineString(coors);

            if (maxLine.Intersects(feature.Geometry.Boundary))
            {
                IGeometry intersectPoints = maxLine.Intersection(feature.Geometry.Boundary);

                if (intersectPoints.Coordinates.Length > 1)
                {
                    if (coors[1].X > coors[0].X)
                    {
                        maxLine.Coordinates[1] = intersectPoints.Coordinates[intersectPoints.Coordinates.Length - 1];
                    }
                    else if (coors[1].X < coors[0].X)
                    {
                        maxLine.Coordinates[1] = intersectPoints.Coordinates[0];
                    }
                    else if (coors[1].X == coors[0].X)
                    {
                        if (coors[1].Y > coors[0].Y)
                        {
                            maxLine.Coordinates[1] = intersectPoints.Coordinates[intersectPoints.Coordinates.Length - 1];
                        }
                        else if (coors[1].Y < coors[0].Y)
                        {
                            maxLine.Coordinates[1] = intersectPoints.Coordinates[0];
                        }
                    }
                }
                else
                {
                    maxLine.Coordinates[1] = intersectPoints.Coordinate;
                }
            }
            return(maxLine);
        }
Пример #10
0
        private void getMaxMinAngle(IFeature feature)
        {
            IList <ILineString> lines    = new List <ILineString>();
            Coordinate          centroid = feature.Geometry.Centroid.Coordinate;
            Coordinate          origin   = new Coordinate();

            origin.X = MaxPoints.getMaxVector(feature).Coordinates[1].X - centroid.X;
            origin.Y = MaxPoints.getMaxVector(feature).Coordinates[1].Y - centroid.Y;    //最大点平移到自定义坐标系

            for (int i = 5; i <= 361; i += 5)
            {
                double angle = getAngle(origin);
                double k     = 0;
                angle += i;

                if (angle > 360)  //若角大于360,减去360
                {
                    angle -= 360;
                }

                k = Math.Tan(angle * Math.PI / 180);


                Coordinate point = new Coordinate();  //判定每隔5度的点落在1.4象限,2,3象限,或者X轴上
                if (angle > 90 && angle < 270)
                {
                    point.X = -100000.0;
                    point.Y = k * point.X;
                }
                else if ((angle >= 0 && angle < 90) || (angle > 270 && angle <= 360))
                {
                    point.X = 100000.0;
                    point.Y = k * point.X;
                }
                else if (angle == 90)
                {
                    point.X = 0;
                    point.Y = 100000.0;
                }
                else if (angle == 270)
                {
                    point.X = 0;
                    point.Y = -100000.0;
                }
                point.X += centroid.X; //将点移动回到原空间投影坐标系
                point.Y += centroid.Y;



                Coordinate[] points = new Coordinate[] { centroid, point };
                LineString   line   = new LineString(points);
                if (!line.Intersects(feature.Geometry.Boundary)) //如果所得线段与边界不相交,跳出当前循环,进入下个循环
                {
                    continue;
                }

                IGeometry intersectPoints = line.Intersection(feature.Geometry.Boundary);

                if (intersectPoints.Coordinates.Length > 1)
                {
                    if (points[1].X > points[0].X)
                    {
                        line.Coordinates[1] = intersectPoints.Coordinates[intersectPoints.Coordinates.Length - 1];
                    }
                    else if (points[1].X < points[0].X)
                    {
                        line.Coordinates[1] = intersectPoints.Coordinates[0];
                    }
                    else if (points[1].X == points[0].X)
                    {
                        if (points[1].Y > points[0].Y)
                        {
                            line.Coordinates[1] = intersectPoints.Coordinates[intersectPoints.Coordinates.Length - 1];
                        }
                        else if (points[1].Y < points[0].Y)
                        {
                            line.Coordinates[1] = intersectPoints.Coordinates[0];
                        }
                    }
                }
                else
                {
                    line.Coordinates[1] = intersectPoints.Coordinate;
                }
                lines.Add(line);
            }

            lines.Add(lines[0]);


            double titio = 0;

            for (int i = 0; i < lines.Count - 1; i++)
            {
                double b = centroid.Distance(lines[i + 1].Coordinates[1]);
                double a = centroid.Distance(lines[i].Coordinates[1]);
                double h = b * Math.Sin(5 * Math.PI / 180);
                titio = 1 - h / (h + a);
                Titio.Add(titio);
            }
        }