public static NetTopologySuite.Geometries.MultiLineString ToGeometryMultiLineString(PolyLineM polyLineM)
        {
            if (polyLineM == null)
            {
                throw new ArgumentNullException(nameof(polyLineM));
            }

            var coordinates = Array.ConvertAll(polyLineM.Points, point => new NetTopologySuite.Geometries.Coordinate(point.X, point.Y));

            if (polyLineM.Measures != null)
            {
                for (var measureIndex = 0; measureIndex < polyLineM.Measures.Length; measureIndex++)
                {
                    coordinates[measureIndex] = new NetTopologySuite.Geometries.CoordinateM(coordinates[measureIndex].X, coordinates[measureIndex].Y, polyLineM.Measures[measureIndex]);
                }
            }

            var lines             = new NetTopologySuite.Geometries.LineString[polyLineM.NumberOfParts];
            var toCoordinateIndex = coordinates.Length;

            for (var partIndex = polyLineM.NumberOfParts - 1; partIndex >= 0; partIndex--)
            {
                var fromCoordinateIndex = polyLineM.Parts[partIndex];

                lines[partIndex] = new NetTopologySuite.Geometries.LineString(
                    GeometryConfiguration.GeometryFactory.CoordinateSequenceFactory.Create(
                        new ArraySegment <NetTopologySuite.Geometries.Coordinate>(
                            coordinates,
                            fromCoordinateIndex,
                            toCoordinateIndex - fromCoordinateIndex).ToArray()
                        ),
                    GeometryConfiguration.GeometryFactory);

                toCoordinateIndex = fromCoordinateIndex;
            }

            return(new NetTopologySuite.Geometries.MultiLineString(lines));
        }
Beispiel #2
0
        private static IEnumerable <RoadInfo> ReadRoads(ISpatialOperation spatial)
        {
            var json = File.ReadAllText(Path.Combine(s_dataDir, @"osm-kunming-roads-network.geojson"));
            var fc   = JsonConvert.DeserializeObject <FeatureCollection>(json);

            foreach (var feature in fc.Features)
            {
                var geom       = feature.Geometry as LineString;
                var lineCoords = geom.Coordinates.Select(c => new GeoAPI.Geometries.Coordinate(c.Longitude, c.Latitude)).ToArray();
                var lineGeom   = new NetTopologySuite.Geometries.LineString(lineCoords);
                yield return(new RoadInfo(
                                 Convert.ToInt64(feature.Properties["gid"]),
                                 Convert.ToInt64(feature.Properties["source"]),
                                 Convert.ToInt64(feature.Properties["target"]),
                                 (double)feature.Properties["reverse"] >= 0D ? false : true,
                                 (short)0,
                                 Convert.ToSingle(feature.Properties["priority"]),
                                 120f,
                                 120f,
                                 Convert.ToSingle(spatial.Length(lineGeom)),
                                 lineGeom));
            }
        }
Beispiel #3
0
        private static ILineString ReadLineString(JsonTextReader jreader)
        {
            if (jreader == null)
            {
                throw new ArgumentNullException("reader", "A valid JSON reader object is required.");
            }

            ILineString line = null;

            if (jreader.TokenClass == JsonTokenClass.Array)
            {
                jreader.ReadToken(JsonTokenClass.Array);
                List <Coordinate> list = new List <Coordinate>();
                while (jreader.TokenClass == JsonTokenClass.Array)
                {
                    Coordinate item = new Coordinate();
                    Read(ref item, jreader);
                    list.Add(item);
                }
                jreader.ReadToken(JsonTokenClass.EndArray);
                line = new NetTopologySuite.Geometries.LineString(list.ToArray());
            }
            return(line);
        }
