예제 #1
0
 //GET /api/routing?from=31.8239,35.0375&to=31.8213,35.0965&type=f
 public async Task<IHttpActionResult> GetRouting(string from, string to, string type)
 {
     LineString lineString;
     var profile = ConvertProfile(type);
     var pointFrom = await GetGeographicPosition(from);
     var pointTo = await GetGeographicPosition(to);
     if (ModelState.IsValid == false)
     {
         return BadRequest(ModelState);
     }
     if (profile == ProfileType.None)
     {   
         lineString = new LineString(new[] { pointFrom, pointTo });
     }
     else
     {
         lineString = await _routingGateway.GetRouting(new RoutingGatewayRequest
         {
             From = from,
             To = to,
             Profile = profile,
         });
     }
     var table = new AttributesTable();
     table.AddAttribute("Name", "Routing from " + from + " to " + to + " profile type: " + profile);
     table.AddAttribute("Creator", "IsraelHikingMap");
     var feature = new Feature(lineString, table);
     return Ok(new FeatureCollection(new Collection<IFeature> { feature }));
 }
        internal IEnumerable <DiagramObject> CreateDiagramObjects()
        {
            List <DiagramObject> result = new List <DiagramObject>();

            if (LineShapeType == LineShapeTypeEnum.Polygon)
            {
                NetTopologySuite.Geometries.LineString curve1 = CreateCurve(-4, -4);
                NetTopologySuite.Geometries.LineString curve2 = CreateCurve(+4, +4);

                List <Coordinate> pnts = new List <Coordinate>();

                // Start
                pnts.AddRange(curve1.Coordinates);
                var reversedCurve2 = curve2.Reverse();
                pnts.AddRange(reversedCurve2.Coordinates);
                // complete poly
                pnts.Add(curve1.StartPoint.Coordinate);

                var ring = new LinearRing(pnts.ToArray());

                var poly = new Polygon(ring);

                result.Add(new DiagramObject()
                {
                    IdentifiedObject = _refClass == null ? null : new IdentifiedObjectReference()
                    {
                        RefId = _refId, RefClass = _refClass
                    },
                    Style    = Style is null ? "Cable" : Style,
                    Label    = this.Label,
                    Geometry = poly
                });
        public void TestSTDistance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var point = new NTSG.Point(new NTSG.Coordinate(-72.1235, 42.3521))
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeometryEntity(1, point));
                var lineString = new NTSG.LineString(new[] { new NTSG.Coordinate(-72.1260, 42.45), new NTSG.Coordinate(-72.123, 42.1546) })
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeometryEntity(2, lineString));

                // Geometry example - units in planar degrees 4326 is WGS 84 long lat, units are degrees.
                var distances4326 = db.TestGeometries.Select(g => g.Geometry.STDistance(point)).ToList();

                Assert.AreEqual(2, distances4326.Count);
                Assert.AreEqual(0.0, distances4326[0]);
                Assert.AreEqual(0.00150567726382822, distances4326[1], 1.0E9);

                // Geometry example - units in meters (SRID:3857, proportional to pixels on popular web maps).
                var distances3857 = db.TestGeometries.Select(g => g.Geometry.STTransform(SRID3857).STDistance(point.STTransform(SRID3857))).ToList();

                Assert.AreEqual(2, distances3857.Count);
                Assert.AreEqual(0.0, distances3857[0]);
                Assert.AreEqual(167.441410065196, distances3857[1], 1.0E9);

                var nullDistance = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STDistance(null)).Single();
                Assert.IsNull(nullDistance);
            }
        }
        public void GetMissingLines_GpxWithoutEnoughPoints_ShouldReturnEmptyList()
        {
            var gpxLine = new LineString(new[] {new Coordinate(1, 1), new Coordinate(2, 2)});

            var results = _service.GetMissingLines(gpxLine, new LineString[0], 200, 30);

            Assert.AreEqual(0, results.Count);
        }
        public void GetMissingLines_GpxDistanceIsTooSmall_ShouldReturnEmptyResults()
        {
            var gpxLines = new LineString(new[] {new Coordinate(1, 1), new Coordinate(2, 2), new Coordinate(3, 3)});

            var results = _service.GetMissingLines(gpxLines, new LineString[0], 200, 30);

            Assert.AreEqual(0, results.Count);
        }
        public void GetMissingLines_SimpleGpx_ShouldReturnIt()
        {
            var gpxLine = new LineString(new[] {new Coordinate(1, 1), new Coordinate(20, 20), new Coordinate(300, 300)});

            var results = _service.GetMissingLines(gpxLine, new LineString[0], 200, 30);

            Assert.AreEqual(1, results.Count);
        }
