Beispiel #1
0
 public void Multils()
 {
     var rnd = new Random();
     var ls = new LineString[40];
     var lscheck = new GeoAPI.Geometries.ILineString[40];
     var gf = new NetTopologySuite.Geometries.GeometryFactory();
     for (var ii = 0; ii < 40; ii++)
     {
         var coord = new Coordinate[36];
         var coordcheck = new GeoAPI.Geometries.Coordinate[36];
         for (var i = 0; i < 36; i++)
         {
             coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
             var x = coord[i].X;
             var y = coord[i].Y;
             var c = new GeoAPI.Geometries.Coordinate(x, y);
             coordcheck[i] = c;
         }
         ls[ii] = new LineString(coord);
         lscheck[ii] = gf.CreateLineString(coordcheck);
     }
     var mls = new MultiLineString(ls);
     var mlscheck = gf.CreateMultiLineString(lscheck);
     for (var ii = 0; ii < mls.Coordinates.Count; ii++)
     {
         Assert.AreEqual(mls.Coordinates[ii].X, mlscheck.Coordinates[ii].X);
         Assert.AreEqual(mls.Coordinates[ii].Y, mlscheck.Coordinates[ii].Y);
     }
     Assert.AreEqual(mls.NumGeometries, mlscheck.NumGeometries);
 }
        public void TestLengthIndexedLine()
        {
            var gf = new NetTopologySuite.Geometries.GeometryFactory();
            var l = gf.CreateLineString(
                new []
                    {   new GeoAPI.Geometries.Coordinate(0, 0), 
                        new GeoAPI.Geometries.Coordinate(300, 100),});

            System.Console.WriteLine(SplitLineString(l, 20d));
        }
 public void LineLength()
 {
     var coords = new Coordinate[36];
     var rnd = new Random();
     var coordscheck = new GeoAPI.Geometries.Coordinate[36];
     for (var i = 0; i < 36; i++)
     {
         coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
         var x = coords[i].X;
         var y = coords[i].Y;
         var c = new GeoAPI.Geometries.Coordinate(x, y);
         coordscheck[i] = c;
     }
     var gf = new NetTopologySuite.Geometries.GeometryFactory();
     var lscheck = gf.CreateLineString(coordscheck);
     var ls = new LineString(coords);
     var length = ls.Length;
     var lengthcheck = lscheck.Length;
     Assert.AreEqual(length, lengthcheck);
 }
Beispiel #4
0
        public void LineStartPoint()
        {
            var coords      = new Coordinate[36];
            var rnd         = new Random();
            var coordscheck = new GeoAPI.Geometries.Coordinate[36];

            for (var i = 0; i < 36; i++)
            {
                coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
                var x = coords[i].X;
                var y = coords[i].Y;
                var c = new GeoAPI.Geometries.Coordinate(x, y);
                coordscheck[i] = c;
            }
            var gf      = new NetTopologySuite.Geometries.GeometryFactory();
            var lscheck = gf.CreateLineString(coordscheck);
            var ls      = new LineString(coords);

            AssertExt.AreEqual15(ls.StartPoint.X, lscheck.StartPoint.X);
            AssertExt.AreEqual15(ls.StartPoint.Y, lscheck.StartPoint.Y);
        }
Beispiel #5
0
        public void LineStringEnvelopeHeightWidth()
        {
            var coords      = new Coordinate[36];
            var rnd         = new Random();
            var coordscheck = new GeoAPI.Geometries.Coordinate[36];

            for (var i = 0; i < 36; i++)
            {
                coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
                var x = coords[i].X;
                var y = coords[i].Y;
                var c = new GeoAPI.Geometries.Coordinate(x, y);
                coordscheck[i] = c;
            }
            var gf = new NetTopologySuite.Geometries.GeometryFactory();

            GeoAPI.Geometries.ILineString lscheck = gf.CreateLineString(coordscheck);
            var ls = new LineString(coords);

            AssertExt.AreEqual15(ls.Envelope.Width, lscheck.EnvelopeInternal.Width);
            AssertExt.AreEqual15(ls.Envelope.Height, lscheck.EnvelopeInternal.Height);
        }
