import shapefile# read the shapefilereader = shapefile.Reader("my.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 filefrom json import dumpsgeojson = open("pyshp-demo.json", "w")geojson.write(dumps({"type": "FeatureCollection","features": buffer}, indent=2) + "\n")geojson.close()
--
You received this message because you are subscribed to the Google Groups "Geospatial Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geospatialpyth...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Geospatial Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geospatialpyth...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
TypeError: b' ' is not JSON serializable
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Isaac\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 580, in runfile execfile(filename, namespace) File "C:\Users\Isaac\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 48, in execfile exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace) File "C:/python_projects/shp_to_geojson.py", line 24, in <module>
"features": buffer}, indent=2) + "\n")
File "C:\Users\Isaac\Anaconda3\lib\json\__init__.py", line 237, in dumps **kw).encode(obj) File "C:\Users\Isaac\Anaconda3\lib\json\encoder.py", line 194, in encode chunks = list(chunks) File "C:\Users\Isaac\Anaconda3\lib\json\encoder.py", line 422, in _iterencode yield from _iterencode_dict(o, _current_indent_level) File "C:\Users\Isaac\Anaconda3\lib\json\encoder.py", line 396, in _iterencode_dict yield from chunks File "C:\Users\Isaac\Anaconda3\lib\json\encoder.py", line 317, in _iterencode_list yield from chunks File "C:\Users\Isaac\Anaconda3\lib\json\encoder.py", line 396, in _iterencode_dict yield from chunks File "C:\Users\Isaac\Anaconda3\lib\json\encoder.py", line 396, in _iterencode_dict yield from chunks File "C:\Users\Isaac\Anaconda3\lib\json\encoder.py", line 429, in _iterencode o = _default(o) File "C:\Users\Isaac\Anaconda3\lib\json\encoder.py", line 173, in default raise TypeError(repr(o) + " is not JSON serializable")TypeError: b' ' is not JSON serializable