예제 #7
0
        public void Segments()
        {
            var a = new LineString(new[] { p0, p1, p2, p3 });

            var segments = a.Segments().ToList();

            Assert.AreEqual(3, segments.Count);
            AssertLineSegment(segments[0], p0, p1);
            AssertLineSegment(segments[1], p1, p2);
            AssertLineSegment(segments[2], p2, p3);
        }
예제 #8
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            NetTopologySuite.Geometries.LineString NTGeometry = (value as NetTopologySuite.Geometries.LineString);
            List <Avalonia.Point> list = new List <Avalonia.Point>();

            foreach (var coordinate in NTGeometry.Coordinates)
            {
                list.Add(new Avalonia.Point(coordinate.X, coordinate.Y));
            }

            return(list.ToArray());
        }
예제 #9
0
        public void Points()
        {
            var a = new LineString(new[] { p0, p1, p2, p3 });

            var points = a.Points().ToList();

            Assert.AreEqual(4, points.Count);
            AssertCoordinates(p0, points[0]);
            AssertCoordinates(p1, points[1]);
            AssertCoordinates(p2, points[2]);
            AssertCoordinates(p3, points[3]);
        }
        public void TestSTIntersects()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "LINESTRING ( 2 0, 0 2 )";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert();

                const string Wkt2 = "LINESTRING ( 0 0, 0 2 )";
                db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2)).Insert();

                const string PointWkt = "POINT(0 0)";
                var          point    = new NTSGS.Point(new NTSGS.Coordinate(0, 0));

                Assert.IsFalse(db.TestGeometries
                               .Where(g => g.Id == 1)
                               .Select(g => g.Geometry.STIntersects(point))
                               .Single());

                Assert.IsTrue(db.TestGeometries
                              .Where(g => g.Id == 2)
                              .Select(g => g.Geometry.STIntersects(point))
                              .Single());

                Assert.IsNull(db.TestGeometries
                              .Where(g => g.Id == 2)
                              .Select(g => g.Geometry.STIntersects(null))
                              .Single());

                Assert.IsFalse(db.Select(() => SpatialRelationships.STIntersects(Wkt1, PointWkt)));
                Assert.IsTrue(db.Select(() => SpatialRelationships.STIntersects(Wkt2, PointWkt)));
                Assert.IsNull(db.Select(() => SpatialRelationships.STIntersects((string)null, (string)null)));

                // geography
                var lineGeography = new NTSGS.LineString(new[] { new NTSGS.Coordinate(-43.23456, 72.4567), new NTSGS.Coordinate(-43.23456, 72.4568) })
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeographyEntity(1, lineGeography));

                var pointGeography = new NTSGS.Point(-43.23456, 72.4567)
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeographyEntity(2, pointGeography));

                var intersects = db.TestGeographies
                                 .Where(g => g.Id == 1)
                                 .Select(g => g.Geography.STIntersects(db.TestGeographies.Where(g0 => g0.Id == 2).Single().Geography))
                                 .Single();

                Assert.IsTrue(intersects);
            }
        }
