-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGeoTool.py
More file actions
35 lines (28 loc) · 942 Bytes
/
Copy pathGeoTool.py
File metadata and controls
35 lines (28 loc) · 942 Bytes
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
import shapely
import shapely.geometry
wgs84metter = 8.983111749910168882500898311175e-6
wgs84kmetter = wgs84metter * 1000
def SplitGeometry(jsonobj, splitter = wgs84kmetter):
res = []
shgeo = shapely.geometry.shape(jsonobj)
b = shgeo.bounds
xmin = b[0]
ymin = b[1]
xmax = b[2]
ymax = b[3]
xmincut = xmin
ymincut = ymin
while (ymincut < ymax):
xmaxcut = xmincut + splitter
ymaxcut = ymincut + splitter
cutgeo = shapely.geometry.box(xmincut, ymincut, xmaxcut, ymaxcut)
xmincut = xmincut + splitter
if (xmincut > xmax):
xmincut = xmin
ymincut = ymincut + splitter
cutresgeo = cutgeo.intersection(shgeo)
if not cutresgeo.is_empty:
gcol = shapely.geometry.GeometryCollection([cutresgeo])
cutj = gcol.__geo_interface__
res.append(cutj)
return res