Beispiel #4
0
        public static double ProjectedDistanceBetweenPlaces(Wgs84Coordinates a, Wgs84Coordinates b)
        {
            Wgs84Coordinates[] mycoordinates = new Wgs84Coordinates[] { a, b };

            DotSpatial.Projections.ProjectionInfo projFrom = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            DotSpatial.Projections.ProjectionInfo projTo   = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.CylindricalEqualAreaworld;
            projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.EquidistantConicworld;
            // projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.EquidistantCylindricalworld;

            // projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.WebMercator;
            projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.WorldSpheroid.Mercatorsphere;
            projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.WorldSpheroid.EckertVsphere; // Exception
            projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.WorldSpheroid.MillerCylindricalsphere;
            projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.WorldSpheroid.EquidistantCylindricalsphere;
            // projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.WorldSpheroid.EquidistantConicsphere;
            projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.SpheroidBased.Lambert2;
            // projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.SpheroidBased.Lambert2Wide;
            // projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.WorldSpheroid.EckertIVsphere;
            // projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.Europe.EuropeEquidistantConic;

            double[] latLonPoints = new double[mycoordinates.Length * 2];
            double[] z            = new double[mycoordinates.Length];

            // dotspatial takes the x,y in a single array, and z in a separate array.  I'm sure there's a
            // reason for this, but I don't know what it is.
            for (int i = 0; i < mycoordinates.Length; i++)
            {
                latLonPoints[i * 2]     = (double)mycoordinates[i].Longitude;
                latLonPoints[i * 2 + 1] = (double)mycoordinates[i].Latitude;
                z[i] = 0;
            } // Next i

            // prepare for ReprojectPoints (it's mutate array)
            DotSpatial.Projections.Reproject.ReprojectPoints(
                latLonPoints, z, projFrom, projTo
                , 0, latLonPoints.Length / 2
                );

            // assemblying new points array to create polygon
            GeoAPI.Geometries.Coordinate[] polyPoints = new GeoAPI.Geometries.Coordinate[latLonPoints.Length / 2];

            for (int i = 0; i < latLonPoints.Length / 2; ++i)
            {
                polyPoints[i] = new GeoAPI.Geometries.Coordinate(latLonPoints[i * 2], latLonPoints[i * 2 + 1]);
            } // Next i

            // Assembling linear ring to create polygon
            // NetTopologySuite.Geometries.LinearRing lr = new NetTopologySuite.Geometries.LinearRing(polyPoints);

            var line = new NetTopologySuite.Geometries.LineString(polyPoints);

            // var line = new NetTopologySuite.Geometries.LineSegment(polyPoints[0], polyPoints[1]);
            line.SRID = 4326;


            GeoAPI.Geometries.Coordinate[] unprojPoints = new GeoAPI.Geometries.Coordinate[]
            {
                new GeoAPI.Geometries.Coordinate((double)a.Latitude, (double)a.Longitude, 0),
                new GeoAPI.Geometries.Coordinate((double)b.Latitude, (double)b.Longitude, 0)
            };
            var unprojline = new NetTopologySuite.Geometries.LineString(unprojPoints);

            unprojline.SRID = 4326;

            System.Console.WriteLine(unprojline.Length);

            double dist = polyPoints[0].Distance(polyPoints[1]);

            System.Console.WriteLine(dist);

            // SELECT geography::Point(47.552063, 9.226081, 4326).STDistance(geography::Point(47.374487, 9.556946, 4326))
            // 31813.1626618977

            return(line.Length);
        }
Beispiel #5
0
        public static (Feature pand, double distance) GetNearestPand(List <Feature> panden, NetTopologySuite.Geometries.Point loc1, NetTopologySuite.Geometries.LineString line, double MinimumDistance)
        {
            Feature nearestPand     = null;
            double  distanceNearest = Double.MaxValue;

            foreach (var pand in panden)
            {
                var geom       = pand.Geometry;
                var pandGeom   = GeometryConverter.GetGeoApiGeometry(geom);
                var intersects = pandGeom.Intersects(line);

                if (intersects)
                {
                    var dist = loc1.Distance(pandGeom);

                    if (dist < distanceNearest && dist > MinimumDistance / 111000)
                    {
                        distanceNearest = dist;
                        nearestPand     = pand;
                    }
                }
            }
            return(nearestPand, distanceNearest);
        }
 public DrawingLineString(NetTopologySuite.Geometries.LineString lineString)
 {
     Update(lineString.Coordinates.Select(c => c.ToPoint()), lineString.IsClosed);
 }