예제 #11
0
 public void Test()
 {
     var x = LonLat_to_Merc(new Coordinate(37.8686517, 47.94573));
     var y = LonLat_to_Merc(new Coordinate(37.8686533, 47.9457283));
     var x1 = new Coordinate(37.8686517, 47.94573);
     var y1 = new Coordinate(37.8686533, 47.9457283);
     LineString s = new LineString(new Coordinate[] { x, y });
     Console.WriteLine(s.Length);
     double f = GetDistance(x1, y1);
     Console.WriteLine(f);
     Assert.AreEqual(s.Length, f,0.01);
 }
        private static void CheckLineEquals(double[][] expected, NTSGS.LineString actual, double tolerance)
        {
            var pointsCount    = expected.Length;
            var dimensionCount = expected[0].Length; // Depends on 2D / 3D geometry dimensions

            for (var i = 0; i < pointsCount; i++)
            {
                for (var j = 0; j < dimensionCount; j++)
                {
                    var exp = expected[i][j];
                    var res = actual.GetCoordinateN(i).CoordinateValue[j];

                    Assert.AreEqual(exp, res, tolerance);
                }
            }
        }
        private void CheckLineEquals(double[][] expected, NTSG.LineString result, double tolerance)
        {
            var pointsCount    = expected.Length;
            var dimensionCount = expected[0].Length;

            for (int i = 0; i < pointsCount; i++)
            {
                for (int j = 0; j < dimensionCount; j++)
                {
                    var exp = expected[i][j];
                    var res = result.GetCoordinateN(i).CoordinateValue[j];

                    Assert.AreEqual(exp, res, tolerance);
                }
            }
        }
        internal IEnumerable <DiagramObject> CreateDiagramObjects(Diagram diagram)
        {
            List <DiagramObject> result = new List <DiagramObject>();


            NetTopologySuite.Geometries.LineString curve = CreateCurve(0, 0, 0);

            result.Add(new DiagramObject(diagram)
            {
                IdentifiedObject = _refClass == null ? null : new IdentifiedObjectReference()
                {
                    RefId = _refId, RefClass = _refClass
                },
                Style        = Style is null ? "Cable" : Style,
                Label        = this.Label,
                Geometry     = curve,
                DrawingOrder = DrawingOrder
            });
        public void GetMissingLines_GpxCloseToALine_ShouldSplitIt()
        {
            var gpxLine = new LineString(new[]
            {
                new Coordinate(1, 1),
                new Coordinate(20, 20),
                new Coordinate(300, 300),
                new Coordinate(400, 400),
                new Coordinate(500, 500),
                new Coordinate(600, 600),
                new Coordinate(700, 700),
            });

            var results = _service.GetMissingLines(gpxLine,
                new[] {new LineString(new[] {new Coordinate(399, 399), new Coordinate(399, 0)})}, 200, 30);

            Assert.AreEqual(2, results.Count);
        }
        public void SplitSelfLoops_GpxSharpTShape_ShouldSplitIt()
        {
            var gpxLine = new LineString(new[]
            {
                new Coordinate(0, 0),
                new Coordinate(100, 0),
                new Coordinate(200, 0),
                new Coordinate(300, 0),
                new Coordinate(300, 300),
                new Coordinate(301, 0),
                new Coordinate(400, 0),
                new Coordinate(600, 0)
            });

            var results = _service.SplitSelfLoops(gpxLine, 30);

            Assert.AreEqual(2, results.Count);
            Assert.AreEqual(4, results.First().Count);
            Assert.AreEqual(4, results.Last().Count);
        }
예제 #17
0
        private async Task AddTestData()
        {
            var point = new NetTopologySuite.Geometries.Point(new Coordinate(10, 10));

            point.SRID = srid;
            _dbContext.Cities.Add(new City()
            {
                CityName = "ChengDu",
                Location = point
            });
            var line = new NetTopologySuite.Geometries.LineString(new Coordinate[]
            {
                new Coordinate(0, 0),
                new Coordinate(10, 0),
                new Coordinate(10, 10),
                new Coordinate(0, 10)
            });

            line.SRID = srid;
            _dbContext.Roads.Add(new Road()
            {
                RoadName = "Road Name 1",
                Line     = line
            });
            var border = new NetTopologySuite.Geometries.Polygon(new LinearRing(new Coordinate[]
            {
                new Coordinate(0, 0),
                new Coordinate(10, 0),
                new Coordinate(10, 10),
                new Coordinate(0, 10),
                new Coordinate(0, 0)
            }));

            border.SRID = srid;
            _dbContext.Countries.Add(new Country()
            {
                CountryName = "China",
                Border      = border
            });
            await _dbContext.SaveChangesAsync();
        }
예제 #18
0
        public void Distance_Lines()
        {
            var a = new LineString(new[]
                        {
                            new Coordinate(5, 10),
                            new Coordinate(19, 11),
                            new Coordinate(6, 10.5),
                        });

            var b = new LineString(new[]
                        {
                            new Coordinate(16, 35),
                            new Coordinate(22, 57),
                            new Coordinate(122, 213),
                            new Coordinate(574, 112),
                        });

            var distance = Hausdorff.Distance(a, b);

            Assert.AreEqual(27.313000567495326, distance);
        }
예제 #19
0
 private bool IsClosingALoop(LineString gpxLine, int currentIndex, double closestPointTolerance)
 {
     int indexOfLinePrefix = currentIndex - 1;
     var currentCoordinatePoint = new Point(gpxLine[currentIndex]);
     while (indexOfLinePrefix >= 0)
     {
         if (currentCoordinatePoint.Distance(new Point(gpxLine.Coordinates[indexOfLinePrefix])) >
             closestPointTolerance)
         {
             break;
         }
         indexOfLinePrefix--;
     }
     if (indexOfLinePrefix < 0)
     {
         return false;
     }
     var distance = indexOfLinePrefix > 0
             ? currentCoordinatePoint.Distance(new LineString(gpxLine.Coordinates.Take(indexOfLinePrefix + 1).ToArray()))
             : currentCoordinatePoint.Distance(new Point(gpxLine.Coordinates[indexOfLinePrefix]));
     return distance < closestPointTolerance;
 }
예제 #20
0
 /// <summary>
 /// This part of this splitter will remove line that already exsits and will split lines that are close to an exsiting line.
 /// This can be used with both OSM lines and other parts of the same GPS trace.
 /// The algorithm is faily simple - 
 /// Go over all the points in the given <see cref="gpxLine"/> and look for point that are close to <see cref="existingLineStrings"/>
 /// </summary>
 /// <param name="gpxLine">The line to manipulate</param>
 /// <param name="existingLineStrings">The lines to test agains</param>
 /// <param name="minimalMissingPartLength">The minimal length allowed to a trace that can be added</param>
 /// <param name="closestPointTolerance">The distace of the closest point allowed</param>
 /// <returns>a split line from the orignal line</returns>
 public List<LineString> GetMissingLines(LineString gpxLine, IReadOnlyList<LineString> existingLineStrings, double minimalMissingPartLength, double closestPointTolerance)
 {
     var gpxSplit = new List<LineString>();
     var waypointsGroup = new List<Coordinate>();
     foreach (var coordinate in gpxLine.Coordinates)
     {
         if (waypointsGroup.Count > 0 && waypointsGroup.Last().Equals(coordinate))
         {
             continue;
         }
         if (IsCloseToALine(coordinate, existingLineStrings.Concat(gpxSplit).ToArray(), closestPointTolerance))
         {
             waypointsGroup.Add(coordinate);
             AddLineString(gpxSplit, waypointsGroup.ToArray());
             waypointsGroup = new List<Coordinate> { coordinate };
             continue;
         }
         waypointsGroup.Add(coordinate);
     }
     AddLineString(gpxSplit, waypointsGroup.ToArray());
     return gpxSplit.Where(l => l.Length > minimalMissingPartLength).ToList();
 }
예제 #21
0
        public IActionResult CreateRoad(string roadName)
        {
            //LinearRing的点必须形成一个封闭的线串,而LineString则不需要
            var line = new NetTopologySuite.Geometries.LineString(new Coordinate[]
            {
                new Coordinate(10, 0),
                new Coordinate(10, 10),
                new Coordinate(0, 10),
                new Coordinate(0, 0),
                //new Coordinate(10,0),
            });

            //设置坐标系
            line.SRID = srid;
            _dbContext.Roads.Add(new Road()
            {
                RoadName = roadName,
                Line     = line
            });
            _dbContext.SaveChanges();
            return(Json("ok"));
        }
예제 #22
0
        private void TestShapeCreation()
        {
            var points = new Coordinate[3];
            points[0] = new Coordinate(0, 0);
            points[1] = new Coordinate(1, 0);
            points[2] = new Coordinate(1, 1);

            var line_string = new LineString(points);

            var attributes = new AttributesTable();
            attributes.AddAttribute("FOO", "FOO");

            var feature = new Feature(Factory.CreateMultiLineString(new ILineString[] { line_string }), attributes);
            var features = new Feature[1];
            features[0] = feature;

            var shp_writer = new ShapefileDataWriter("line_string")
            {
                Header = ShapefileDataWriter.GetHeader(features[0], features.Length)
            };
            shp_writer.Write(features);             
        }
예제 #23
0
        /// <summary>
        /// This part of the splitter if responsible for splitting a line with a self loop.
        /// It will allway return lines that do not have self loop, but can be duplicate of one another
        /// Use <see cref="GetMissingLines"/> method to remove those duplications.
        /// </summary>
        /// <param name="gpxLine">The line to look for self loops in</param>
        /// <returns>a list of lines that do not have self loops</returns>
        public List<LineString> SplitSelfLoops(LineString gpxLine, double closestPointTolerance)
        {
            var lines = new List<LineString>();
            gpxLine = (LineString)gpxLine.Reverse();

            int coordinateIndex = 0;
            while (coordinateIndex < gpxLine.Coordinates.Length)
            {
                if (IsClosingALoop(gpxLine, coordinateIndex, closestPointTolerance) == false)
                {
                    coordinateIndex++;
                    continue;
                }
                AddLineString(lines, gpxLine.Coordinates.Take(coordinateIndex).ToArray());
                gpxLine = new LineString(gpxLine.Coordinates.Skip(coordinateIndex).ToArray());
                coordinateIndex = 0;
            }
            AddLineString(lines, gpxLine.Coordinates);

            lines = lines.Select(l => (LineString)l.Reverse()).ToList();
            lines.Reverse();
            return lines;
        }
 /// <summary>
 /// Gets the geometry for the edges in the subdivision as a <see cref="IMultiLineString"/>
 /// containing 2-point lines.
 /// </summary>
 /// <param name="geomFact">the GeometryFactory to use</param>
 /// <returns>a IMultiLineString</returns>
 public IMultiLineString GetEdges(IGeometryFactory geomFact)
 {
     var quadEdges = GetPrimaryEdges(false);
     ILineString[] edges = new LineString[quadEdges.Count];
     int i = 0;
     foreach (var qe in quadEdges)
     {
         edges[i++] = geomFact.CreateLineString(new[] {
                                                 qe.Orig.Coordinate, qe.Dest.Coordinate });
     }
     return geomFact.CreateMultiLineString(edges);
 }
        public void SplitSelfLoops_Gpx90DegreesLassoShape_ShouldSplitItAndRemoveDuplication()
        {
            var gpxLine = new LineString(new[]
            {
                new Coordinate(0, 0),
                new Coordinate(100, 0),
                new Coordinate(175, 0),
                new Coordinate(400, 0),
                new Coordinate(400, 200),
                new Coordinate(200, 200),
                new Coordinate(200, 1),
                new Coordinate(150, 1),
                new Coordinate(0, 1)
            });

            var results = _service.SplitSelfLoops(gpxLine, 30);

            Assert.AreEqual(2, results.Count);
            Assert.AreEqual(3, results.First().Count);
            Assert.AreEqual(6, results.Last().Count);
        }
        [Ignore] // I still son't have a solution for this.
        public void SplitSelfLoops_GpxXShape_ShouldSplitItAndRemoveDuplication()
        {
            var gpxLine = new LineString(new[]
            {
                new Coordinate(0, 0),
                new Coordinate(20, 0),
                new Coordinate(300, 300),
                new Coordinate(0, 300),
                new Coordinate(300, 0),
                new Coordinate(320, 0),
            });

            var results = _service.SplitSelfLoops(gpxLine, 30);

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(3, results.First().Count);
        }
        // see https://code.google.com/p/nettopologysuite/issues/detail?id=146
        public void Issue146_ShapeCreationWithInvalidAttributeName()
        {
            Coordinate[] points = new Coordinate[3];
            points[0] = new Coordinate(0, 0);
            points[1] = new Coordinate(1, 0);
            points[2] = new Coordinate(1, 1);
            LineString ls = new LineString(points);
            IMultiLineString mls = GeometryFactory.Default.CreateMultiLineString(new ILineString[] { ls });

            AttributesTable attrs = new AttributesTable();
            attrs.AddAttribute("Simulation name", "FOO");

            Feature[] features = new[] { new Feature(mls, attrs) };
            ShapefileDataWriter shp_writer = new ShapefileDataWriter("invalid_line_string")
            {
                Header = ShapefileDataWriter.GetHeader(features[0], features.Length)
            };
            shp_writer.Write(features);
        }
예제 #28
0
 private async Task<bool> CanBeMerged(Coordinate coordinate1, Coordinate coordinate2, List<LineString> simplifiedLines)
 {
     var newLine = new LineString(new[] {coordinate1, coordinate2});
     if (newLine.Length >= CLOSEST_POINT_TOLERANCE*2)
     {
         return false;
     }
     var linesInArea = await GetLineStringsInArea(newLine);
     if (linesInArea.Concat(simplifiedLines).Any(l => l.Intersects(newLine)))
     {
         return false;
     }
     return true;
 }
예제 #29
0
        /** See {@link #unwrapDateline(Geometry)}. */
        private static int UnwrapDateline(LineString lineString)
        {
            var cseq = lineString.CoordinateSequence;
            int size = cseq.Count;
            if (size <= 1)
                return 0;

            int shiftX = 0;//invariant: == shiftXPage*360
            int shiftXPage = 0;
            int shiftXPageMin = 0/* <= 0 */, shiftXPageMax = 0; /* >= 0 */
            double prevX = cseq.GetX(0);
            for (int i = 1; i < size; i++)
            {
                double thisX_orig = cseq.GetX(i);
                Debug.Assert(thisX_orig >= -180 && thisX_orig <= 180);// : "X not in geo bounds";
                double thisX = thisX_orig + shiftX;
                if (prevX - thisX > 180)
                {//cross dateline from left to right
                    thisX += 360;
                    shiftX += 360;
                    shiftXPage += 1;
                    shiftXPageMax = Math.Max(shiftXPageMax, shiftXPage);
                }
                else if (thisX - prevX > 180)
                {//cross dateline from right to left
                    thisX -= 360;
                    shiftX -= 360;
                    shiftXPage -= 1;
                    shiftXPageMin = Math.Min(shiftXPageMin, shiftXPage);
                }
                if (shiftXPage != 0)
                    cseq.SetOrdinate(i, Ordinate.X, thisX);
            }
            if (lineString is LinearRing)
            {
                Debug.Assert(cseq.GetCoordinate(0).Equals(cseq.GetCoordinate(size - 1)));
                Debug.Assert(shiftXPage == 0);//starts and ends at 0
            }
            Debug.Assert(shiftXPageMax >= 0 && shiftXPageMin <= 0);
            //Unfortunately we are shifting again; it'd be nice to be smarter and shift once
            ShiftGeomByX(lineString, shiftXPageMin * -360);
            int crossings = shiftXPageMax - shiftXPageMin;
            if (crossings > 0)
                lineString.GeometryChanged();
            return crossings;
        }
예제 #30
0
 private void MergeBackLines(List<LineString> missingLines)
 {
     for (int lineIndex = missingLines.Count - 1; lineIndex >= 1; lineIndex--)
     {
         var currentLineCoordinates = missingLines[lineIndex].Coordinates.ToList();
         var previousLineCoordinates = missingLines[lineIndex - 1].Coordinates;
         if (!currentLineCoordinates.First().Equals2D(previousLineCoordinates.Last()))
         {
             continue;
         }
         currentLineCoordinates.RemoveAt(0);
         missingLines[lineIndex - 1] = new LineString(previousLineCoordinates.Concat(currentLineCoordinates).ToArray());
         missingLines.RemoveAt(lineIndex);
     }
 }
예제 #31
0
 private void SplitLinesByNumberOfPoints(List<LineString> lineStings)
 {
     bool needToLinesToSplit;
     do
     {
         needToLinesToSplit = false;
         for (int lineIndex = 0; lineIndex < lineStings.Count; lineIndex++)
         {
             var line = lineStings[lineIndex];
             if (line.Count <= MAX_NUMBER_OF_POINTS_PER_LINE)
             {
                 continue;
             }
             needToLinesToSplit = true;
             var newLine = new LineString(line.Coordinates.Skip(line.Count/2).ToArray());
             if (lineIndex == lineStings.Count - 1)
             {
                 lineStings.Add(newLine);
             }
             else
             {
                 lineStings.Insert(lineIndex + 1, newLine);
             }
             lineStings[lineIndex] = new LineString(line.Coordinates.Take(line.Count/2 + 1).ToArray());
         }
     } while (needToLinesToSplit);
 }
예제 #32
0
 private async Task<List<LineString>> GetLineStringsInArea(LineString gpxLine)
 {
     var northEast = _coordinatesConverter.ItmToWgs84(new NorthEast
     {
         North = (int) gpxLine.Coordinates.Max(c => c.Y),
         East = (int) gpxLine.Coordinates.Max(c => c.X)
     });
     var southWest = _coordinatesConverter.ItmToWgs84(new NorthEast
     {
         North = (int) gpxLine.Coordinates.Min(c => c.Y),
         East = (int) gpxLine.Coordinates.Min(c => c.X)
     });
     var highways = await _elasticSearchGateway.GetHighways(new LatLng {lat = northEast.Latitude, lng = northEast.Longitude}, new LatLng {lat = southWest.Latitude, lng = southWest.Longitude});
     return highways.Select(highway => ToItmLineString(highway.Geometry.Coordinates)).ToList();
 }
        public void SplitSelfLoops_GpxCamelShape_ShouldSplitItAndRemoveLowerPart()
        {
            var gpxLine = new LineString(new[]
            {
                new Coordinate(0, 0),
                new Coordinate(100, 0),
                new Coordinate(175, 0),
                new Coordinate(400, 0),
                new Coordinate(400, 200),
                new Coordinate(500, 200),
                new Coordinate(500, 0),
                new Coordinate(800, 0),
                new Coordinate(1000, 0),
                new Coordinate(1000, 200),
                new Coordinate(1100, 200),
                new Coordinate(1100, -1),
                new Coordinate(1050, -1),
                new Coordinate(900, -1),
                new Coordinate(700, -1),
                new Coordinate(450, -1),
                new Coordinate(300, -1),
                new Coordinate(100, -1),
            });

            var results = _service.SplitSelfLoops(gpxLine, 30);

            Assert.AreEqual(2, results.Count);
            Assert.AreEqual(9, results.First().Count);
            Assert.AreEqual(9, results.Last().Count);
        }
        public void SplitSelfLoops_GpxQuestionMarkShape_ShouldSplitItAndRemoveDuplication()
        {
            var gpxLine = new LineString(new[]
            {
                new Coordinate(0, 0),
                new Coordinate(200, 0),
                new Coordinate(400, 0),
                new Coordinate(400, 200),
                new Coordinate(600, 200),
                new Coordinate(600, 0),
                new Coordinate(400, -1),
                new Coordinate(400, -200),
                new Coordinate(600, -200),
                new Coordinate(601, 0),
                new Coordinate(601, 100),
                new Coordinate(601, 200),
                new Coordinate(601, 400),
                new Coordinate(601, 600)
            });

            var results = _service.SplitSelfLoops(gpxLine, 30);

            Assert.AreEqual(2, results.Count);
            Assert.AreEqual(6, results.First().Count);
            Assert.AreEqual(8, results.Last().Count);
        }
예제 #35
0
        private static LineString CreateWKBLineString(BinaryReader reader, WkbByteOrder byteOrder)
        {
            //l.Vertices.AddRange(ReadCoordinates(reader, byteOrder));
            Point[] arrPoint = ReadCoordinates(reader, byteOrder);
            var arrCoordinate = new Coordinate[arrPoint.Length];

            for (int i = 0; i < arrPoint.Length; i++)
                arrCoordinate[i] = new Coordinate(arrPoint[i].X, arrPoint[i].Y);

            LineString l = new LineString(arrCoordinate);
            return l;
        }
예제 #36
0
 private async Task<LineString> FindALineToMergeTo(List<LineString> linesToMerge, List<LineString> mergedLines, LineString lineToMerge)
 {
     foreach (var mergedLine in mergedLines)
     {
         var linesToTestAgainst = linesToMerge.Concat(mergedLines).Except(new[] { mergedLine, lineToMerge }).ToList();
         if (await CanBeMerged(mergedLine.Coordinates.Last(), lineToMerge.Coordinates.First(), linesToTestAgainst) ||
             await CanBeMerged(mergedLine.Coordinates.First(), lineToMerge.Coordinates.Last(), linesToTestAgainst) ||
             await CanBeMerged(mergedLine.Coordinates.First(), lineToMerge.Coordinates.First(), linesToTestAgainst) ||
             await CanBeMerged(mergedLine.Coordinates.Last(), lineToMerge.Coordinates.Last(), linesToTestAgainst))
         {
             return mergedLine;
         }
     }
     return null;
 }
        public void TestSTDistance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var point = new NTSGS.Point(new NTSGS.Coordinate(-72.1235, 42.3521))
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeometryEntity(1, point));

                var lineString = new NTSGS.LineString(new[] { new NTSGS.Coordinate(-72.1260, 42.45), new NTSGS.Coordinate(-72.123, 42.1546) })
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeometryEntity(2, lineString));

                // Geometry example - units in planar degrees 4326 is WGS 84 long lat, units are degrees.
                var distances4326 = db.TestGeometries
                                    .Select(g => g.Geometry.STDistance(point))
                                    .ToList();

                Assert.AreEqual(2, distances4326.Count);
                Assert.AreEqual(0.0, distances4326[0]);
                Assert.AreEqual(0.00150567726382822, distances4326[1].Value, 1.0E-9);

                // Geometry example - units in meters (SRID:3857, proportional to pixels on popular web maps).
                var distances3857 = db.TestGeometries
                                    .Select(g => g.Geometry.STTransform(SRID3857).STDistance(point.STTransform(SRID3857)))
                                    .ToList();

                Assert.AreEqual(2, distances3857.Count);
                Assert.AreEqual(0.0, distances3857[0]);
                Assert.AreEqual(167.441410065196, distances3857[1].Value, 1.0E-9);

                var nullDistance = db.TestGeometries
                                   .Where(g => g.Id == 1)
                                   .Select(g => g.Geometry.STDistance(null))
                                   .Single();
                Assert.IsNull(nullDistance);

                Assert.AreEqual(
                    0.00150567726382282,
                    db.Select(() => MeasurementFunctions.STDistance(
                                  "SRID=4326;POINT(-72.1235 42.3521)",
                                  "SRID=4326;LINESTRING(-72.1260 42.45, -72.123 42.1546)")).Value,
                    1.0E-12);

                Assert.IsNull(db.Select(() => MeasurementFunctions.STDistance((NTSG)null, (NTSG)null)));

                // geography
                var pointGeography = new NTSGS.Point(-72.1235, 42.3521)
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeographyEntity(1, pointGeography));

                var lineGeography = new NTSGS.LineString(new[] { new NTSGS.Coordinate(-72.1260, 42.45), new NTSGS.Coordinate(-72.123, 42.1546) })
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeographyEntity(2, lineGeography));

                var distance1 = db.TestGeographies
                                .Where(g => g.Id == 1)
                                .Select(g => g.Geography.STDistance(db.TestGeographies.Where(g0 => g0.Id == 2).Single().Geography))
                                .Single();

                Assert.AreEqual(123.802077, distance1.Value, 1.0E-6);

                var distance2 = db.TestGeographies
                                .Where(g => g.Id == 1)
                                .Select(g => g.Geography.STDistance(db.TestGeographies.Where(g0 => g0.Id == 2).Single().Geography, false))
                                .Single();

                Assert.AreEqual(123.475737, distance2.Value, 1.0E-6);
            }
        }
 private static bool IsSameStructureLineString(LineString g1, LineString g2)
 {
     // could check for both empty or nonempty here
     return true;
 }
