+----------------------------------------- Jeff Whitaker -----------+
Jeff, I just had a thought....
Isn't the country borders drawn as Path or Polygon objects? I believe
there are some matplotlib internal functions that can be given a list
of points (such as those for a grid) and a path and it will return
which points are within the path and which are outside. One could use
that to make the mask.
Might make for a nice feature for basemap in the upcoming v1.1.0 release.
Ben Root
Ben/Yoshi: The countries are not polygons, they are line segments.
Worse yet, they are all just lumped together with no metadata (no way to
know which lines define the country you want). If you had a shapefile
with just the country of interest in it, defined as a polygon, then it's
doable You could take a look at the source code for the is_land method,
which tests to see if a given x,y point is inside any of the continent
polygons.
Let us know if you have you have the country polygon, and then I can
help you with the details.
-Jeff
Sorry for being late, i was really busy. Thank you for your offer, I have
the polygon now (attached), could you help me with this?
Best regards, Yoshi
Yoshi:
Here's the basic idea:
1) read the germany.dat file, use it to create a _geoslib Poly instance,
i.e.
from mpl_toolkits.basemap import _geoslib
b = np.asarray([lons,lats]).T # lons and lats are lists.
germanypoly = _geoslib.Polygon(b)
2) loop over all the points on the grid and do
inside = _geoslib.Point((lonpt,latpt)).within(germanypoly)
filling a boolean array with the values.
3) use this boolean array as a mask to create a masked array from your
data. Then, when you plot the masked array with contourf only the
points inside germany will be contoured.
Give this a try and let us know how it goes.
-Jeff
------------------------------------------------------------------------------
Storage Efficiency Calculator
This modeling tool is based on patent-pending intellectual property that
has been used successfully in hundreds of IBM storage optimization engage-
ments, worldwide. Store less, Store more with what you own, Move data to
the right place. Try It Now! http://www.accelacomm.com/jaw/sfnl/114/51427378/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users