-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_grid_inside_polygon.py
50 lines (29 loc) · 1013 Bytes
/
create_grid_inside_polygon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import uuid
import geopandas as gpd
import fiona
import numpy as np
from shapely.geometry import Polygon
aoi = gpd.read_file(r'D:/aus_v2/iwm_0.001_aus_uuid_part1_north_selected.shp')
#for index, row in aoi.iterrows():
#print(index)
polygons = []
uuid_list = []
xmin, ymin, xmax, ymax = aoi.geometry.total_bounds
length = 0.001
wide = 0.001
cols = list(np.arange(xmin, xmax, wide))
rows = list(np.arange(ymin, ymax, length))
#shp_data['uuid'][i] = str(uuid.uuid4())
for x in cols[:-1]:
for y in rows[:-1]:
uuid_id = str(uuid.uuid4())
uuid_list.append(uuid_id)
polygons.append(Polygon([(x,y), (x+wide, y), (x+wide, y+length), (x, y+length)]))
#id_aoi = id_aoi + 1
#break
out_filename = "D:/aus_v2/iwm_0.01/iwm_0.001_aus_uuid_part1_north_" + row.uuid + ".shp"
grid = gpd.GeoDataFrame({'uuid': uuid_list, 'geometry':polygons})
grid['iwm_uuid'] = row.uuid
grid = grid.set_crs(aoi.crs)
#with fiona.Env(OSR_WKT_FORMAT="WKT2_2018"):
# grid.to_file(out_filename)