Wizard Book


Programming Python, Web, Android

Python: Konversi SHP menjadi GeoJSON menggunakan PySHP

Mengkonversi File Peta SHP shapefile menjadi GeoJSON menggunakan Python PySHP

#pip install pyshp
import shapefile
# read the shapefile
reader = shapefile.Reader("cities.shp")
fields = reader.fields[1:]
field_names = [field[0] for field in fields]
buffer = []
for sr in reader.shapeRecords():
    atr = dict(zip(field_names, sr.record))
    geom = sr.shape.__geo_interface__
    buffer.append(dict(type="Feature", \
    geometry=geom, properties=atr))
    
# write the GeoJSON file
from json import dumps
geojson = open("citites.json", "w")
geojson.write(dumps({"type": "FeatureCollection",\
"features": buffer}, indent=2) + "\n")
geojson.close()

http://geospatialpython.com/2013/07/shapefile-to-geojson.html https://stackoverflow.com/questions/43119040/shapefile-into-geojson-conversion-python-3

email : contohprogram.com@gmail.com
WA : +6289671400363