5

I'm new to ProjNET and NetTopologySuite, I get some points with Lon/Lat in WGS84, and the distance between two points is not with the unit of meter, so I want to reproject the coordinate system from WGS84 to UTM, here is the code

        NetTopologySuite.Geometries.PrecisionModel precisionModel = new NetTopologySuite.Geometries.PrecisionModel(GeoAPI.Geometries.PrecisionModels.Floating);

        ProjNet.CoordinateSystems.CoordinateSystem wgs84 = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
        ProjNet.CoordinateSystems.CoordinateSystem utm50 = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(50, true);


        int SRID_wgs84 = Convert.ToInt32(wgs84.AuthorityCode);    //WGS84 SRID
        int SRID_utm50 = Convert.ToInt32(utm50.AuthorityCode);    //UTM50 SRID

        ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
        GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(wgs84, utm50);


        NetTopologySuite.Geometries.GeometryFactory factory_wgs84 = new NetTopologySuite.Geometries.GeometryFactory(precisionModel, SRID_wgs84);


        var q1_rad_wgs84 = factory_wgs84.CreatePoint(new GeoAPI.Geometries.Coordinate(Deg2Rad(117.977319), Deg2Rad(30.957558)));
        var q2_rad_wgs84 = factory_wgs84.CreatePoint(new GeoAPI.Geometries.Coordinate(Deg2Rad(117.577319), Deg2Rad(30.757558)));


        double[] coords_p1 = transformation.MathTransform.Transform(new double[] { q1_rad_wgs84.X, q1_rad_wgs84.Y });
        double[] coords_p2 = transformation.MathTransform.Transform(new double[] { q2_rad_wgs84.X, q2_rad_wgs84.Y });

        NetTopologySuite.Geometries.GeometryFactory factory_utm50 = new NetTopologySuite.Geometries.GeometryFactory(precisionModel, SRID_utm50);

        var p1_utm50 = factory_utm50.CreatePoint(new GeoAPI.Geometries.Coordinate(coords_p1[0], coords_p1[1]));
        var p2_utm50 = factory_utm50.CreatePoint(new GeoAPI.Geometries.Coordinate(coords_p2[0], coords_p2[1]));

        var distance_in_meter = p1_utm50.Distance(p2_utm50);

but I found that, after reproject the coordinate, the value of distance_in_meter is wrong.

Is there any problems with my codes?

2

Based on the Proj.Net FAQ, I believe the input values do not need to be converted to radians. Often, projection and transformation functions accept coordinate values in the input coordinate reference system's unit and will return values in the output coordinate reference system unit of measure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.