コード例 #1
0
        private GeometryCollection CreateCollection2()
        {
            //create a new geometries array
            Geometry[] geom = new Geometry[10];

            Coordinate  coordinate = new Coordinate();
            Coordinates coords     = new Coordinates();

            GeometryFactory gf         = new GeometryFactory(_precMod, _sRID);
            LineString      lineString = gf.CreateLineString(coords);

            for (int c = 0; c < 10; c++)
            {
                for (int i = c; i < c + 10; i++)
                {
                    //if this isn't here the coordinates for all the points are reset every time the coordinate is reset
                    coordinate = new Coordinate();
                    //make the x coordinate equal to the iterator
                    coordinate.X = (double)i;
                    //make the y coordinate equal to the iterator plus 10
                    coordinate.Y = (double)i + 10;
                    coords.Add(coordinate);
                }
                lineString = gf.CreateLineString(coords);
                geom[c]    = lineString;
            }
            //put the geometries into a geometry collection
            GeometryCollection geoColl = gf.CreateGeometryCollection(geom);

            return(geoColl);
        }
コード例 #2
0
ファイル: GpxProlongerExecutor.cs プロジェクト: HarelM/Site
        private void HandleTwoLinesCase(GpxProlongerExecutorInput input, SegmentWithLines segment, List <LineString> linesToProlong)
        {
            var bothLinesAreInList = linesToProlong.Contains(segment.Start.Line) && linesToProlong.Contains(segment.End.Line);

            if (bothLinesAreInList &&
                segment.Start.Line.Coordinates.Last().Distance(segment.Start.Coordinate) < input.MinimalDistance &&
                segment.End.Line.Coordinates.First().Distance(segment.End.Coordinate) < input.MinimalDistance)
            {
                linesToProlong.Remove(segment.Start.Line);
                linesToProlong.Remove(segment.End.Line);
                linesToProlong.Add(_geometryFactory.CreateLineString(
                                       segment.Start.Line.Coordinates
                                       .Concat(segment.OriginalCoordinates)
                                       .Concat(segment.End.Line.Coordinates)
                                       .Distinct()
                                       .ToArray()) as LineString);
            }
            else if (!AddSegmentToLine(segment.Start.Line, segment, linesToProlong, input.MinimalDistance))
            {
                if (!AddSegmentToLine(segment.End.Line, segment, linesToProlong, input.MinimalDistance))
                {
                    linesToProlong.Add(CreateLineString(segment.StartProjected, segment.OriginalCoordinates, segment.EndProjected));
                }
            }
        }
コード例 #3
0
ファイル: OsmLineAdderService.cs プロジェクト: HarelM/Site
        /// <summary>
        /// This adds an intersecting node of the new highway if it crosses an existing highway
        /// </summary>
        /// <param name="previousCoordinate"></param>
        /// <param name="coordinate"></param>
        /// <param name="newWayNodes"></param>
        /// <param name="itmHighways"></param>
        /// <param name="highways"></param>
        private void AddIntersectingNodes(Coordinate previousCoordinate, Coordinate coordinate, List <Node> newWayNodes,
                                          List <LineString> itmHighways, List <Feature> highways)
        {
            var previousItmPoint = GetItmCoordinate(previousCoordinate);
            var lineSegment      = _geometryFactory.CreateLineString(new [] { previousItmPoint.Coordinate, GetItmCoordinate(coordinate).Coordinate });
            var closeItmLines    = itmHighways.Where(hw => hw.Distance(lineSegment) <= _options.MaxDistanceToExisitngLineForMerge &&
                                                     hw.Distance(previousItmPoint) > _options.MaxDistanceToExisitngLineForMerge);

            foreach (var closeItmLine in closeItmLines)
            {
                var closestPointInExistingLine = closeItmLine.Coordinates.Select(c => new Point(c)).OrderBy(p => p.Distance(lineSegment)).First();
                if (closestPointInExistingLine.Distance(lineSegment) > _options.MaxDistanceToExisitngLineForMerge)
                {
                    continue;
                }
                var indexInLine    = closeItmLine.Coordinates.ToList().IndexOf(closestPointInExistingLine.Coordinate);
                var closestHighway = highways.First(x => x.GetOsmId() == closeItmLine.GetOsmId());
                var closestNode    = CreateNodeFromExistingHighway(closestHighway, indexInLine);
                if (!CanAddNewNode(newWayNodes, closestNode.Id.Value))
                {
                    continue;
                }
                newWayNodes.Add(closestNode);
            }
        }
