diff options
| author | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2017-06-21 18:55:43 -0400 |
|---|---|---|
| committer | Kristian Evers <kristianevers@gmail.com> | 2017-08-04 18:11:11 +0200 |
| commit | c974baa2238959cba65000ddd5dc89698e3421c9 (patch) | |
| tree | 7359efcd3f01266c9cdad4e85a82e425fdcbfb4e /docs/plot/plot.py | |
| parent | a5050370c9150cfefa720156f820840292e69e1c (diff) | |
| download | PROJ-c974baa2238959cba65000ddd5dc89698e3421c9.tar.gz PROJ-c974baa2238959cba65000ddd5dc89698e3421c9.zip | |
Specify PROJ_LIB when generating plots.
Otherwise, it will try to use pre-installed data instead of a local
copy.
Diffstat (limited to 'docs/plot/plot.py')
| -rw-r--r-- | docs/plot/plot.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/docs/plot/plot.py b/docs/plot/plot.py index 8eebad24..b1286f33 100644 --- a/docs/plot/plot.py +++ b/docs/plot/plot.py @@ -62,7 +62,7 @@ from shapely.ops import transform from descartes import PolygonPatch PROJ = '../../src/proj' -#PROJ = 'proj' +PROJ_LIB = '../../nad' LINE_LOW = 'data/coastline.geojson' LINE_MED = 'data/coastline50.geojson' @@ -77,6 +77,7 @@ COLOR_LAND = '#000000' COLOR_COAST = '#000000' COLOR_GRAT = '#888888' + def interp_coords(coords, tol): ''' Interpolates extra coordinates when the euclidean distance between adjacent @@ -128,6 +129,7 @@ def interp_coords(coords, tol): return xy + def project(coordinates, proj_string, in_radians=False): ''' Project geographical coordinates @@ -152,12 +154,14 @@ def project(coordinates, proj_string, in_radians=False): args = [PROJ, '-b'] args.extend(proj_string.split(' ')) - proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + env={'PROJ_LIB': os.path.abspath(PROJ_LIB)}) stdout, _ = proc.communicate(coordinates.tobytes()) out = np.frombuffer(stdout, dtype=np.double) return np.reshape(out, (-1, 2)) + def project_xy(x, y, proj_string): ''' Wrapper for project() that works with shapely.ops.transform(). @@ -165,6 +169,7 @@ def project_xy(x, y, proj_string): a = project(zip(x, y), proj_string) return zip(*a) + def meridian(lon, lat_min, lat_max): ''' Calculate meridian coordinates. @@ -174,6 +179,7 @@ def meridian(lon, lat_min, lat_max): coords[:, 1] = np.linspace(lat_min, lat_max, N_POINTS) return coords + def parallel(lat, lon_min, lon_max): ''' Calculate parallel coordinates. @@ -183,6 +189,7 @@ def parallel(lat, lon_min, lon_max): coords[:, 1] = lat return coords + def build_graticule(lonmin=-180, lonmax=180, latmin=-85, latmax=85): ''' Build graticule @@ -215,6 +222,7 @@ def resample_polygon(polygon): rings.append(interp_coords(int_ring.coords.xy, 2)) return Polygon(ext, rings) + def plotproj(plotdef, data, outdir): ''' Plot map. @@ -343,5 +351,6 @@ def main(): for key in data: data[key].close() + if __name__ == "__main__": sys.exit(main()) |
