Skip to content

Commit 9dfa89c

Browse files
author
Jeff Whitaker
committed
Merge branch 'master' of https://github.com/jswhit/basemap
2 parents 805ad9b + 97147b5 commit 9dfa89c

File tree

4 files changed

+123
-57
lines changed

4 files changed

+123
-57
lines changed

Changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
version 1.0.8 (not yet released)
22
--------------------------------
3+
* fix for coastline drawing glitch (issue 123).
34
* update shapefile.py to version 1.2.0 from pyshp.googlecode.com. Add back
45
in modification clobbered in upgrade to version 1.1.7 (issue 30).
56
* added 'facecolor' keyward argument to drawcounties() method; gives user
67
ability to fill counties with specified matplotlib color argument.
8+
* fix drawgreatcircle bug so that lines exiting and reentering a projection
9+
region don't draw horizontally across the map.
710

811
version 1.0.7 (git tag v1.0.7rel)
912
---------------------------------

README renamed to README.md

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
**Descripton**
1+
#Basemap
22

3-
basemap - plot on map projections (with coastlines and political boundaries)
3+
Plot on map projections (with coastlines and political boundaries)
44
using matplotlib.
55

6-
**Requirements**
6+
##Requirements
77

8-
python 2.5 (or higher)
8+
* python 2.5 (or higher)
99

10-
matplotlib
10+
* matplotlib
1111

12-
numpy
12+
* numpy
1313

14-
The GEOS (Geometry Engine - Open Source) library (version 3.1.1 or higher).
14+
* The GEOS (Geometry Engine - Open Source) library (version 3.1.1 or higher).
1515
Source code is included in the geos-3.3.3 directory.
1616

17-
PIL (http://pythonware.com/products/pil) is optional (only
17+
* PIL (http://pythonware.com/products/pil) is optional (only
1818
needed for Basemap warpimage and bluemarble methods).
1919

20-
On linux, if your python was installed via a package management system, make
20+
* On linux, if your python was installed via a package management system, make
2121
sure the corresponding "python-dev" package is also installed. Otherwise, you
2222
may not have the python header (Python.h), which is required to build python
2323
C extensions.
2424

25-
**Copyright**
25+
##Copyright
2626

2727
source code from proj.4 (http://proj.maptools.org) is included in the
2828
'src' directory under the terms given in LICENSE_proj4.
@@ -61,7 +61,7 @@ USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
6161
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
6262
PERFORMANCE OF THIS SOFTWARE.
6363

64-
**Documentation**
64+
##Documentation
6565

6666
see http://matplotlib.github.com/basemap/
6767

@@ -70,64 +70,42 @@ see scripts in 'examples' directory for example usage.
7070
read the FAQ and/or email the matplotlib-users mailing list if
7171
you have problems or questions.
7272

73-
**Install**
73+
##Install
7474

75-
0) Install pre-requisite python modules numpy and matplotlib.
75+
0. Install pre-requisite python modules numpy and matplotlib.
7676

77-
1) Then download basemap-X.Y.Z.tar.gz (approx 100 mb) from
77+
1. Then download basemap-X.Y.Z.tar.gz (approx 100 mb) from
7878
the sourceforge download site, unpack and cd to basemap-X.Y.Z.
7979

80-
2) Install the GEOS library. If you already have it on your
80+
2. Install the GEOS library. If you already have it on your
8181
system, just set the environment variable GEOS_DIR to point to the location
8282
of libgeos_c and geos_c.h (if libgeos_c is in /usr/local/lib and
8383
geos_c.h is in /usr/local/include, set GEOS_DIR to /usr/local).
8484
Then go to step (3). If you don't have it, you can build it from
8585
the source code included with basemap by following these steps:
8686

87-
> cd geos-3.3.3
88-
> export GEOS_DIR=<where you want the libs and headers to go>
89-
A reasonable choice on a Unix-like system is /usr/local, or
90-
if you don't have permission to write there, your home directory.
91-
> ./configure --prefix=$GEOS_DIR
92-
> make; make install
87+
```
88+
> cd geos-3.3.3
89+
> export GEOS_DIR=<where you want the libs and headers to go>
90+
A reasonable choice on a Unix-like system is /usr/local, or
91+
if you don't have permission to write there, your home directory.
92+
> ./configure --prefix=$GEOS_DIR
93+
> make; make install
94+
```
9395

94-
3) cd back to the top level basemap directory (basemap-X.Y.Z) and
96+
3. cd back to the top level basemap directory (basemap-X.Y.Z) and
9597
run the usual 'python setup.py install'. Check your installation
9698
by running "from mpl_toolkits.basemap import Basemap" at the python
9799
prompt.
98100