コード例 #4
0
        public void test_Geometry()
        {
            LineString[] linestrings = new LineString[2];
            Coordinates  coords1     = new Coordinates();
            Coordinate   coord       = new Coordinate(5, 3);

            coords1.Add(coord);
            coord = new Coordinate(4, 5);
            coords1.Add(coord);
            coord = new Coordinate(3, 4);
            coords1.Add(coord);

            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            LineString      ls = gf.CreateLineString(coords1);

            linestrings[0] = ls;

            Coordinates coords2 = new Coordinates();

            coord = new Coordinate(2, 7);
            coords2.Add(coord);
            coord = new Coordinate(9, 2);
            coords2.Add(coord);
            coord = new Coordinate(7, 9);
            coords2.Add(coord);

            ls             = gf.CreateLineString(coords2);
            linestrings[1] = ls;

            MultiLineString mls = gf.CreateMultiLineString(linestrings);

            Assertion.AssertEquals("Geometry-1: ", "LineString:(5, 3, NaN),(4, 5, NaN),(3, 4, NaN)", mls.GetGeometryN(0).ToString());
            Assertion.AssertEquals("Geometry-2: ", "LineString:(2, 7, NaN),(9, 2, NaN),(7, 9, NaN)", mls.GetGeometryN(1).ToString());
        }
コード例 #5
0
        public void test_ToString()
        {
            Coordinates coords = new Coordinates();
            Coordinate  coord  = new Coordinate(1.0, 2.0);

            coords.Add(coord);
            coord = new Coordinate(3.0, 4.0);
            coords.Add(coord);

            GeometryFactory gf  = new GeometryFactory(_precMod, _sRID);
            LineString      ls1 = gf.CreateLineString(coords);

            Assertion.AssertEquals("ToString-1: ", "LineString:(1, 2, NaN),(3, 4, NaN)", ls1.ToString());

            coord = new Coordinate(2.4, 4.9);
            coords.Add(coord);
            LineString ls2 = gf.CreateLineString(coords);

            Assertion.AssertEquals("ToString-2: ", "LineString:(1, 2, NaN),(3, 4, NaN),(2.4, 4.9, NaN)", ls2.ToString());

            coord = new Coordinate(1.0, 1.0);
            coords.Add(coord);
            LineString ls3 = gf.CreateLineString(coords);

            Assertion.AssertEquals("ToString-3: ", "LineString:(1, 2, NaN),(3, 4, NaN),(2.4, 4.9, NaN),(1, 1, NaN)", ls3.ToString());
        }
コード例 #6
0
        /**
         * Returns
         * <ul>
         * <li>an empty LineString if input CoordinateSequence has no valid
         * point</li>
         * <li>a Point if input CoordinateSequence has a single valid Point</li>
         * </ul>
         * makeLineStringValid keeps the original dimension of input sequence.
         *
         * @param lineString the LineString to make valid
         * @return a valid LineString or a Point if lineString length equals 0
         */
        private NetTopologySuite.Geometries.Geometry makeLineStringValid(LineString lineString)
        {
            CoordinateSequence sequence = lineString.CoordinateSequence;
            CoordinateSequence sequenceWithoutDuplicates = makeSequenceValid(sequence, false, false);
            GeometryFactory    factory = lineString.Factory;

            if (sequenceWithoutDuplicates.Count == 0)
            {
                // no valid point -> empty LineString
                return(factory.CreateLineString(factory.CoordinateSequenceFactory.Create(0, sequence.Dimension)));
            }
            else if (sequenceWithoutDuplicates.Count == 1)
            {
                // a single valid point -> returns a Point
                if (preserveGeomDim)
                {
                    return(factory.CreateLineString(factory.CoordinateSequenceFactory.Create(0, sequence.Dimension)));
                }
                else
                {
                    return(factory.CreatePoint(sequenceWithoutDuplicates));
                }
            }
            else if (preserveDuplicateCoord)
            {
                return(factory.CreateLineString(makeSequenceValid(sequence, true, false)));
            }
            else
            {
                return(factory.CreateLineString(sequenceWithoutDuplicates));
            }
        }
