Exemplo n.º 1
0
        public static bool SelfOverlaps(this LineString instance)
        {
            if (instance.Length <= 0.0 || instance.NumPoints <= 2)
            {
                return(false);
            }

            var lines     = new LineString[instance.NumPoints - 1];
            var fromPoint = instance.StartPoint;

            for (var index = 1; index < instance.NumPoints; index++)
            {
                var toPoint = instance.GetPointN(index);
                lines[index - 1] =
                    new LineString(
                        new CoordinateArraySequence(
                            new[]
                {
                    new Coordinate(Math.Round(fromPoint.X, 3), Math.Round(fromPoint.Y, 3)),
                    new Coordinate(toPoint.X, toPoint.Y)
                })
                        , GeometryConfiguration.GeometryFactory);
                fromPoint = toPoint;
            }

            return
                ((
                     from left in lines
                     from right in lines
                     where !ReferenceEquals(left, right)
                     select left.Overlaps(right) || left.Covers(right)
                     ).Any(overlaps => overlaps));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the computed variable-width line buffer.
        /// </summary>
        /// <returns>A polygon</returns>
        public Geometry GetResult()
        {
            Utilities.Assert.IsTrue(_line.NumPoints == _width.Length);

            var parts = new List <Geometry>();

            var pts = _line.Coordinates;

            for (int i = 0; i < _line.NumPoints; i++)
            {
                double dist  = _width[i] / 2;
                var    ptBuf = _line.GetPointN(i).Buffer(dist);
                parts.Add(ptBuf);

                if (i >= 1)
                {
                    var curvePts = GenerateSegmentCurve(pts[i - 1], pts[i],
                                                        _width[i - 1], _width[i]);
                    var segBuf = _geomFactory.CreatePolygon(curvePts);
                    parts.Add(segBuf);
                }
            }

            var partsGeom = _geomFactory.CreateGeometryCollection(GeometryFactory.ToGeometryArray(parts));
            var buffer    = partsGeom.Union();

            return(buffer);
        }
Exemplo n.º 3
0
        public void test_Point()
        {
            LineString ls = SimpleOpen();

            Point point = ls.GetPointN(4);

            Assertion.AssertEquals("Point-1: ", 5.0, point.X);
            Assertion.AssertEquals("Point-2: ", 5.0, point.Y);
        }
Exemplo n.º 4
0
        public void test_PointN()
        {
            LineString ls = SimpleOpen();

            Coordinate coord  = new Coordinate(11.0, 12.0);
            Coordinate coord2 = new Coordinate(11.0, 20.0);
            Coordinate coord3 = new Coordinate(0.0, 0.0);

            GeometryFactory gf     = new GeometryFactory(_precMod, _sRID);
            Point           point  = gf.CreatePoint(coord);
            Point           point2 = gf.CreatePoint(coord2);
            Point           point3 = gf.CreatePoint(coord);

            Point testPoint = ls.GetPointN(11) as Point;

            Assertion.AssertEquals("PointN: ", true, testPoint.Equals(point));
        }
Exemplo n.º 5
0
        private void ImageToWorld_Rotation(float deg)
        {
            var map = new Map(new Size(1000, 500))
            {
                BackColor = System.Drawing.Color.LightSkyBlue
            };

            map.Zoom   = 1000;
            map.Center = new Point(25000, 75000);
            double mapScale = map.GetMapScale(96);

            double scaleX = 1;
            double scaleY = 1;

            System.Drawing.Drawing2D.Matrix mapTransform = new System.Drawing.Drawing2D.Matrix();
            mapTransform.RotateAt(deg, new PointF(map.Size.Width / 2f, map.Size.Height / 2f));
            map.MapTransform = mapTransform;

            var env = map.Envelope;

            // Affine Transformation:
            // 1: Translate to mapViewPort centre
            // 2: Reflect in X-Axis
            // 3: Rotation about mapViewPort centre
            // 4: Scale to map units
            // 5: Translate to map centre

            //CLOCKWISE affine transform (negate degrees)
            //double rad = -1 * deg * Math.PI / 180.0;
            //GeoAPI.CoordinateSystems.Transformations.IMathTransform trans =
            //    new ProjNet.CoordinateSystems.Transformations.AffineTransform(
            //        scaleX * Math.Cos(rad),
            //        -scaleX * Math.Sin(rad),
            //        -scaleX * Math.Cos(rad) * map.Size.Width / 2f + scaleX * Math.Sin(rad) * map.Size.Height / 2f + map.Center.X,
            //        -scaleY * Math.Sin(rad),
            //        -scaleY * Math.Cos(rad),
            //        scaleY * Math.Sin(rad) * map.Size.Width / 2f + scaleY * Math.Cos(rad) * map.Size.Height / 2f + map.Center.Y);

            //ANTICLCOCKWISE affine transform
            double rad = deg * Math.PI / 180.0;

            GeoAPI.CoordinateSystems.Transformations.IMathTransform trans =
                new ProjNet.CoordinateSystems.Transformations.AffineTransform(
                    scaleX * Math.Cos(rad),
                    scaleX * Math.Sin(rad),
                    -scaleX * Math.Cos(rad) * map.Size.Width / 2d - scaleX * Math.Sin(rad) * map.Size.Height / 2d + map.Center.X,
                    scaleY * Math.Sin(rad),
                    -scaleY * Math.Cos(rad),
                    -scaleY * Math.Sin(rad) * map.Size.Width / 2d + scaleY * Math.Cos(rad) * map.Size.Height / 2d + map.Center.Y);

            // image coordindates
            var pts = new[] { new Point(map.Size.Width / 2f, map.Size.Height / 2f),     // centre
                              new Point(0, 0),                                          // UL
                              new Point(map.Size.Width, 0),                             // UR
                              new Point(map.Size.Width, map.Size.Height),               // LR
                              new Point(0, map.Size.Height),                            // LL
                              new Point(map.Size.Width * 0.05, map.Size.Height * 0.95), // LL inset 5%
                              new Point(map.Size.Width * 0.95, map.Size.Height * 0.95), // LR inset 5%
                              new Point(map.Size.Width * 0.95, map.Size.Height * 0.05), // UR inset 5%
                              new Point(map.Size.Width * 0.05, map.Size.Height * 0.05)  // UL inset 5%
            };

            LineString lineString = new LineString(pts);

            NetTopologySuite.CoordinateSystems.Transformations.GeometryTransform.TransformLineString(new GeometryFactory(new PrecisionModel()), lineString, trans);

            // .Net Matrix
            //System.Drawing.Drawing2D.Matrix matrix;
            //matrix = new System.Drawing.Drawing2D.Matrix();
            //matrix.Translate(-map.Size.Width / 2f, -map.Size.Height / 2f);      // shift origin to viewport centre
            //matrix.Scale(1, -1, System.Drawing.Drawing2D.MatrixOrder.Append);   // reflect in X axis
            //matrix.Rotate(deg, System.Drawing.Drawing2D.MatrixOrder.Append);    // rotate about viewport centre
            //matrix.Scale((float)scaleX, (float)scaleY, System.Drawing.Drawing2D.MatrixOrder.Append); // scale
            //matrix.Translate((float)map.Center.X, (float)map.Center.Y, System.Drawing.Drawing2D.MatrixOrder.Append); // translate to map centre

            //var ptsF = new[] { new PointF(map.Size.Width / 2f, map.Size.Height / 2f), // centre
            //                new PointF(0, 0),                            // UL
            //                new PointF(map.Size.Width, 0),               // UR
            //                new PointF(map.Size.Width, map.Size.Height), // LR
            //                new PointF(0, map.Size.Height) };            // LL

            //matrix.TransformPoints(ptsF);

            // validate ImageToWorld calcs with independent affine transformation
            Assert.IsTrue(lineString.GetPointN(0).Coordinate.Equals2D(map.ImageToWorld(new PointF(map.Size.Width / 2f, map.Size.Height / 2f), true), 0.001), "Centre: " + deg + " deg");
            Assert.IsTrue(lineString.GetPointN(1).Coordinate.Equals2D(map.ImageToWorld(new PointF(0, 0), true), 0.001), "Upper Left: " + deg + " deg");
            Assert.IsTrue(lineString.GetPointN(2).Coordinate.Equals2D(map.ImageToWorld(new PointF(map.Size.Width, 0), true), 0.001), "Upper Right: " + deg + " deg");
            Assert.IsTrue(lineString.GetPointN(3).Coordinate.Equals2D(map.ImageToWorld(new PointF(map.Size.Width, map.Size.Height), true), 0.001), "Lower Right: " + deg + " deg");
            Assert.IsTrue(lineString.GetPointN(4).Coordinate.Equals2D(map.ImageToWorld(new PointF(0, map.Size.Height), true), 0.001), "Lower Left: " + deg + " deg");

            // validate map envelope: lineString outline = image extents, so lineString.EnvelopeInternal should equal map.Envelope
            // this test found long-standing bug in Map.Envelope calcs
            Assert.IsTrue(env.BottomLeft().Equals2D(lineString.EnvelopeInternal.BottomLeft(), 0.1));
            Assert.IsTrue(env.TopLeft().Equals2D(lineString.EnvelopeInternal.TopLeft(), 0.1));
            Assert.IsTrue(env.TopRight().Equals2D(lineString.EnvelopeInternal.TopRight(), 0.1));
            Assert.IsTrue(env.BottomRight().Equals2D(lineString.EnvelopeInternal.BottomRight(), 0.1));

            // visual checks
            var vl = new VectorLayer("Test Points");
            var gp = new GeometryProvider(lineString);

            gp.Geometries.Add(new NetTopologySuite.Geometries.Point(25000, 75000));
            vl.DataSource = gp;
            var cps = new SharpMap.Rendering.Symbolizer.CharacterPointSymbolizer();

            cps.CharacterIndex       = 221;
            cps.Font                 = new Font("Wingdings", 30);
            vl.Style.PointSymbolizer = cps;
            map.Layers.Add(vl);

            map.ZoomToBox(lineString.EnvelopeInternal);

            string fn = $"MapRotation_{deg:000}_{map.Zoom:0}_{map.MapScale:0}.bmp";

            using (var img = map.GetMap(96))
                img.Save(fn, System.Drawing.Imaging.ImageFormat.Bmp);

            map.Dispose();
        }