WMTSTest.py
6.7 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# coding=utf-8
#author: 4N
#createtime: 2021/8/18
#email: nheweijun@sina.com
import random
from .SliceScheme import SliceScheme
import random
from osgeo.ogr import *
from osgeo import ogr
def create(slice_para,extent,level,output,check_shp=None):
file = open(output, 'w')
lxy_extent={}
for l in range(level[0],level[1]+1):
row = 0
col = 0
minx, miny, maxx, maxy = SliceScheme.get_polygon(slice_para, l, row, col)
min_row = 0
while miny > extent[3]:
row += 1
minx, miny, maxx, maxy = SliceScheme.get_polygon(slice_para,l, row, col)
min_row = row
max_row = min_row
while maxy >extent[1]:
max_row = row
row += 1
minx, miny, maxx, maxy = SliceScheme.get_polygon(slice_para,l, row, col)
min_col=0
while maxx < extent[0]:
min_col = col
col += 1
minx, miny, maxx, maxy = SliceScheme.get_polygon(slice_para,l, row, col)
max_col=min_col
while minx < extent[2]:
max_col = col
col += 1
minx, miny, maxx, maxy = SliceScheme.get_polygon(slice_para,l, row, col)
lxy_extent[l]=[min_row,max_row,min_col,max_col]
print(lxy_extent)
count = 0
while count<10000:
l = random.choice(range(level[0],level[1]+1))
y = random.choice(range(lxy_extent[l][0],lxy_extent[l][1]+1))
x = random.choice(range(lxy_extent[l][2], lxy_extent[l][3] + 1))
minx, miny, maxx, maxy = SliceScheme.get_polygon(slice_para, l,y, x)
if check_shp:
driver: Driver = ogr.GetDriverByName("ESRI Shapefile")
ds: DataSource = driver.Open(check_shp, 1)
if not ds:
raise Exception("打开数据失败!")
layer: Layer = ds.GetLayer(0)
feature:Feature = layer.GetFeature(0)
geo:Geometry = feature.GetGeometryRef()
ring = ogr.Geometry(ogr.wkbLinearRing)
ring.AddPoint(minx, miny)
ring.AddPoint(minx, maxy)
ring.AddPoint(maxx, maxy)
ring.AddPoint(maxx, miny)
ring.AddPoint(minx, miny)
# Create polygon
poly = ogr.Geometry(ogr.wkbPolygon)
poly.AddGeometry(ring)
if geo.Intersect(poly):
file.write("{},{},{}\n".format(l, y, x))
count+=1
else:
file.write("{},{},{}\n".format(l,y,x))
count += 1
if __name__ == '__main__':
slice_para = {'rows': 256.0, 'cols': 256.0, 'x': -180.0, 'y': 90.0, 'dpi': 96.0,
'0': {'scale': 295497593.05875003, 'resolution': 0.7031250000000002},
'1': {'scale': 147748796.52937502, 'resolution': 0.3515625000000001},
'2': {'scale': 73874398.26468751, 'resolution': 0.17578125000000006},
'3': {'scale': 36937199.132343754, 'resolution': 0.08789062500000003},
'4': {'scale': 18468599.566171877, 'resolution': 0.043945312500000014},
'5': {'scale': 9234299.783085939, 'resolution': 0.021972656250000007},
'6': {'scale': 4617149.891542969, 'resolution': 0.010986328125000003},
'7': {'scale': 2308574.9457714846, 'resolution': 0.005493164062500002},
'8': {'scale': 1154287.4728857423, 'resolution': 0.002746582031250001},
'9': {'scale': 577143.7364428712, 'resolution': 0.0013732910156250004},
'10': {'scale': 288571.8682214356, 'resolution': 0.0006866455078125002},
'11': {'scale': 144285.9341107178, 'resolution': 0.0003433227539062501},
'12': {'scale': 72142.9670553589, 'resolution': 0.00017166137695312505},
'13': {'scale': 36071.48352767945, 'resolution': 8.583068847656253e-05},
'14': {'scale': 18035.741763839724, 'resolution': 4.2915344238281264e-05},
'15': {'scale': 9017.870881919862, 'resolution': 2.1457672119140632e-05},
'16': {'scale': 4508.935440959931, 'resolution': 1.0728836059570316e-05},
'17': {'scale': 2254.4677204799655, 'resolution': 5.364418029785158e-06},
'18': {'scale': 1127.2338602399827, 'resolution': 2.682209014892579e-06},
'19': {'scale': 563.6169301199914, 'resolution': 1.3411045074462895e-06}}
# slice_para = {'rows': 256.0, 'cols': 256.0, 'x': -400.0, 'y': 400.0, 'dpi': 96.0,
# '0': {'scale': 590995186.11750006, 'resolution': 1.4062500000000004},
# '1': {'scale': 295497593.05875003, 'resolution': 0.7031250000000002},
# '2': {'scale': 147748796.52937502, 'resolution': 0.3515625000000001},
# '3': {'scale': 73874398.26468751, 'resolution': 0.17578125000000006},
# '4': {'scale': 36937199.132343754, 'resolution': 0.08789062500000003},
# '5': {'scale': 18468599.566171877, 'resolution': 0.043945312500000014},
# '6': {'scale': 9234299.783085939, 'resolution': 0.021972656250000007},
# '7': {'scale': 4617149.891542969, 'resolution': 0.010986328125000003},
# '8': {'scale': 2308574.9457714846, 'resolution': 0.005493164062500002},
# '9': {'scale': 1154287.4728857423, 'resolution': 0.002746582031250001},
# '10': {'scale': 577143.7364428712, 'resolution': 0.0013732910156250004},
# '11': {'scale': 288571.8682214356, 'resolution': 0.0006866455078125002},
# '12': {'scale': 144285.9341107178, 'resolution': 0.0003433227539062501},
# '13': {'scale': 72142.9670553589, 'resolution': 0.00017166137695312505},
# '14': {'scale': 36071.48352767945, 'resolution': 8.583068847656253e-05},
# '15': {'scale': 18035.741763839724, 'resolution': 4.2915344238281264e-05},
# '16': {'scale': 9017.870881919862, 'resolution': 2.1457672119140632e-05},
# '17': {'scale': 4508.935440959931, 'resolution': 1.0728836059570316e-05},
# '18': {'scale': 2254.4677204799655, 'resolution': 5.364418029785158e-06},
# '19': {'scale': 1127.2338602399827, 'resolution': 2.682209014892579e-06},
# '20': {'scale': 563.6169301199914, 'resolution': 1.3411045074462895e-06}}
# level = [8,15]
# extent = [112, 22.7, 115, 24.03]
level = [12, 17]
extent = [111.644, 28.989, 111.7, 29.027]
output = "wmts.bat"
create(slice_para,extent,level,output)