Data visualization with SAS programming

GPROJECT: Convert LAT-LONG to UTM

Accepted Solution Solved
Reply
Respected Advisor
Posts: 4,920
Accepted Solution

GPROJECT: Convert LAT-LONG to UTM

Hi,


This my first attempt to transform latitudes and longitudes into UTM (Zone 18) coordinates using SAS. PROC GPROJECT PROJECT=proj4 seems to be what I need but I can’t get the desired result :

 

data have;

id=1; lat=45.5; long=73.5;

run;

proc gproject latlon degrees westlong

project=proj4 to="EPSG:32618"  /* WGS 84 / UTM zone 18N */

data=have out=want;

id id;

run;

proc print data=want noobs; run;

       X       Y    id     lat     long

1.28282 0.79412     1    45.5     73.5


X and Y are clearly not what I expect. Please help!

PG

PG

Accepted Solutions
Solution
‎11-10-2014 10:06 PM
Respected Advisor
Posts: 4,920

Re: GPROJECT: Convert LAT-LONG to UTM

Posted in reply to Darrell_sas

Thank you Darrell, I got it now. It turns out that options EASTLONG, WESTLONG and DEGREES are ignored for METHOD=PROJ4. Longitudes must be within the specified limits for the UTM zone (and negative), otherwise GPROJECT gives garbage without any warning. The correct projection will be given by:

data have;

id=1; lat=45.5; long=-73.5;

run;

proc gproject latlon

project=proj4 to="EPSG:32618"  /* WGS 84 / UTM zone 18N */

data=have out=want;

id id;

run;

proc print data=want noobs; run;


                           X             Y    id     lat     long

                   617189.99    5039590.76     1    45.5    -73.5

PG

PG

View solution in original post


All Replies
Super User
Posts: 11,343

Re: GPROJECT: Convert LAT-LONG to UTM

I would try adding a few other points.

In 9.3 with any of the available projections except NONE a single points yields output of 0,0. So it may be an effect of not having something else to generate.

Respected Advisor
Posts: 4,920

Re: GPROJECT: Convert LAT-LONG to UTM

Thanks

This is a simplified example. I tried with almost 3000 coordinates and got all UTM coordinates between 0.5 and 1.5... Some of these coordinates are kilometers apart. All have distinct IDs however.

PG

PS. I'm using SAS 9.4

PG
Super User
Posts: 11,343

Re: GPROJECT: Convert LAT-LONG to UTM

It has been awhile since I tried projecting any data from lat/long but my results back then seemed to yield a x in the -1 to 1 and y in -1 to 2 range. I suspect those results were just SAS drawing coordinate for GMap. Maybe something similar is happening here?!

SAS Employee
Posts: 170

Re: GPROJECT: Convert LAT-LONG to UTM

What numbers are you expecting?

The doc says: The DEGREES and EASTLONG options are enabled with the PROJ4 projection method.

I think that means you CANNOT turn on WESTLONG.  I think the doc isn't very clear on this.

Also, the PROJ4 doc says the LONG/LAT must be: -78.0000, 0.0000, -72.0000, 84.0000

(WGS 84 / UTM zone 18N: EPSG Projection -- Spatial Reference)

So, you need to change your value to EASTLONG.

Solution
‎11-10-2014 10:06 PM
Respected Advisor
Posts: 4,920

Re: GPROJECT: Convert LAT-LONG to UTM

Posted in reply to Darrell_sas

Thank you Darrell, I got it now. It turns out that options EASTLONG, WESTLONG and DEGREES are ignored for METHOD=PROJ4. Longitudes must be within the specified limits for the UTM zone (and negative), otherwise GPROJECT gives garbage without any warning. The correct projection will be given by:

data have;

id=1; lat=45.5; long=-73.5;

run;

proc gproject latlon

project=proj4 to="EPSG:32618"  /* WGS 84 / UTM zone 18N */

data=have out=want;

id id;

run;

proc print data=want noobs; run;


                           X             Y    id     lat     long

                   617189.99    5039590.76     1    45.5    -73.5

PG

PG
Occasional Contributor
Posts: 8

Re: GPROJECT: Convert LAT-LONG to UTM

Hi, I have a problem somewhat similar...  here is a output test ; coordoninate are lat long from Canada territory.

 
 data have ;
 
  id = "CA-1001" ;
  long = -52.7 ;
  lat  =  47.5 ;
 
 run ;
  
  proc gproject latlon degrees eastlong
  project=proj4 to="EPSG:3347" 
  data=have out=want;
  id id ;
 
 run ;
 
 proc print data=want noobs ;
 
 run ;
 
To my understanding I am using the correct parameters... the results are at the bottom... but the x and y result should be in a 0.45 for X and - 0.08 for Y... not 1026136... ?
 
I have been trying for the last sevral hours to do the right conversion for a map project... If someone can help I would appeciate... Best regards.  Guy
 
X Y id long lat
10261036.29 2376434.81 CA-1001 -52.7

47.5 

SAS Employee
Posts: 1

Re: GPROJECT: Convert LAT-LONG to UTM

Posted in reply to CandidedeVoltaire

Guy,

 

What is the projection that you are trying to convert into?  The values that you are getting from the proc for that EPSG value appear to be correct. I looked up the range of values for the UTM represented by EPSG:3347, and those returned values are in the expected range.  

 

For reference, here is the definition of EPSG 3347 from spatialreference.org that I used:

http://spatialreference.org/ref/epsg/nad83-statistics-canada-lambert/

 

Thanks,

Scott

Occasional Contributor
Posts: 8

Re: GPROJECT: Convert LAT-LONG to UTM

Posted in reply to ScottJackson

I found the ligth at the end of the tunnel... The problem was not a conversion problem.... I was in the Mapsgfk.canada and Mapsgfk.canada_attr map files.  The X and Y variables used in those maps were generated by the map provider... I could not find any way of converting external points in Latitude and longitude to those internal coordinates.  The solution was so simple, I imported the Canadian SHP map file from open data Stat Can with MAPIMPORT... The coordinates X Y in the map is in Latitude and longitude... so I repeated the program and all is good.  Hoping my experience can be useful for someone in the future.

 

Best retards Scott

Occasional Contributor
Posts: 8

Re: GPROJECT: Convert LAT-LONG to UTM

Posted in reply to CandidedeVoltaire

Best Regards ;-)

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 3218 views
  • 3 likes
  • 5 in conversation