コード例 #7
0
ファイル: PointLine.cs プロジェクト: carlhuth/GenXSource
        public void TestPointLine1()
        {
            // 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(5.0, 5.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("disjoint", false, point1.Disjoint(linestring));
            Assertion.AssertEquals("contains", false, point1.Contains(linestring));
            Assertion.AssertEquals("within", false, point1.Within(linestring));

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

            Assertion.AssertEquals("touches", true, point1.Touches(linestring));

            // always returns false when a point is involved
            Assertion.AssertEquals("overlaps", false, point1.Overlaps(linestring));
        }
コード例 #8
0
        private MultiLineString CreateMLS()
        {
            Coordinates     coords     = new Coordinates();
            Coordinate      coord      = new Coordinate();
            GeometryFactory gf         = new GeometryFactory(_precMod, _sRID);
            LineString      lineString = gf.CreateLineString(coords);

            LineString[] ls = new LineString[10];
            for (int i = 0; i < 10; i++)
            {
                coords = new Coordinates();
                for (int j = i; j < i + 10; j++)
                {
                    coord   = new Coordinate();
                    coord.X = (double)j;
                    coord.Y = (double)j + 5;
                    coords.Add(coord);
                }
                lineString = gf.CreateLineString(coords);
                ls[i]      = lineString;
            }
            MultiLineString multiLS = gf.CreateMultiLineString(ls);

            return(multiLS);
        }
コード例 #9
0
        private Feature ConvertRelation(CompleteRelation relation)
        {
            if (IsMultipolygon(relation))
            {
                return(ConvertToMultipolygon(relation));
            }

            var nodes = relation.Members.Select(m => m.Member).OfType <Node>().ToList();

            if (nodes.Any())
            {
                var multiPoint = _geometryFactory.CreateMultiPoint(nodes.Select(n => _geometryFactory.CreatePoint(ConvertNode(n))).ToArray());
                return(new Feature(multiPoint, ConvertTags(relation)));
            }

            var geometries = GetGeometriesFromWays(GetAllWays(relation));

            if (!geometries.Any())
            {
                return(null);
            }
            var jointLines = geometries.OfType <LineString>().ToList();

            jointLines.AddRange(geometries.OfType <Polygon>().Select(p => _geometryFactory.CreateLineString(p.ExteriorRing.Coordinates.ToArray()) as LineString));
            var multiLineString = _geometryFactory.CreateMultiLineString(jointLines.ToArray());

            return(new Feature(multiLineString, ConvertTags(relation)));
        }
コード例 #10
0
        /// <inheritdoc/>
        public List <LineString> SplitSelfLoops(LineString gpxLine, double minimalDistanceToClosestPoint)
        {
            var lines           = new List <LineString>();
            var reversedGpxLine = ReverseLine(gpxLine);

            int coordinateIndex = 0;

            while (coordinateIndex < reversedGpxLine.Coordinates.Length)
            {
                var indexOfClosingLine = GetClosingLoopIndex(reversedGpxLine, coordinateIndex, minimalDistanceToClosestPoint);
                if (indexOfClosingLine == -1)
                {
                    coordinateIndex++;
                    continue;
                }
                AddLineString(lines, reversedGpxLine.Coordinates.Take(indexOfClosingLine).ToArray());
                var reminingPoints = reversedGpxLine.Coordinates.Skip(indexOfClosingLine).ToArray();
                reversedGpxLine = reminingPoints.Length > 1 ? _geometryFactory.CreateLineString(reminingPoints) as LineString : _geometryFactory.CreateLineString(new Coordinate[0]) as LineString;
                coordinateIndex = 0;
            }
            AddLineString(lines, reversedGpxLine.Coordinates);

            lines = lines.Select(ReverseLine).ToList();
            lines.Reverse();
            return(lines);
        }