99-
4) To test, cd to the examples directory and run 'python simpletest.py'.
101+
4. To test, cd to the examples directory and run 'python simpletest.py'.
100102
To run all the examples (except those that have extra dependencies
101103
or require an internet connection), execute 'python run_all.py'.
102104

103-
**Contact**
105+
##Contact
104106

105107
Jeff Whitaker <[email protected]>
106108

109+
##Thanks
107110

108-
**Thanks**
109-
110-
to
111-
112-
John Hunter
113-
Andrew Straw
114-
Eric Firing
115-
Rob Hetland
116-
Scott Sinclair
117-
Ivan Lima
118-
Erik Andersen
119-
Michael Hearne
120-
Jesper Larsen
121-
Ryan May
122-
David Huard
123-
Mauro Cavalcanti
124-
Chris Murphy
125-
Pierre Gerard-Marchant
126-
Christoph Gohlke
127-
Eric Bruning
128-
Stephane Raynaud
129-
Tom Loredo
130-
Patrick Marsh
131-
Phil Elson
132-
133-
for valuable contributions.
111+
Special thanks to John Hunter, Andrew Straw, Eric Firing, Rob Hetland, Scott Sinclair, Ivan Lima, Erik Andersen, Michael Hearne, Jesper Larsen, Ryan May, David Huard, Mauro Cavalcanti, Chris Murphy, Pierre Gerard-Marchant, Christoph Gohlke, Eric Bruning, Stephane Raynaud, Tom Loredo, Patrick Marsh, Phil Elson, and Henry Hammond for valuable contributions.

