-
Notifications
You must be signed in to change notification settings - Fork 1
/
location_finder.py
73 lines (59 loc) · 1.97 KB
/
location_finder.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from owslib.wms import WebMapService
from owslib import crs
from pyspark import SparkContext
from image_processing import *
import csv
c = crs.Crs('EPSG:3857')
wms = WebMapService('http://www.ign.es/wms-inspire/pnoa-ma', version='1.3.0')
def parallel_processing(xy,box,picsize):
img = wms.getmap(
layers=['OI.OrthoimageCoverage'],
styles=[],
srs='EPSG:3857',
bbox=(xy[0] - box, xy[1] - box, xy[0] + box, xy[1] + box),
size=(picsize,picsize), #W,H px
format='image/png',
transparent=False
)
with open('Images/image{0}{1}.png'.format(xy[0],xy[1]),'wb') as out:
out.write(img.read())
green_detection(xy)
c=contour_detection(xy)
locations=location_convertor(c,xy,box,picsize)
return locations
def getmap():
sc = SparkContext()
box = 1000 # m?
x=241314#m?
y=5066180 #m?
picsize = 512
xylist=[]
d=[]
xydict={}
location_list=[]
for i in range(-12,12):
for j in range(-12,12):
xylist.append([x+(i*(box-100)),y+(j*(box-100))])
xylist = sc.parallelize(xylist)\
.map(lambda x: [x,parallel_processing(x,box,picsize)])\
.collect()
sc.stop()
# remove localization exact duplicates
[d.append(item) for item in xylist if item not in d]
with open('locations.csv',"w") as f:
for element in d:
if (element[1] != []):
for i in range(len(element[1])):
csv_row=[]
csv_row.append(str(element[0][0])+str(element[0][1]))
csv_row.append(element[1][i][0])
csv_row.append(element[1][i][1])
xydict[str(element[0][0])+str(element[0][1])]=element[1]
writer = csv.writer(f, lineterminator='\n')
writer.writerow(csv_row)
f.close()
return xydict
if __name__ == "__main__":
xydict=getmap()
for element in xydict.items():
print(element)