コード例 #11
0
 public void TestQuery()
 {
     var geometries = new List<IGeometry>();
     geometries.Add(_factory.CreateLineString(new Coordinate[]
                                                  {
                                                      new Coordinate(0, 0), new Coordinate(10, 10)
                                                  }));
     geometries.Add(_factory.CreateLineString(new Coordinate[]
                                                  {
                                                      new Coordinate(20, 20), new Coordinate(30, 30)
                                                  }));
     geometries.Add(_factory.CreateLineString(new Coordinate[]
                                                  {
                                                      new Coordinate(20, 20), new Coordinate(30, 30)
                                                  }));
     STRtree t = new STRtree(4);
     foreach (var g in geometries)
     {
         t.Insert(g.EnvelopeInternal, new Object());
     }
     t.Build();
     try
     {
         Assert.AreEqual(1, t.Query(new Envelope(5, 6, 5, 6)).Count);
         Assert.AreEqual(0, t.Query(new Envelope(20, 30, 0, 10)).Count);
         Assert.AreEqual(2, t.Query(new Envelope(25, 26, 25, 26)).Count);
         Assert.AreEqual(3, t.Query(new Envelope(0, 100, 0, 100)).Count);
     }
     catch (Exception x)
     {
         Console.WriteLine(x.Message);
         throw x;
     }
 }
コード例 #12
0
 public static IReadOnlyList <MultiLineStringEntity> CreateMultiLineStringEntities(GeometryFactory factory)
 => new[]
 {
     new MultiLineStringEntity
     {
         Id = 1,
         MultiLineString = factory.CreateMultiLineString(
             new[]
         {
             factory.CreateLineString(
                 new[]
             {
                 new Coordinate(0, 0),
                 new Coordinate(0, 1)
             }),
             factory.CreateLineString(
                 new[]
             {
                 new Coordinate(1, 0),
                 new Coordinate(1, 1)
             })
         })
     },
     new MultiLineStringEntity
     {
         Id = 2,
         MultiLineString = null
     }
 };
コード例 #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="computer"></param>
        private void BuildEdges(ComputeWeightDelegate computer)
        {
            if (strings.Count < 2)
            {
                throw new TopologyException("you must specify two or more geometries to build a graph");
            }

            // Counts the number of edges in the set we pass to this method.
            int numberOfEdgesInLines = 0;

            foreach (var str in strings)
            {
                int edges = str.Coordinates.GetUpperBound(0);
                numberOfEdgesInLines += edges;
            }

            // Double values because we use also reversed edges...
            if (bidirectional)
            {
                numberOfEdgesInLines *= 2;
            }

            consts = new Dictionary <IEdge <Coordinate>, double>(numberOfEdgesInLines);

            foreach (var line in strings)
            {
                // A line has to have at least two dimensions
                int bound = line.Coordinates.GetUpperBound(0);
                if (bound > 0)
                {
                    for (int counter = 0; counter < bound; counter++)
                    {
                        // Prepare a segment
                        var src = line.Coordinates[counter];
                        var dst = line.Coordinates[counter + 1];

                        // Here we calculate the weight of the edge
                        var lineString = factory.CreateLineString(
                            new[] { src, dst, });
                        double weight = computer(lineString);

                        // Add the edge
                        IEdge <Coordinate> localEdge = new Edge <Coordinate>(src, dst);
                        graph.AddEdge(localEdge);
                        consts.Add(localEdge, weight);

                        if (!bidirectional)
                        {
                            continue;
                        }

                        // Add the reversed edge
                        IEdge <Coordinate> localEdgeRev = new Edge <Coordinate>(dst, src);
                        graph.AddEdge(localEdgeRev);
                        consts.Add(localEdgeRev, weight);
                    }
                }
            }
        }