examples/nytolondon.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
# lonlat, lonlon are lat/lon of London.
1818
lonlat = 51.53
1919
lonlon = 0.08
20+
2021
# find 1000 points along the great circle.
2122
#x,y = m.gcpoints(nylon,nylat,lonlon,lonlat,1000)
2223
# draw the great circle.
2324
#m.plot(x,y,linewidth=2)
2425
# drawgreatcircle performs the previous 2 steps in one call.
2526
m.drawgreatcircle(nylon,nylat,lonlon,lonlat,linewidth=2,color='b')
27+
2628
m.drawcoastlines()
2729
m.fillcontinents()
2830
# draw parallels
@@ -46,6 +48,7 @@
4648
# lonlat, lonlon are lat/lon of London.
4749
lonlat = 51.53
4850
lonlon = 0.08
51+
4952
# find 1000 points along the great circle.
5053
#x,y = m.gcpoints(nylon,nylat,lonlon,lonlat,1000)
5154
# draw the great circle.
@@ -62,4 +65,57 @@
6265
m.drawmeridians(meridians,labels=[1,1,0,1])
6366
plt.title('Great Circle from New York to London (Gnomonic)')
6467
sys.stdout.write('plotting Great Circle from New York to London (Gnomonic)\n')
68+
69+
fig=plt.figure()
70+
71+
72+
# Example of Great Circles which exit and reenter the map
73+
m = Basemap(projection='robin', lat_0=0, lon_0=0,resolution='c')
74+
75+
m.drawmapboundary(fill_color='#ffffff',color='#ffffff')
76+
m.fillcontinents(color='#f2f2f2',lake_color='#ffffff')
77+
m.drawcoastlines(color='#e0e0e0')
78+
m.drawcountries(color='#e0e0e0')
79+
80+
parallels = np.arange(-90,90,10.)
81+
meridians = np.arange(10.,351.,20.)
82+
m.drawparallels(parallels,labels=[False,False,False,False], color='#d3d3d3',dashes=[1,3])
83+
m.drawmeridians(meridians,labels=[False,False,False,False], color='#d3d3d3',dashes=[1,3])
84+
85+
# Choose the lat and longtitude of two points
86+
87+
p1 = (45.27,-75.42) # roughly Ottawa
88+
p2 = (44.05,-4.28) # roughly Paris
89+
p3 = (-38.58,145.05) # roughly Victoria
90+
91+
la1, lo1 = p1
92+
la2, lo2 = p2
93+
la3, lo3 = p3
94+
95+
# Drawing points; you need to convert from lon-lat to xy-cartesian
96+
x1,y1 = m(lo1,la1)
97+
x2,y2 = m(lo2,la2)
98+
x3,y3 = m(lo3,la3)
99+
100+
# Convert back by setting inverse=True
101+
lon,lat = m(x1,y1,inverse=True)
102+
103+
# Plot pionts using markers
104+
m.plot(x1,y1, marker='.', markersize=8, color='#000000')
105+
m.plot(x2,y2, marker='.', markersize=8, color='#000000')
106+
m.plot(x3,y3, marker='.', markersize=8, color='#000000')
107+
108+
# Of note, the map uses metres as it's smallest distance, so 1000*x is x km
109+
# The offset is in projection cooordinates
110+
plt.text(x1+100000,y1+100000,'Ottawa')
111+
plt.text(x2+100000,y2+100000,'Paris')
112+
plt.text(x3+100000,y3+100000,'Victoria')
113+
114+
# Draw a great circle line joining them
115+
m.drawgreatcircle(lo1,la1,lo2,la2,linewidth=1,color='#000000',alpha=1,del_s=100)
116+
m.drawgreatcircle(lo2,la2,lo3,la3,linewidth=1,color='#000000',alpha=1,del_s=100)
117+
118+
# Drawing a great circle which exits and reenters the map works on certain projections
119+
m.drawgreatcircle(lo1,la1,lo3,la3,linewidth=1,color='#FF0000',alpha=1,del_s=100)
120+
65121
plt.show()

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ def _readboundarydata(self,name,as_polygons=False):
14041404
xd = (bx[1:]-bx[0:-1])**2
14051405
yd = (by[1:]-by[0:-1])**2
14061406
dist = np.sqrt(xd+yd)
1407-
split = dist > 0.5*(self.xmax-self.xmin)
1407+
split = dist > 0.1*(self.xmax-self.xmin)
14081408
if np.sum(split) and self.projection not in _cylproj:
14091409
ind = (np.compress(split,np.squeeze(split*np.indices(xd.shape)))+1).tolist()
14101410
iprev = 0
@@ -2891,10 +2891,6 @@ def drawgreatcircle(self,lon1,lat1,lon2,lat2,del_s=100.,**kwargs):
28912891
method of Basemap instance.
28922892
============== =======================================================
28932893
2894-
.. note::
2895-
Cannot handle situations in which the great circle intersects
2896-
the edge of the map projection domain, and then re-enters the domain.
2897-
28982894
Returns a matplotlib.lines.Line2D object.
28992895
"""
29002896
# use great circle formula for a perfect sphere.
@@ -2908,7 +2904,34 @@ def drawgreatcircle(self,lon1,lat1,lon2,lat2,del_s=100.,**kwargs):
29082904
lats.append(lat)
29092905
lons.append(lon2); lats.append(lat2)
29102906
x, y = self(lons, lats)
2911-
return self.plot(x,y,**kwargs)
2907+
2908+
# Correct wrap around effect of great circles
2909+
2910+
# get points
2911+
p = self.plot(x,y,**kwargs)[0].get_path()
2912+
2913+
# since we know the difference between any two points, we can use this to find wrap arounds on the plot
2914+
max_dist = 1000*del_s*2
2915+
2916+
# calculate distances and compare with max allowable distance
2917+
dists = np.abs(np.diff(p.vertices[:,0]))
2918+
cuts = np.where( dists > max_dist )[0]
2919+
2920+
# if there are any cut points, cut them and begin again at the next point
2921+
for i,k in enumerate(cuts):
2922+
# vertex to cut at
2923+
cut_point = cuts[i]
2924+
2925+
# create new vertices with a nan inbetween and set those as the path's vertices
2926+
verts = np.concatenate(
2927+
[p.vertices[:cut_point, :],
2928+
[[np.nan, np.nan]],
2929+
p.vertices[cut_point+1:, :]]
2930+
)
2931+
p.codes = None
2932+
p.vertices = verts
2933+
2934+
return p
29122935

29132936
def transform_scalar(self,datin,lons,lats,nx,ny,returnxy=False,checkbounds=False,order=1,masked=False):
29142937
"""
@@ -4058,10 +4081,16 @@ def warpimage(self,image="bluemarble",scale=None,**kwargs):
40584081
40594082
returns a matplotlib.image.AxesImage instance.
40604083
"""
4084+
4085+
# fix PIL import on some versions of OSX and scipy
40614086
try:
40624087
from PIL import Image
40634088
except ImportError:
4064-
raise ImportError('warpimage method requires PIL (http://www.pythonware.com/products/pil)')
4089+
try:
4090+
import Image
4091+
except ImportError:
4092+
raise ImportError('warpimage method requires PIL (http://www.pythonware.com/products/pil)')
4093+
40654094
from matplotlib.image import pil_to_array
40664095
if self.celestial:
40674096
msg='warpimage does not work in celestial coordinates'

0 commit comments

Comments
 (0)