Sunday, 24 July 2016

r - Transform coordinates from NOAA


I use data from NOAA for some analysis in R and I want to transform coordinates to EPSG:54004 or something useful.


There is something what they write about their coordinates.


...    

POS: 29-34
GEOPHYSICAL-POINT-OBSERVATION latitude coordinate
The latitude coordinate of a GEOPHYSICAL-POINT-OBSERVATION where southern
hemisphere is negative.
MIN: -90000 MAX: +90000
UNITS: Angular Degrees
SCALING FACTOR: 1000
DOM: A general domain comprised of the numeric characters (0-9), a plus
sign (+), and a minus sign (-).
+99999 = Missing


POS: 35-41
GEOPHYSICAL-POINT-OBSERVATION longitude coordinate
The longitude coordinate of a GEOPHYSICAL-POINT-OBSERVATION where values west from
000000 to 179999 are signed negative.
MIN: -179999 MAX: +180000 UNITS: Angular Degrees
SCALING FACTOR: 1000
DOM: A general domain comprised of the numeric characters (0-9), a plus
sign (+), and a minus sign (-).
+999999 = Missing

...

And my problem is, that I can't transform this coodrinates correctly. I use this R command:


    sc <- cbind(st$LAT, st$LON)
ptransform(sc/180*pi,
'+proj=latlong +ellps=sphere',
'+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')

But coordinates are somehow wrong as you can see. The points should be in borders because they are meteostations from this countries. Map with points.



Answer




I solved the problem, it was in input to ptransform function in R.
Instead sc <- cbind(st$LAT, st$LON) I have to use sc <- cbind(st$LON, st$LAT). Then as you say I have to use EPSG:4326 as input CRS and EPSG:3857 as destination CRS. And the transformation with this command.


    tr <- ptransform(sc/180*pi, 
'+proj=longlat',
'+proj=merc')

Correct transformation


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...