コード例 #14
0
        public void CrossAndIntersectionTest()
        {
            // Arrange
            var gf = new GeometryFactory(new PrecisionModel(100000000));

            var closestCoordinate = new Coordinate(152608, 594957);
            var closestLine       = gf.CreateLineString(new[]
            {
                new Coordinate(152348, 595130),
                new Coordinate(152421, 595061),
                new Coordinate(152455, 595033),
                new Coordinate(152524, 595001),
                new Coordinate(152593, 594973),
                new Coordinate(152622, 594946),
                new Coordinate(152634, 594930),
                new Coordinate(152641, 594921),
                new Coordinate(152649, 594910),
                new Coordinate(152863, 594623),
                new Coordinate(152873, 594607)
            });
            var    indexedLine     = new NetTopologySuite.LinearReferencing.LengthIndexedLine(closestLine);
            double projectedIndex  = indexedLine.Project(closestCoordinate);
            var    coordinateToAdd = indexedLine.ExtractPoint(projectedIndex);

            gf.PrecisionModel.MakePrecise(coordinateToAdd);

            var line = gf.CreateLineString(new[] { new Coordinate(152503, 594904), coordinateToAdd });

            ToImage(0, closestLine, line, GeometryFactory.Default.CreatePoint(coordinateToAdd));

            // act
            var intersectionPt = line.Intersection(closestLine).Coordinate;

            gf.PrecisionModel.MakePrecise(intersectionPt);

            // assert intersection point is equal to coordinate to add
            Assert.AreEqual(coordinateToAdd, intersectionPt);

            // act insertion of coordinate to add
            var lip = new NetTopologySuite.LinearReferencing.LocationIndexOfPoint(closestLine);
            var ll  = lip.IndexOf(coordinateToAdd);

            if (!ll.IsVertex)
            {
                var cl  = (ILineString)closestLine;
                var cls = cl.Factory.CoordinateSequenceFactory.Create(cl.CoordinateSequence.Count + 1, cl.CoordinateSequence.Ordinates);
                CoordinateSequences.Copy(cl.CoordinateSequence, 0, cls, 0, ll.SegmentIndex + 1);
                cls.SetOrdinate(ll.SegmentIndex + 1, Ordinate.X, coordinateToAdd.X);
                cls.SetOrdinate(ll.SegmentIndex + 1, Ordinate.Y, coordinateToAdd.Y);
                CoordinateSequences.Copy(cl.CoordinateSequence, ll.SegmentIndex + 1, cls, ll.SegmentIndex + 2, cl.CoordinateSequence.Count - ll.SegmentIndex - 1);
                closestLine = gf.CreateLineString(cls);
            }

            ToImage(1, closestLine, line, GeometryFactory.Default.CreatePoint(coordinateToAdd));

            Assert.IsTrue(line.Touches(closestLine));
            Assert.IsFalse(line.Crosses(closestLine));
        }
