Converting geography decimal to UTM

Topics: SharpMap Project
Mar 13, 2011 at 9:51 AM

Hi.

Can you give me a code example for using projnet or other tool to convert decimal coordinates to UTM coordinates.

 

Thanks Ahead.

 

Coordinator
Mar 13, 2011 at 11:42 AM

Hi, you could do like this.

 

ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
ProjNet.CoordinateSystems.ICoordinateSystem wgs84 = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
ProjNet.CoordinateSystems.ICoordinateSystem utm33 = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(33, true);
ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(wgs84, utm33);

double[] coords = tranformation.MathTransform.Transform(new double[] { lon, lat });

 

Mar 15, 2011 at 10:10 AM
Thanks.
i.e
Do you know how to convert decimal jpw file to a UTM jpw ?.


2011/3/13 petlof <notifications@codeplex.com>

From: petlof

Hi, you could do like this.

ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
ProjNet.CoordinateSystems.ICoordinateSystem wgs84 = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
ProjNet.CoordinateSystems.ICoordinateSystem utm33 = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(33, true);
ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(wgs84, utm33);

double[] coords = tranformation.MathTransform.Transform(new double[] { lon, lat });

Read the full discussion online.

To add a post to this discussion, reply to this email (SharpMap@discussions.codeplex.com)

To start a new discussion for this project, email SharpMap@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Coordinator
Mar 15, 2011 at 10:13 AM

Use gdal_warp utility in the FWTools package.

http://fwtools.maptools.org/

Mar 20, 2011 at 11:46 AM
Hi.
How do i convert UTM to geography decimal ?.
Thanks Ahead.
2011/3/13 petlof <notifications@codeplex.com>

From: petlof

Hi, you could do like this.

ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
ProjNet.CoordinateSystems.ICoordinateSystem wgs84 = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
ProjNet.CoordinateSystems.ICoordinateSystem utm33 = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(33, true);
ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(wgs84, utm33);

double[] coords = tranformation.MathTransform.Transform(new double[] { lon, lat });

Read the full discussion online.

To add a post to this discussion, reply to this email (SharpMap@discussions.codeplex.com)

To start a new discussion for this project, email SharpMap@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Coordinator
Mar 20, 2011 at 6:15 PM

Just change

ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(wgs84, utm33);


to
ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(utm33, wgs84);

instead.


Jun 11, 2014 at 10:40 AM
Hi,

Why doesn't work in my code;

ICoordinateSystem,
ICoordinateTransformation,
tranformation.

Error : The type or namespace name '...' does not exist in the namespace 'ProjNet....' (Are you missing an assembly reference) ?
Jun 11, 2014 at 10:42 AM
My code;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjNet.Converters.WellKnownText;
using ProjNet.CoordinateSystems.Transformations;
using ProjNet.CoordinateSystems.Projections;
using SharpMap;

namespace GPSTest
{
class Program
{
    static void Main(string[] args)
    {
        ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
        ProjNet.CoordinateSystems.ICoordinateSystem wgs84 = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
        ProjNet.CoordinateSystems.ICoordinateSystem utm33 = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(33, true);
        ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(utm33, wgs84);

        double[] coords = tranformation.MathTransform.Transform(new double[] { lon, lat });
    }
}
}
Coordinator
Jun 11, 2014 at 10:51 AM
The interfaces are defined in GeoAPI
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using ProjNet.Converters.WellKnownText; 
using ProjNet.CoordinateSystems.Transformations; 
using ProjNet.CoordinateSystems.Projections; 
using SharpMap; 

namespace GPSTest 
{
class Program
{
    static void Main(string[] args)
    {
        ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = 
            new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
        GeoAPI.CoordinateSystems.ICoordinateSystem wgs84 = 
            ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
        GeoAPI.CoordinateSystems.ICoordinateSystem utm33 = 
            ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(33, true);
        GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation transformation = 
            ctFact.CreateFromCoordinateSystems(utm33, wgs84);

        double[] coords = tranformation.MathTransform.Transform(new double[] { lon, lat });
    }
}
}
Jun 11, 2014 at 11:39 AM
Thank you FObermaier,

My problem is abut Proj.Net version. I downloaded again Proj.Net, now it solved.

Thanks
Sep 2, 2014 at 10:56 PM
Hi - This is my first time trying this. I'm getting the same error at one of the other posts: The type or namespace name 'ICoordinateSystem' does not exist in the namespace 'ProjNet.CoordinateSystems'. Obviously I'm missing a reference or something. In the earlier post he download ProjNet, but that is included in the SharpMap (Core + UI) download among other items. Although, I did try downloading it. I also tried changing the target framwork to .net 4 from 4.51, as I saw in another post.

My code is below. Any thoughts?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GeoAPI;
using GeoAPI.CoordinateSystems;
using ProjNet.Converters.WellKnownText;
using ProjNet.CoordinateSystems.Transformations;
using ProjNet.CoordinateSystems.Projections;
using SharpMap;

namespace UTMtoLatLong
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void convertButton_Click(object sender, EventArgs e)
        {
            
            double lat = Convert.ToDouble(xCoordTextBox.Text.Trim());
            double lon = Convert.ToDouble(YCoordTextBox.Text.Trim());

            ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            ProjNet.CoordinateSystems.ICoordinateSystem wgs84 = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
            ProjNet.CoordinateSystems.ICoordinateSystem utm33 = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(33, true);
            ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(utm33, wgs84);

            double[] coords = tranformation.MathTransform.Transform(new double[] { lon, lat });

        }
    }
}
Coordinator
Sep 3, 2014 at 7:18 AM
As I said earlier, the interfaces are defined in GeoAPI.
This should work:
// ....
var ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
var wgs84 = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
var utm33 = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(33, true);
var transformation = ctFact.CreateFromCoordinateSystems(utm33, wgs84);
//....