Aspose support to convert UTM cordinates to Lat Long

Hi team,

DO we have any conversion method to convert the UTM coordinates to Lat Long format in Aspose GIS.

Regards,
Sarika Goel

@SarikaGoel Thanks for asking! Please consider the following example:

// Source and destination SRS
var utm32N = SpatialReferenceSystem.CreateFromEpsg(32632);
var latLong = SpatialReferenceSystem.CreateFromEpsg(4326);
var transformation = utm32N.CreateTransformationTo(latLong);

// Transform geometry
var utmPoint = new Aspose.Gis.Geometries.Point(510000, 7042000);
var geoPoint = transformation.Transform(utmPoint) as Aspose.Gis.Geometries.Point;

// Write result
Console.WriteLine("UTM Easting: " + utmPoint.X);
Console.WriteLine("UTM Northing: " + utmPoint.Y);
Console.WriteLine("Longitude: " + geoPoint.X);
Console.WriteLine("Latitude: " + geoPoint.Y);

Did it help you?

@SarikaGoel,
If you need to convert a standalone coordinate, consider the example above.
If you need to convert a file with coordinates (for example a shapefile) from the UTM to the Lat Long, the following code will do it

// Create a definition of a SRS. Substitute "32632" with the EPSG code of the UTM zone you need.
var sourceSrs = SpatialReferenceSystem.CreateFromEpsg(32632);
var targetSrs = SpatialReferenceSystem.Wgs84;

// Create a transformation from UTM to WGS84 (longitude, latitude)
var srsTransformation = sourceSrs.CreateTransformationTo(targetSrs);

using (var sourceLayer = VectorLayer.Open(sourcePath, Drivers.Shapefile))
using (var targetLayer = VectorLayer.Create(targetPath, Drivers.Shapefile))
{
    targetLayer.CopyAttributes(sourceLayer);

    foreach (var sourceFeature in sourceLayer)
    {
        // Transform shapefile geometry to WGS84 (longitude, latitude)
        IGeometry sourceGeometry = sourceFeature.Geometry;
        IGeometry targetGeometry = sourceGeometry == Geometry.Null
                                       ? sourceGeometry
                                       : srsTransformation.Transform(sourceGeometry);

        // Create a feature in output layer, copy attributes, set the transformed geometry and add it.
        Feature targetFeature = targetLayer.ConstructFeature();
        targetFeature.CopyValues(sourceFeature);
        targetFeature.Geometry = targetGeometry;
        targetLayer.Add(targetFeature);
    }

@Helpdesk Team: I am using attached Geojson and want to change the 6 digits coordinates to 2 digit lat long. Kindly guide me . I have updated the drivers from shapefile to geojson.Historic_Flood_Map.zip (14.3 KB)

@SarikaGoel,

Aspose.GIS assumes that all coordinates in geojson files are in Long, Lat format. The following code works around this limitation:

// Create a definition of a SRS. Substitute "32718" with the EPSG code of the UTM zone you need.
var sourceSrs = SpatialReferenceSystem.CreateFromEpsg(32718);
var targetSrs = SpatialReferenceSystem.Wgs84;

// Create a transformation from UTM to WGS84 (longitude, latitude)
var srsTransformation = sourceSrs.CreateTransformationTo(targetSrs);

using (var sourceLayer = VectorLayer.Open(sourcePath, Drivers.GeoJson))
using (var targetLayer = VectorLayer.Create(targetPath, Drivers.GeoJson))
{
    targetLayer.CopyAttributes(sourceLayer);

    foreach (var sourceFeature in sourceLayer)
    {
        var sourceGeometry = sourceFeature.Geometry.Clone();
        // Aspose.GIS assumes that all geometries in GeoJSON are in WGS84 SRS, so we have to manually set SRS to the one we need.
        sourceGeometry.SpatialReferenceSystem = sourceSrs;
        IGeometry targetGeometry = sourceGeometry == Geometry.Null
                                       ? sourceGeometry
                                       : srsTransformation.Transform(sourceGeometry);

        // Create a feature in output layer, copy attributes, set the transformed geometry and add it.
        Feature targetFeature = targetLayer.ConstructFeature();
        targetFeature.CopyValues(sourceFeature);
        targetFeature.Geometry = targetGeometry;
        targetLayer.Add(targetFeature);
    }
}

It’s very similar to the one provided above, except for the part where we assign SRS to geometry before transformation.
Since the UTM is not a single spatial reference, but rather a family of them, you need to know what is the UTM zone of your data in order to transform it. Same 6 digit coordinates can correspond to different places on the Earth, depending on the UTM zone. There is no information about spatial reference in the Historic_Flood_Map.json, so you need to look up and specify EPSG code of the spatial reference manually. If you don’t know the UTM zone of the data, please contact your data supplier.

Hope this help.

Thanks Helpdesk team.