Beispiel #6
0
        public void LineLength()
        {
            var coords      = new Coordinate[36];
            var rnd         = new Random();
            var coordscheck = new GeoAPI.Geometries.Coordinate[36];

            for (var i = 0; i < 36; i++)
            {
                coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
                var x = coords[i].X;
                var y = coords[i].Y;
                var c = new GeoAPI.Geometries.Coordinate(x, y);
                coordscheck[i] = c;
            }
            var gf          = new NetTopologySuite.Geometries.GeometryFactory();
            var lscheck     = gf.CreateLineString(coordscheck);
            var ls          = new LineString(coords);
            var length      = ls.Length;
            var lengthcheck = lscheck.Length;

            Assert.AreEqual(length, lengthcheck);
        }
 public void LineEndPoint()
 {
     var coords = new Coordinate[36];
     var rnd = new Random();
     var coordscheck = new GeoAPI.Geometries.Coordinate[36];
     for (var i = 0; i < 36; i++)
     {
         coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
         var x = coords[i].X;
         var y = coords[i].Y;
         var c = new GeoAPI.Geometries.Coordinate(x, y);
         coordscheck[i] = c;
     }
     var gf = new NetTopologySuite.Geometries.GeometryFactory();
     var lscheck = gf.CreateLineString(coordscheck);
     var ls = new LineString(coords);
     AssertExt.AreEqual15(ls.EndPoint.X, lscheck.EndPoint.X);
     AssertExt.AreEqual15(ls.EndPoint.Y, lscheck.EndPoint.Y);
 }
        public void LineStringEnvelopeHeightWidth()
        {
            var coords = new Coordinate[36];
            var rnd = new Random();
            var coordscheck = new GeoAPI.Geometries.Coordinate[36];
            for (var i = 0; i < 36; i++)
            {
                coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
                var x = coords[i].X;
                var y = coords[i].Y;
                var c = new GeoAPI.Geometries.Coordinate(x, y);
                coordscheck[i] = c;
            }
            var gf = new NetTopologySuite.Geometries.GeometryFactory();
            GeoAPI.Geometries.ILineString lscheck = gf.CreateLineString(coordscheck);
            var ls = new LineString(coords);
            AssertExt.AreEqual15(ls.Envelope.Width, lscheck.EnvelopeInternal.Width);
            AssertExt.AreEqual15(ls.Envelope.Height, lscheck.EnvelopeInternal.Height);

        }
Beispiel #9
0
 public void EnveloptMls()
 {
     var rnd = new Random();
     var ls = new LineString[40];
     var lscheck = new GeoAPI.Geometries.ILineString[40];
     var gf = new NetTopologySuite.Geometries.GeometryFactory();
     for (var ii = 0; ii < 40; ii++)
     {
         var coord = new Coordinate[36];
         var coordcheck = new GeoAPI.Geometries.Coordinate[36];
         for (var i = 0; i < 36; i++)
         {
             coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
             var x = coord[i].X;
             var y = coord[i].Y;
             var c = new GeoAPI.Geometries.Coordinate(x, y);
             coordcheck[i] = c;
         }
         ls[ii] = new LineString(coord);
         lscheck[ii] = gf.CreateLineString(coordcheck);
     }
     var mls = new MultiLineString(ls);
     var mlscheck = gf.CreateMultiLineString(lscheck);
     Assert.AreEqual(mls.Envelope.Width, mlscheck.EnvelopeInternal.Width);
     Assert.AreEqual(mls.Envelope.Height, mlscheck.EnvelopeInternal.Height);
 }
 public static ILineString CreateLineString(Coordinate[] coords)
 {
     return(geomFactory.CreateLineString(coords));
 }
        /// <summary>
        /// Converts the given OsmSharp feature into an NTS feature.
        /// </summary>
        /// <param name="feature"></param>
        /// <returns></returns>
        public static Feature Convert(OsmSharp.Geo.Features.Feature feature)
        {
            if (feature == null) { throw new ArgumentNullException("feature"); }

            var geometryFactory = new NetTopologySuite.Geometries.GeometryFactory();
            if(feature.Geometry is OsmSharp.Geo.Geometries.Polygon)
            { // a polygon.
                var polygon = (feature.Geometry as OsmSharp.Geo.Geometries.Polygon);
                var holes = polygon.Holes.Select((hole) => {
                    return (ILinearRing)geometryFactory.CreateLinearRing(hole.Coordinates.Select((coordinate) => {
                        return new Coordinate(coordinate.Longitude, coordinate.Latitude);
                    }).ToArray());
                }).ToArray();
                var shell = geometryFactory.CreateLinearRing(polygon.Ring.Coordinates.Select((coordinate) => {
                    return new Coordinate(coordinate.Longitude, coordinate.Latitude);
                }).ToArray());
                return new Feature(geometryFactory.CreatePolygon(shell, holes),
                    OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes));
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.LineairRing)
            { // a lineair ring.
                var lineairRing = (feature.Geometry as OsmSharp.Geo.Geometries.LineairRing);
                var coordinates = lineairRing.Coordinates.Select((coordinate) => {
                    return new Coordinate(coordinate.Longitude, coordinate.Latitude);
                });
                return new Feature(geometryFactory.CreateLinearRing(coordinates.ToArray()),
                    OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes));
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.LineString)
            { // a line string.
                var lineString = (feature.Geometry as OsmSharp.Geo.Geometries.LineString);
                var coordinates = lineString.Coordinates.Select((coordinate) =>
                {
                    return new Coordinate(coordinate.Longitude, coordinate.Latitude);
                });
                return new Feature(geometryFactory.CreateLineString(coordinates.ToArray()),
                    OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes));
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.Point)
            { // a point.
                var point = (feature.Geometry as OsmSharp.Geo.Geometries.Point);
                return new Feature(geometryFactory.CreatePoint(new Coordinate(point.Coordinate.Longitude, point.Coordinate.Latitude)),
                    OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes));
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.MultiLineString)
            { // a multi line string.
                throw new NotSupportedException("A MultiLineString is not supported.");
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.MultiPoint)
            { // a multi point.
                throw new NotSupportedException("A MultiPoint is not supported.");
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.MultiPolygon)
            { // a multi polygon.
                throw new NotSupportedException("A MultiPolygon is not supported.");
            }
            throw new ArgumentOutOfRangeException("Geometry not recognized: {0}", feature.ToString());
        }