1 year ago
#369192
bandit_hilmi
Why Geojson dumps 0 kB file in Python?
I am trying to generate a geojson file in Python. Below is my code. Code was ran with no error but generate a 0 kb geojson file.How can I fix my code? I want only geo coordinates and land no in my file.
from geojson import GeoJSONEncoder, Feature, Point, Polygon,
FeatureCollection, GeometryCollection
chopsize = 1
n=0
x0=0
y0=0
for y0 in range(0, 16, chopsize): #y
for x0 in range(0, 2, chopsize): #x
box = (x0, y0,
x0+chopsize, y0,
x0+chopsize,
y0+chopsize,
x0, y0+chopsize,
x0,y0)
n=n+1
landno=''
landno += f'Land No: {n}'
coordinates = []
coordinates += [[x0, y0],[x0 +
chopsize, y0],
[x0+chopsize,y0+chopsize],
[x0,y0+chopsize],[x0,y0]]
properties=[landno]
poly=Polygon(coordinates)
geo_collection = GeometryCollection(poly)
my_feature=(Feature(properties))
geo_data=[geo_collection,my_feature]
feature_collection = FeatureCollection(geo_data)
print(feature_collection)
with open('myfile.geojson', 'w') as f:
geojson.dumps(geo_data, sort_keys=True)
f.close()
python
json
geojson
folium
0 Answers
Your Answer