| ... | ... |
@@ -1,7 +1,9 @@ |
| 1 |
+#-*- coding: utf-8 -*- |
|
| 1 | 2 |
import shapefile |
| 2 | 3 |
from json import dumps |
| 3 | 4 |
|
| 4 |
-sf = shapefile.Reader("pyshp/shapefiles/blockgroups")
|
|
| 5 |
+path = "pyshp/shapefiles/blockgroups" |
|
| 6 |
+sf = shapefile.Reader(path) |
|
| 5 | 7 |
|
| 6 | 8 |
fields = sf.fields[1:] |
| 7 | 9 |
field_names = [field[0] for field in fields] |
| ... | ... |
@@ -14,6 +16,5 @@ for sr in sf.shapeRecords(): |
| 14 | 16 |
buffer.append(dict(type="Feature", geometry=geom, properties=atr)) |
| 15 | 17 |
|
| 16 | 18 |
geojson = open("pyshp-demo.geojson", "w")
|
| 17 |
-geojson.write(dumps({"type": "FeatureCollection",\
|
|
| 18 |
-"features": buffer}, indent=2) + "\n") |
|
| 19 |
+geojson.write(dumps({"type": "FeatureCollection", "features": buffer}, indent=2, ensure_ascii=False))
|
|
| 19 | 20 |
geojson.close() |