Convert Lat/Long DD to X,Y in Qt

6747
5
Jump to solution
01-30-2015 02:29 PM
TimMurphy2
New Contributor II

Hello! I'm new to the community so please forgive me if this is the wrong place to ask this.

I am having trouble taking GPS coordinates and displaying the data as a point on the graphics layer in the correct scaling.

My overall goal is to display multiple GPS points on a map and keep track of each point. The map I am using at the moment is the ArcGIS Qt API topographic map of the world. I have had classes in C and C++ but am fairly new to Qt and ArcGIS. I am having trouble at the moment with the taking of set DD coordinates and using the coordinate converter function to save to a point the x,y coordinates I need. Any help is appreciated thanks!

0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

You could do the following:

EsriRuntimeQt::SpatialReference sr(102100)

EsriRuntimeQt::Point new_point = EsriRuntimeQt::CoordinateConversion::DecimalDegreesToPoint(longitude, sr);

This gives me valid coordinates. My guess is that your map isn't ready (i.e. there is no spatial reference set yet, because it isn't finished initializing), so because there is no valid sr going into the function, it comes back as NaN. You can use the onMapReady slot and wait to do this calculation until that point, or you could try what I did above.

-Luke

View solution in original post

5 Replies
KishorGhatage
Occasional Contributor III

Hi Tim,

I have no idea how it is done programmatically however in ArcMap you can use Convert Coordinate Notation tool to change the format.

ArcGIS Help 10.1

If you have a point layer and would like to change the DD coordinates to meter or feet you can use Project tool.

ArcGIS Help 10.1

Hope this is helpful

Kishor

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Hey Tim,

If you are using the topographic basemap, odds are that the map is in WKID 102100 (WGS 1984 Web Mercator Auxiliary Sphere). Your GPS coordinates are likely in WKID 4326 (WGS 1984). If you want to take coordinates and convert them to the same spatial ref as the map, I would use the CoordinateConversion class - EsriRuntimeQt::CoordinateConversion Class Reference  . There is a DecimalDegreesToPoint and a DecimalDegreesToPoints function that takes either a coordinate as a string, or a list of coordinate strings in, along with the desired output spatial reference (in this case, that is most likely WKID 102100). This will return to you a Point geometry. You can then apply the Point geometry as the geometry of a Graphic, and add that Graphic to a Graphics Layer.

Hope this helps,

Luke

TimMurphy2
New Contributor II

I did find the EsriRuntimeQt::CoordinateConversion Class and I am glad to hear that I was on the right track. The issue that i am having at the moment is that I am unsure the code to go from:

        QString longitude= "40.7127N 74.0059W";

    EsriRuntimeQt::CoordinateConversion::DecimalDegreesToPoint(longitude, m_map.spatialReference());

to:

EsriRuntimeQt::Point point(261644.04, 5794404);

The point class form decimalDegrees keeps coming back empty so I am unsure how to save the point class correctly to save the latitude and longitude. Thank you for your help thus far though!

0 Kudos
LucasDanzinger
Esri Frequent Contributor

You could do the following:

EsriRuntimeQt::SpatialReference sr(102100)

EsriRuntimeQt::Point new_point = EsriRuntimeQt::CoordinateConversion::DecimalDegreesToPoint(longitude, sr);

This gives me valid coordinates. My guess is that your map isn't ready (i.e. there is no spatial reference set yet, because it isn't finished initializing), so because there is no valid sr going into the function, it comes back as NaN. You can use the onMapReady slot and wait to do this calculation until that point, or you could try what I did above.

-Luke

TimMurphy2
New Contributor II

Thank you so much! This worked like a charm! You are amazing!