Esempio n. 1
0
        } // End Function SpatialDistanceBetweenPlaces

        // TestTransform.LOLdistance.Test();
        public static void Test()
        {
            var fab = new Wgs84Coordinates(47.552063m, 9.226081m);
            var sg  = new Wgs84Coordinates(47.374487m, 9.556946m);

            double lat1 = (double)fab.Latitude;
            double lon1 = (double)fab.Longitude;
            double lat2 = (double)sg.Latitude;
            double lon2 = (double)sg.Longitude;

            double d   = LOLdistance.DistanceBetweenPlaces(lat1, lon1, lat2, lon2);
            double d3d = LOLdistance.Distance3dBetweenPlaces(lat1, lon1, lat2, lon2);

            double  fastd       = FastDistance.DistanceBetweenPlaces(lat1, lon1, lat2, lon2);
            double  dp          = DistanceAlgorithm.DistanceBetweenPlaces(lat1, lon1, lat2, lon2);
            decimal decDistance = DecimalDistanceAlgorithm.DistanceBetweenPlaces(fab.Latitude, fab.Longitude, sg.Latitude, sg.Longitude);
            double  pd          = LOLdistance.ProjectedDistanceBetweenPlaces(fab, sg);
            double  sd          = SpatialDistanceBetweenPlaces(fab, sg);


            // DECLARE @fab geography;
            // SET @fab = geography::Point(47.552063, 9.226081, 4326)

            // DECLARE @sg geography;
            // SET @sg = geography::Point(47.374487, 9.556946, 4326)

            // SELECT @fab.STDistance(@sg), @sg.STDistance(@fab)-- 31813.1626618977

            System.Console.WriteLine("", d, d3d, fastd, dp, decDistance, pd, sd);
        }
Esempio n. 2
0
        public static double SpatialDistanceBetweenPlaces(Wgs84Coordinates a, Wgs84Coordinates b)
        {
            var fablat = new DotSpatial.Positioning.Latitude((double)a.Latitude);
            var fablng = new DotSpatial.Positioning.Longitude((double)a.Longitude);

            var sglat = new DotSpatial.Positioning.Latitude((double)b.Latitude);
            var sglng = new DotSpatial.Positioning.Longitude((double)b.Longitude);

            var fab = new DotSpatial.Positioning.Position(fablat, fablng);
            var sg  = new DotSpatial.Positioning.Position(sglat, sglng);

            DotSpatial.Positioning.Distance dist = fab.DistanceTo(sg);

            return(dist.ToMeters().Value);
        } // End Function SpatialDistanceBetweenPlaces
Esempio n. 3
0
        // https://stackoverflow.com/questions/46159499/calculate-area-of-polygon-having-wgs-coordinates-using-dotspatial
        // pfff wrong...
        public static void TestComputeArea()
        {
            // this feature can be see visually here http://www.allhx.ca/on/toronto/westmount-park-road/25/
            string feature = "-79.525542519049552,43.691278124243432 -79.525382520578987,43.691281097414787 -79.525228855617627,43.69124858593392 -79.525096151437353,43.691183664769774 -79.52472799258571,43.690927163079735 -79.525379447437814,43.690771996666641 -79.525602330675355,43.691267524226838 -79.525542519049552,43.691278124243432";

            feature = "47.3612503,8.5351944 47.3612252,8.5342631 47.3610145,8.5342755 47.3610212,8.5345227 47.3606405,8.5345451 47.3606350,8.5343411 47.3604067,8.5343545 47.3604120,8.5345623 47.3604308,8.5352457 47.3606508,8.5352328 47.3606413,8.5348784 47.3610383,8.5348551 47.3610477,8.5352063 47.3612503,8.5351944";

            string[] coordinates = feature.Split(' ');
            // System.Array.Reverse(coordinates);

            Wgs84Coordinates[] points = new Wgs84Coordinates[coordinates.Length];

            for (int i = 0; i < coordinates.Length; i++)
            {
                double lon = double.Parse(coordinates[i].Split(',')[0]);
                double lat = double.Parse(coordinates[i].Split(',')[1]);

                points[i] = new Wgs84Coordinates((decimal)lat, (decimal)lon);
            } // Next i

            double area = CalculateArea(points);

            System.Console.WriteLine(area);
        } // End Sub TestComputeArea
Esempio n. 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);
        }