예제 #39
0
        //static void Comapct(ref List<LineString> lsList)
        //{
        //    int n = lsList.Count();
        //    bool found = true;

        //    while (found)
        //    {
        //        found = false;

        //        for (int i = 0; i < n - 2; i++)
        //        {
        //            for (int j = i + 1; j < n - 1; j++)
        //            {
        //                LineString l = UnionLineStrings(lsList[i], lsList[j]);

        //                if (l != null)
        //                {
        //                    lsList[i] = l;
        //                    lsList.RemoveAt(j);
        //                    n--;
        //                    found = true;
        //                }
        //            }
        //        }

        //    }

        //}

        private static LineString UnionLineStrings(LineString ls1, LineString ls2)
        {
            LineString l = null;

            if (ls1.Coordinates.Count() < 0 | ls2.Coordinates.Count() < 0)
            {
                return null;
            }

            Coordinate[] c1 = null;
            Coordinate[] c2 = null;

            if (ls1.StartPoint.Distance(ls2.StartPoint) < 0.001)
            {
                c1 = Reverse(ls1.Coordinates);
                //c.Add(ls2.Coordinates, false);
                c2 = ls2.Coordinates;
            }

            if (ls1.EndPoint.Distance(ls2.EndPoint) < 0.001)
            {
                c1 = ls1.Coordinates;
                //c.Add((CoordinateList)ls2.Coordinates.Reverse(), false);
                c2 = Reverse(ls2.Coordinates);
            }

            if (ls1.StartPoint.Distance(ls2.EndPoint) < 0.001)
            {
                c1 = ls2.Coordinates;
                //c.Add((CoordinateList)ls1.Coordinates, false);
                c2 = ls1.Coordinates;
            }

            if (ls1.EndPoint.Distance(ls2.StartPoint) < 0.001)
            {
                c1 = ls1.Coordinates;
                //c.Add((CoordinateList)ls2.Coordinates, false);
                c2 = ls2.Coordinates;
            }

            if (c1 != null && c2 != null)
            {
                Coordinate[] xx = c1;
                xx.Concat(c2);
                l = new LineString(xx);
            }
            return l;
        }
예제 #40
0
        /// <summary>
        /// This method produces instances of type <see cref="LineString"/>.
        /// </summary>
        /// <returns>The created geometries</returns>
        internal override Collection<SimpleGisShape> createGeometries()
        {
            IPathNode lineStringNode = new PathNode(_GMLNS, "LineString", (NameTable)_xmlReader.NameTable);
            string[] labelValue = new string[1];

            try
            {
                ParseBoundingBox();

                // Reading the entire feature's node makes it possible to collect label values that may appear before or after the geometry property
                while ((_featureReader = GetSubReaderOf(_xmlReader, null, _featureNode)) != null)
                {
                    while ((_geomReader = GetSubReaderOf(_featureReader, null, _propertyNode)) != null)
                    {
                        bool isSelected;
                        int uid;
                        List<string> ll = ParseProperties(_geomReader, out isSelected, out uid);

                        _geomReader = GetSubReaderOf(_featureReader, labelValue, lineStringNode, _CoordinatesNode);

                        LineString l = new LineString(ParseCoordinates(_geomReader));
                        var shp = new SimpleGisShape(l);
                        shp.IsSelected = isSelected;
                        shp.UID = uid;
                        _shapes.Add(shp);
                        FillShapeFields(shp, ll);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return _shapes;
        }