コード例 #15
0
        private void 绘制ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FeatureDataTable fdt = new FeatureDataTable();

            fdt.Columns.Add("FID", typeof(int));
            fdt.Columns.Add("Rotation", typeof(double));

            GeometryFactory geoFactory = new GeometryFactory();

            Coordinate[] lineCoord01 = new Coordinate[] { new Coordinate(0, 0), new Coordinate(10, 10), new Coordinate(20, 20), new Coordinate(0, 0) };
            Coordinate[] lineCoord02 = new Coordinate[] { new Coordinate(10, 20), new Coordinate(10, 30), new Coordinate(10, 48), new Coordinate(0, 0) };
            ILineString  line01      = geoFactory.CreateLineString(lineCoord01);
            ILineString  line02      = geoFactory.CreateLineString(lineCoord02);

            Coordinate[] pCoordinate01 = new Coordinate[] { new Coordinate(0, 0), new Coordinate(10, 10), new Coordinate(20, 20), new Coordinate(0, 0) };
            Coordinate[] pCoordinate02 = new Coordinate[] { new Coordinate(10, 20), new Coordinate(10, 30), new Coordinate(10, 48), new Coordinate(10, 20) };

            IPolygon polygon01 = geoFactory.CreatePolygon(pCoordinate01);
            IPolygon polygon02 = geoFactory.CreatePolygon(pCoordinate02);

            FeatureDataRow fdr = fdt.NewRow();

            fdr["FID"]      = 3;
            fdr["Rotation"] = 180;
            //fdr.Geometry = line01;
            fdr.Geometry = polygon01;
            fdt.Rows.Add(fdr);

            FeatureDataRow fdr02 = fdt.NewRow();

            fdr02["FID"]      = 7;
            fdr02["Rotation"] = 270;
            //fdr02.Geometry = line02;
            fdr02.Geometry = polygon02;
            fdt.Rows.Add(fdr02);

            VectorLayer vlayer = new VectorLayer("1");

            vlayer.Style.Fill          = new SolidBrush(Color.FromArgb(0, 255, 255, 255));
            vlayer.Style.EnableOutline = true;
            vlayer.DataSource          = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt);
            mbox.Map.Layers.Add(vlayer);

            LabelLayer llayer = new LabelLayer("lab");

            llayer.DataSource         = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt);
            llayer.LabelColumn        = "FID";
            llayer.Style.Rotation     = 0;
            llayer.RotationColumn     = "Rotation";
            llayer.Style.IsTextOnPath = false;
            llayer.Style.Font         = new Font("宋体", 25);


            mbox.Map.Layers.Add(llayer);
            mbox.Map.ZoomToExtents();
            mbox.Refresh();
        }
