我有几个可以可视化的GeoJSON文件。我想像
geojson2png input.geojson output.png
以及一些我想形象化的分辨率/边界框的参数。
http://geojson.io很棒,但是上传它并为许多文件拍摄屏幕截图并不可行。我已经看到它是open source,并尝试过geojsonio.py
,但这会将数据上传到公共要点(和has problems)。
如果我只想像在geojson.io上那样应用样式,没有基础地图,可以在本地创建吗?
答案 0 :(得分:0)
from functools import partial
import json
# 3rd party modules
from descartes import PolygonPatch
from shapely import ops
from shapely.geometry.geo import shape
import matplotlib.pyplot as plt
import pyproj
def project(polygon):
geom_area = ops.transform(
partial(
pyproj.transform,
pyproj.Proj(init='EPSG:4326'),
pyproj.Proj(
proj='aea',
lat1=polygon.bounds[1],
lat2=polygon.bounds[3])),
polygon)
return geom_area
def visualize_geojson(geojson_filepath, png_destination='out.png'):
with open(geojson_filepath) as f:
features = json.loads(f.read())
fig = plt.figure(figsize=(25, 25), dpi=300)
ax = fig.gca()
for feature in features['features']:
fc = feature['properties'].get('fill', '#555555')
polygon = shape(feature['geometry'])
ax.add_patch(PolygonPatch(project(polygon),
fc=fc,
ec='#555555',
alpha=0.5,
zorder=2))
ax.axis('scaled')
plt.savefig(png_destination, dpi=300, pad_inches=0)