-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfullmap.py
146 lines (120 loc) · 4.22 KB
/
fullmap.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
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
144
145
146
# General Map outputs module
from owslib.wms import WebMapService
from owslib import crs
from pyproj import Proj, transform
from location_finder import getmap
import cv2
import csv
import sys
import matplotlib as plt
import numpy as np
from skimage import io
import colorsys
from tweet_filter import distance_calculator
def color_palette(N):
HSV_tuples = [(x * 1.0 / N, 0.5, 0.5) for x in range(N)]
RGB_tuples = map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples)
return list(RGB_tuples), HSV_tuples
def location_is_near(row, location_list):
# location_dict = getmap()
for coordinate in location_list:
try:
is_near = distance_calculator(coordinate[1], coordinate[0], float(row[2]), float(row[3])) < 200
except:
raise Exception('Problem')
return is_near
def draw_fields_detected():
c = crs.Crs('EPSG:3857')
#wms = WebMapService('http://www.ign.es/wms-inspire/pnoa-ma', version='1.3.0')
box = 10000 # m?
x=238814#m?
y=5069880 #m?
picsize = 2048
"""
img = wms.getmap(
layers=['OI.OrthoimageCoverage'],
styles=[],
srs='EPSG:3857',
bbox=(x - box, y - box, x + box, y + box),
size=(picsize,picsize), #W,H px
format='image/png',
transparent=False
)
with open('fullmap.png','wb') as out:
out.write(img.read())
"""
img1 = cv2.imread('fullmap.png')
circles = img1.copy()
xydict = getmap()
for element in xydict.values():
for value in element:
lon = value[0]
lat = value[1]
try:
proj = Proj(init='epsg:3857')
xm, ym = proj(lon, lat)
p1 = picsize / (2 * box) * (xm - (x - box))
p2 = picsize / (2 * box) * ((y + box) - ym)
cv2.circle(img1, (int(p1), int(p2)), 5, (0, 0, 255), -1)
plt.imshow()
except Exception as e:
print(e)
cv2.imwrite('circle.png', circles)
def draw_tweets_detected(file):
# Tweet info draw
c = crs.Crs('EPSG:3857')
# wms = WebMapService('http://www.ign.es/wms-inspire/pnoa-ma', version='1.3.0')
box = 10000 # m?
x = 238814 # m?
y = 5069880 # m?
picsize = 2048
img1 = cv2.imread('fullmap.png')
img_fields = cv2.imread('circle.png')
overlay = img1.copy()
tweets = img1.copy()
final = img_fields.copy()
with open(file, 'r') as csv_file:
with open('locations.csv', 'r') as csv_locations:
loc_reader = csv.reader(csv_locations)
location_list = list(loc_reader)
print(location_list)
reader = csv.reader(csv_file,)
reader.__next__()
lat = []
lon = []
for row in reader:
# print(format(row).encode())
if location_is_near(row, location_list):
lat.append(row[2])
lon.append(row[3])
print('Csv finished')
n_tweets = len(lat)
alpha = 2/n_tweets
colors, _ = color_palette(n_tweets)
for i in range(len(lat[:n_tweets])):
try:
# print('Writing...{}'.format(i))
proj = Proj(init='epsg:3857')
xm, ym = proj(lon[i], lat[i])
p1 = picsize / (2 * box) * (xm - (x - box))
p2 = picsize / (2 * box) * ((y + box) - ym)
# cv2.circle(overlay, (int(p1), int(p2)), 5, (int(colors[i][2] * 255), int(colors[i][1] * 255), int(colors[i][0] * 255)), -1)
# cv2.circle(tweets, (int(p1), int(p2)), 5, (int(colors[i][2] * 255), int(colors[i][1] * 255), int(colors[i][0] * 255)), -1)
cv2.circle(tweets, (int(p1), int(p2)), 5,
(0, 200, 255), -1)
cv2.circle(final, (int(p1), int(p2)), 5,
(0, 200, 255), -1)
# cv2.addWeighted(overlay, alpha,
# tweets, 1 - alpha,
# 0, tweets)
except Exception as e:
print(e)
cv2.imshow("Output", tweets)
cv2.imwrite('tweets.png', tweets)
cv2.imwrite('tweetsNfields.png', final)
def main(args):
# draw_fields_detected()
draw_tweets_detected(args[1])
if __name__ == '__main__':
# print(sys.argv)
main(sys.argv)