コード例 #16
0
        /// <summary>
        /// Reads an array of <see cref="Geometry"/>s from JSON
        /// </summary>
        /// <param name="reader">The reader</param>
        /// <param name="objectType">The object type</param>
        /// <param name="existingValue">The existing value</param>
        /// <param name="serializer">The serializer</param>
        /// <returns>The geometry array read</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            //reader.Read();
            //if (!(reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "geometries"))
            //    throw new Exception();
            reader.Read();
            if (reader.TokenType != JsonToken.StartArray)
            {
                throw new Exception();
            }

            reader.Read();
            var geoms = new List <Geometry>();

            while (reader.TokenType != JsonToken.EndArray)
            {
                var obj          = (JObject)serializer.Deserialize(reader);
                var geometryType = (GeoJsonObjectType)Enum.Parse(typeof(GeoJsonObjectType), obj.Value <string>("type"), true);

                switch (geometryType)
                {
                case GeoJsonObjectType.Point:
                    geoms.Add(_factory.CreatePoint(ToCoordinate(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.LineString:
                    geoms.Add(_factory.CreateLineString(ToCoordinates(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.Polygon:
                    geoms.Add(CreatePolygon(ToListOfCoordinates(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.MultiPoint:
                    geoms.Add(_factory.CreateMultiPointFromCoords(ToCoordinates(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.MultiLineString:
                    geoms.Add(CreateMultiLineString(ToListOfCoordinates(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.MultiPolygon:
                    geoms.Add(CreateMultiPolygon(ToListOfListOfCoordinates(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.GeometryCollection:
                    throw new NotSupportedException();
                }

                reader.Read();
            }

            return(geoms);
        }
コード例 #17
0
        private LineString ReadLineString()
        {
            ICoordinateList coords = ReadCoordinates();

            if (coords != null)
            {
                return(m_objFactory.CreateLineString(coords));
            }

            return(null);
        }
コード例 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        protected virtual IGeometry TransformLinearRing(ILinearRing geom, IGeometry parent)
        {
            ICoordinateSequence seq = TransformCoordinates(geom.CoordinateSequence, geom);
            int seqSize             = seq.Count;

            // ensure a valid LinearRing
            if (seqSize > 0 && seqSize < 4 && !preserveType)
            {
                return(factory.CreateLineString(seq));
            }
            return(factory.CreateLinearRing(seq));
        }
コード例 #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geom"></param>
        /// <returns></returns>
        protected virtual IGeometry TransformLinearRing(ILinearRing geom)
        {
            IList <Coordinate> seq = TransformCoordinates(geom.Coordinates, geom);
            int seqSize            = seq.Count;

            // ensure a valid LinearRing
            if (seqSize > 0 && seqSize < 4 && !PRESERVE_TYPE)
            {
                return(_factory.CreateLineString(seq));
            }
            return(_factory.CreateLinearRing(seq));
        }
コード例 #20
0
        public void TestWriteLineString()
        {
            Coordinate[] coordinates =
            {
                new CoordinateZ(10, 10, 0),
                new CoordinateZ(20, 20, 0),
                new CoordinateZ(30, 40, 0)
            };
            var lineString = _factory.CreateLineString(coordinates);

            Assert.AreEqual("LINESTRING (10 10, 20 20, 30 40)", _writer.Write(lineString));
        }
コード例 #21
0
        private LineString ToLine(OverlayEdge edge)
        {
            bool isForward = edge.IsForward;
            var  pts       = new CoordinateList();

            pts.Add(edge.Orig, false);
            edge.AddCoordinates(pts);

            var ptsOut = pts.ToCoordinateArray(isForward);
            var line   = _geometryFactory.CreateLineString(ptsOut);

            return(line);
        }
コード例 #22
0
        private LineString RemoveSpikesFromLineString(LineString geom, GeometryFactory factory, bool ring = false)
        {
            var seq = geom.CoordinateSequence;

            if (geom.Length < 3)
            {
                return(factory.CreateLineString(seq));
            }

            //seq = RemoveSpikesFromSequence(geom.CoordinateSequence, factory.CoordinateSequenceFactory);
            return(ring ? factory.CreateLinearRing(seq)
                        : factory.CreateLineString(seq));
        }
コード例 #23
0
        private MultiLineString nonSimpleMLS()
        {
            Coordinates     coords     = new Coordinates();
            Coordinate      coord      = new Coordinate();
            GeometryFactory gf         = new GeometryFactory(_precMod, _sRID);
            LineString      lineString = gf.CreateLineString(coords);

            LineString[] ls = new LineString[1];

            coord = new Coordinate(2, 2);
            coords.Add(coord);
            coord = new Coordinate(3, 3);
            coords.Add(coord);
            coord = new Coordinate(4, 4);
            coords.Add(coord);
            coord = new Coordinate(5, 5);
            coords.Add(coord);
            coord = new Coordinate(6, 6);
            coords.Add(coord);
            coord = new Coordinate(7, 7);
            coords.Add(coord);
            coord = new Coordinate(8, 8);
            coords.Add(coord);
            coord = new Coordinate(9, 7);
            coords.Add(coord);
            coord = new Coordinate(10, 6);
            coords.Add(coord);
            coord = new Coordinate(10, 5);
            coords.Add(coord);
            coord = new Coordinate(9, 4);
            coords.Add(coord);
            coord = new Coordinate(8, 3);
            coords.Add(coord);
            coord = new Coordinate(7, 4);
            coords.Add(coord);
            coord = new Coordinate(7, 5);
            coords.Add(coord);
            coord = new Coordinate(6, 6);
            coords.Add(coord);
            coord = new Coordinate(5, 7);
            coords.Add(coord);
            coord = new Coordinate(4, 8);
            coords.Add(coord);
            coord = new Coordinate(3, 9);
            coords.Add(coord);
            ls[0] = gf.CreateLineString(coords);

            MultiLineString multiLS = gf.CreateMultiLineString(ls);

            return(multiLS);
        }
コード例 #24
0
        public void GeometryUpdaterTest_FailedTooShort()
        {
            IGeometryFactory gf = new GeometryFactory();

            ILineString oldRefGeometry     = gf.CreateLineString(new Coordinate[] { new Coordinate(0.4, 1), new Coordinate(0.6, 1) });
            ILineString newSegmentGeometry = gf.CreateLineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(0.5, 0.5), new Coordinate(1, 0) });

            GeometryTransformer gt     = new GeometryTransformer(oldRefGeometry, newSegmentGeometry);
            var         result         = gt.Transform();
            ILineString newRefGeometry = result.NewRefGeometry;

            Assert.IsNull(newRefGeometry);
            Assert.IsTrue(result.ResultState == GeometryTransformerResultState.FailedWouldBeTooShort);
        }
コード例 #25
0
        public void GeometryUpdaterTest_SuccessEqualGeoms()
        {
            IGeometryFactory gf = new GeometryFactory();

            ILineString oldRefGeometry     = gf.CreateLineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0) });
            ILineString newSegmentGeometry = gf.CreateLineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(2, 0) });

            GeometryTransformer gt     = new GeometryTransformer(oldRefGeometry, newSegmentGeometry);
            var         result         = gt.Transform();
            ILineString newRefGeometry = result.NewRefGeometry;

            Assert.AreEqual(oldRefGeometry, newRefGeometry);
            Assert.IsTrue(result.ResultState == GeometryTransformerResultState.Success);
        }
コード例 #26
0
        private LineString ToItmLineString(IEnumerable <GpxWaypoint> waypoints)
        {
            var coordinates = waypoints.Select(waypoint => _wgs84ItmMathTransform.Transform(waypoint.Longitude, waypoint.Latitude))
                              .Select(c => new Coordinate(Math.Round(c.x, 1), Math.Round(c.y, 1)));
            var nonDuplicates = new List <Coordinate>();

            foreach (var coordinate in coordinates)
            {
                if (nonDuplicates.Count <= 0 || !nonDuplicates.Last().Equals2D(coordinate))
                {
                    nonDuplicates.Add(coordinate);
                }
            }
            return(_geometryFactory.CreateLineString(nonDuplicates.ToArray()));
        }
コード例 #27
0
        private Geometry CreateLine(double extent, int nSegs)
        {
            var pts =
                new Coordinate[]
            {
                new Coordinate(0, 0),
                new Coordinate(0, extent),
                new Coordinate(extent, extent),
                new Coordinate(extent, 0)
            };
            var    outline = geomFact.CreateLineString(pts);
            double inc     = extent / nSegs;

            return(Densifier.Densify(outline, inc));
        }
コード例 #28
0
        public override String ToString()
        {
            var fact = new GeometryFactory();
            var line = fact.CreateLineString(GetCoordinates());

            return(line.ToString());
        }
コード例 #29
0
        private LineString ToLine(Coordinate p0, Coordinate p1,
                                  Coordinate p2)
        {
            GeometryFactory fact = GeometryFactory.GetInstance();

            return(fact.CreateLineString(new Coordinate[] { p0, p1, p2 }));
        }
コード例 #30
0
        public static IPoint GetCentroidForCoordinates(IList <Coordinate> coordinates, bool forcePolygon = false)
        {
            IList <Coordinate> coordinateList = new List <Coordinate>(coordinates);
            var          geometryFactory      = new GeometryFactory();
            var          firstCoordinate      = coordinateList.First();
            var          lastCoordinate       = coordinateList.Last();
            const double tolerance            = 0.0001;

            // Add the first coordinate to the coordinate collection to force a polygon.
            if (forcePolygon)
            {
                coordinateList.Add(firstCoordinate);
                lastCoordinate = coordinateList.Last();
            }

            IPoint centroid;

            if (firstCoordinate.Equals2D(lastCoordinate, tolerance))
            {
                var polygon = geometryFactory.CreatePolygon(coordinateList.ToArray());
                centroid = polygon.Centroid;
            }
            else
            {
                var lineString = geometryFactory.CreateLineString(coordinateList.ToArray());
                centroid = lineString.Centroid;
            }

            return(centroid);
        }