I have access to an OPeNDAP
service that allows me to peek into a humongous ocean wave dataset. It takes latitude and longitude as inputs (in fact even a range of the two) - but the coordinate system is a rotated one (presumably because the dataset focus is the North Sea and the Arctic):
grid_mapping_name: rotated_latitude_longitude
grid_north_pole_longitude: 140.0
grid_north_pole_latitude: 22.0
earth_radius: 6371000.0
proj4: +proj=ob_tran +o_proj=longlat +lon_0=-40 +o_lat_p=22 +R=6.371e+06 +no_defs
I want to query specific coordinates, but I do not know how to translate these coordinates (i.e. WGS84
lat/lon from Google Maps
) into coordinates for this service. Anyone have an idea how to do this?
For example, let's say I want to transform the coordinate (57.93, 3.63)
(somewhere out in the North Sea).
Any solution is welcome, using pyproj
or something completely different.
EDIT: The OPeNDAP dataset can be found Here - it sadly does not offer a whole lot of information, but snippets of data can be extracted as ASCII.
EDIT2: This is the code I've tried, but it seems the proj4 string is not correctly interpreted:
from osgeo import osr
src = osr.SpatialReference()
tgt = osr.SpatialReference()
src.ImportFromEPSG(4326)
tgt.ImportFromProj4('+proj=ob_tran +o_proj=longlat +lon_0=-40 +o_lat_p=22 +R=6.371e+06 +no_defs')
transform = osr.CoordinateTransformation(src, tgt)
coords = transform.TransformPoint(-122, 46)
x,y = coords[0:2]
print(coords)
Returns:
(-13580977.876779377, 5780349.220256355, 0.0)
ERROR 6: No translation for an empty SRS to PROJ.4 format is known.
Traceback (most recent call last):
File "coordtrans.py", line 24, in <module>
coords = transform.TransformPoint(-122, 46)
File "C:\tools\Anaconda3\envs\testEnv\lib\site-packages\osgeo\osr.py", line 1283, in TransformPoint
return _osr.CoordinateTransformation_TransformPoint(self, *args)
NotImplementedError: Wrong number or type of arguments for overloaded function 'CoordinateTransformation_TransformPoint'.
Possible C/C++ prototypes are:
OSRCoordinateTransformationShadow::TransformPoint(double [3])
OSRCoordinateTransformationShadow::TransformPoint(double [3],double,double,double)
Run in a conda environment with gdal from conda.
The coordinate systems that can be passed are anything supported by the OGRSpatialReference.SetFromUserInput() call, which includes EPSG PCS and GCSes (i.e. EPSG:4296), PROJ.4 declarations (as above), or the name of a .prj file containing well known text.