我有几个要可视化的GeoJSON文件。我想像这样的东西
geojson2png input.geojson output.png以及我想要可视化的分辨率/边界框的一些参数。
http://geojson.io很棒,但上传它并为许多文件截图是不可行的。我已经看到它是open source,并尝试过geojsonio.py,但它会将数据上传到一个公共gist (和has problems)。
如果我只想在geojson.io上应用样式,而没有底层地图,我可以在本地创建它吗?
发布于 2018-10-24 21:10:11
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)https://stackoverflow.com/questions/52969257
复制相似问题