Basemap from proj4 string

Hi,

Is it possible to create a Basemap instance directly from a proj4 string and min/max values of the x and y coordinates?

Or is there a simple and safe way to construct Basemap input arguments/values from a general proj.4 string?

Does anyone know if this is possible?

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Basemap-from-proj4-string-tp43428p44290.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I think some examples would help. Which proj4 string are you looking to use? How are you currently constructing the map?
-p

···

On Wed, Nov 5, 2014 at 7:53 AM, knutfrode <knutfrodesoppel@…32…> wrote:

Does anyone know if this is possible?

View this message in context: http://matplotlib.1069221.n5.nabble.com/Basemap-from-proj4-string-tp43428p44290.html

Sent from the matplotlib - users mailing list archive at Nabble.com.



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

As an example, say I have a proj4 string defining a spatial reference system:
p4 = ‘+lon_0=0.0 +lat_ts=60.0 +R=6370997.0 +proj=stere +x_0=-0.0 +units=m +y_0=4327039.11059 +lat_0=90.0’

Then one can construct a Basemap from this as:
map = Basemap(projection=‘stere’, lon_0=0., lat_0=90, lat_ts=60,
llcrnrlat=50, urcrnrlat=70, llcrnrlon=0, urcrnrlon=20)

I could make a function to construct Basemap arguments from any user specified proj4 string (which is out of control of my application). But that function would probably be long and contain a lot of projection-specific if-then-switches. Copying proj4 arguments directly does not work, e.g. if passing “x_0=0” Basemap complains that x_0 is an unexpected argument.
The problem of making a long parser is not that this is tedious, but that it is error prone and unstable e.g. with respect to future upgrades of Basemap or proj4 libraries.

So as Basemap obviously does have an algorithm to create a proj4 string from its input arguments, I was hoping the reverse algorithm would also be available somehow. E.g. it would be very useful to be able to initialise a Basemap with:

map = Basemap(proj4=p4, llcrnrlat=50, urcrnrlat=70, llcrnrlon=0, urcrnrlon=20)

Knut-Frode

···

Date: Wed, 5 Nov 2014 09:32:16 -0800

I think some examples would help. Which proj4 string are you looking to use? How are you currently constructing the map?
-p

On Wed, Nov 5, 2014 at 7:53 AM, knutfrode <knutfrodesoppel@…32…> wrote:

Does anyone know if this is possible?

View this message in context: http://matplotlib.1069221.n5.nabble.com/Basemap-from-proj4-string-tp43428p44290.html

Sent from the matplotlib - users mailing list archive at Nabble.com.



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I agree that it would be useful, but basemap doesn’t support EPSG codes, so this isn’t fully possible in general.

On a side note, if you’re ever just wanting to transform coordinates, pyproj supports generic proj4 strings. (e.g. “proj = pyproj.Proj(your_proj4_string)”)

It might be possible to initialize a projection in Cartopy from a generic pyproj projection… I’m not sure, though.

At any rate, that doesn’t answer your question at all, but consider it food for thought.

Cheers,

-Joe

···

On Fri, Nov 7, 2014 at 7:16 AM, Knut-Frode Dagestad <knutfrodesoppel@…32…> wrote:

As an example, say I have a proj4 string defining a spatial reference system:
p4 = ‘+lon_0=0.0 +lat_ts=60.0 +R=6370997.0 +proj=stere +x_0=-0.0 +units=m +y_0=4327039.11059 +lat_0=90.0’

Then one can construct a Basemap from this as:
map = Basemap(projection=‘stere’, lon_0=0., lat_0=90, lat_ts=60,
llcrnrlat=50, urcrnrlat=70, llcrnrlon=0, urcrnrlon=20)

I could make a function to construct Basemap arguments from any user specified proj4 string (which is out of control of my application). But that function would probably be long and contain a lot of projection-specific if-then-switches. Copying proj4 arguments directly does not work, e.g. if passing “x_0=0” Basemap complains that x_0 is an unexpected argument.
The problem of making a long parser is not that this is tedious, but that it is error prone and unstable e.g. with respect to future upgrades of Basemap or proj4 libraries.

So as Basemap obviously does have an algorithm to create a proj4 string from its input arguments, I was hoping the reverse algorithm would also be available somehow. E.g. it would be very useful to be able to initialise a Basemap with:

map = Basemap(proj4=p4, llcrnrlat=50, urcrnrlat=70, llcrnrlon=0, urcrnrlon=20)

Knut-Frode


Date: Wed, 5 Nov 2014 09:32:16 -0800

I think some examples would help. Which proj4 string are you looking to use? How are you currently constructing the map?
-p

On Wed, Nov 5, 2014 at 7:53 AM, knutfrode <knutfrodesoppel@…32…> wrote:

Does anyone know if this is possible?

View this message in context: http://matplotlib.1069221.n5.nabble.com/Basemap-from-proj4-string-tp43428p44290.html

Sent from the matplotlib - users mailing list archive at Nabble.com.



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users