Commit 34920a71 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

reactor + buffer on trajectory to increase nr of matches in strtree queries

parent 3ad79526
2017-12-14 13:00 18.3609 58.7568 0.0000
2017-12-14 13:15 18.3595 58.7583 0.0000
2017-12-14 13:15 18.3596 58.7582 0.0000
2017-12-14 13:30 18.3523 58.7620 0.0000
2017-12-14 13:45 18.3441 58.7661 0.0000
2017-12-14 14:00 18.3272 58.7730 0.0000
2017-12-14 14:00 18.3273 58.7730 0.0000
2017-12-14 14:15 18.3063 58.7805 0.0000
2017-12-14 14:30 18.2833 58.7879 0.0000
2017-12-14 14:30 18.2833 58.7880 0.0000
2017-12-14 14:45 18.2648 58.7937 0.0000
2017-12-14 15:00 18.2476 58.7993 0.0000
2017-12-14 15:15 18.2335 58.8036 0.0000
......@@ -13,14 +13,14 @@
2017-12-14 16:00 18.2157 58.8107 0.0000
2017-12-14 16:15 18.2136 58.8118 0.0000
2017-12-14 16:30 18.2105 58.8132 0.0000
2017-12-14 16:45 18.2091 58.8141 0.0000
2017-12-14 16:45 18.2092 58.8141 0.0000
2017-12-14 17:00 18.2071 58.8152 0.0000
2017-12-14 17:15 18.2054 58.8161 0.0000
2017-12-14 17:30 18.2067 58.8169 0.0000
2017-12-14 17:45 18.2091 58.8177 0.0000
2017-12-14 18:00 18.2102 58.8187 0.0000
2017-12-14 18:15 18.2102 58.8209 0.0000
2017-12-14 18:30 18.2102 58.8225 0.0000
2017-12-14 18:30 18.2102 58.8224 0.0000
2017-12-14 18:45 18.2105 58.8235 0.0000
2017-12-14 19:00 18.2109 58.8246 0.0000
2017-12-14 19:15 18.2112 58.8260 0.0000
......@@ -28,7 +28,7 @@
2017-12-14 19:45 18.2112 58.8290 0.0000
2017-12-14 20:00 18.2109 58.8303 0.0000
2017-12-14 20:15 18.2105 58.8313 0.0000
2017-12-14 20:30 18.2092 58.8328 0.0000
2017-12-14 20:30 18.2091 58.8328 0.0000
2017-12-14 20:45 18.2081 58.8340 0.0000
2017-12-14 21:00 18.2061 58.8351 0.0000
2017-12-14 21:15 18.2043 58.8361 0.0000
......@@ -55,7 +55,7 @@
2017-12-15 02:30 18.1601 58.8502 0.0000
2017-12-15 02:45 18.1580 58.8505 0.0000
2017-12-15 03:00 18.1566 58.8514 0.0000
2017-12-15 03:15 18.1552 58.8523 0.0000
2017-12-15 03:15 18.1553 58.8523 0.0000
2017-12-15 03:30 18.1546 58.8534 0.0000
2017-12-15 03:45 18.1532 58.8544 0.0000
2017-12-15 04:00 18.1518 58.8557 0.0000
......@@ -74,7 +74,7 @@
2017-12-15 07:15 18.1375 58.8638 0.0000
2017-12-15 07:30 18.1373 58.8641 0.0000
2017-12-15 07:45 18.1370 58.8643 0.0000
2017-12-15 08:00 18.1366 58.8645 0.0000
2017-12-15 08:00 18.1366 58.8646 0.0000
2017-12-15 08:15 18.1363 58.8648 0.0000
2017-12-15 08:30 18.1358 58.8649 0.0000
2017-12-15 08:45 18.1353 58.8650 0.0000
......@@ -84,13 +84,13 @@
2017-12-15 09:45 18.1341 58.8657 0.0000
2017-12-15 10:00 18.1338 58.8659 0.0000
2017-12-15 10:15 18.1335 58.8660 0.0000
2017-12-15 10:30 18.1333 58.8661 0.0000
2017-12-15 10:45 18.1331 58.8663 0.0000
2017-12-15 10:30 18.1333 58.8662 0.0000
2017-12-15 10:45 18.1332 58.8663 0.0000
2017-12-15 11:00 18.1330 58.8664 0.0000
2017-12-15 11:15 18.1328 58.8665 0.0000
2017-12-15 11:30 18.1327 58.8666 0.0000
2017-12-15 11:30 18.1328 58.8666 0.0000
2017-12-15 11:45 18.1327 58.8666 0.0000
2017-12-15 12:00 18.1326 58.8667 0.0000
2017-12-15 12:00 18.1327 58.8667 0.0000
2017-12-15 12:15 18.1326 58.8667 0.0000
2017-12-15 12:30 18.1326 58.8667 0.0000
2017-12-15 12:45 18.1326 58.8667 0.0000
......
......@@ -16,60 +16,63 @@ from shapely import geometry
from shapely.geometry import LineString
from shapely.strtree import STRtree
def storetree():
def storetree(switch='json'):
try:
with open('../coastline_HELCOM_82214.dat',"r") as coastlinefile:
lines = coastlinefile.readlines()
section = []
sections = []
jsonsections = []
for i, line in enumerate(lines):
if len(section) == 100:
sections.append(LineString(section))
jsonsections.append(section)
sections.append(section)
section = []
if '-999999' in line:
if len(section) == 1: #create a line from previous section on ending point
split = lines[i-1].split(' ')
section.append([float(split[2]),float(split[1])])
if len(section) > 0:
sections.append(LineString(section))
jsonsections.append(section)
sections.append(section)
section = []
continue
split = line.split(' ')
section.append([float(split[2]),float(split[1])])
print('Number of lines: '+str(len(sections)))
# with open('resources/strtree.pickle', 'wb') as dumphandle:
# print('HIGHEST_PROTOCOL :'+str(pickle.HIGHEST_PROTOCOL))
# pickle.dump(sections, dumphandle, protocol=pickle.HIGHEST_PROTOCOL)
with codecs.open('resources/strtree.json', 'w', 'utf8') as jsonhandle:
jsonhandle.write(json.dumps(jsonsections, sort_keys = True, ensure_ascii=False))
if (switch is 'pickle'):
with open('resources/strtree.pickle', 'wb') as picklehandle:
print('HIGHEST_PROTOCOL :'+str(pickle.HIGHEST_PROTOCOL))
pickle.dump(sections, picklehandle, protocol=pickle.HIGHEST_PROTOCOL)
if (switch is 'json'):
with codecs.open('resources/strtree.json', 'w', 'utf8') as jsonhandle:
jsonhandle.write(json.dumps(sections, sort_keys = True, ensure_ascii=False))
except Exception as error:
print_exc()
sys.exit(1)
def loadtree():
def loadtree(switch='json'):
try:
# with open('resources/strtree.pickle', 'rb') as picklehandle:
# # tree = STRtree(pickle.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.pickle')))))
# tree = STRtree(pickle.load(picklehandle))
# queryline = LineString([[57.5,17.5],[57.5,18.5]])
# matches = tree.query(queryline);
# print('Number of pickle matches: '+str(len(matches)))
with open('resources/strtree.json', 'r') as jsonhandle:
#jsondata = json.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.json'))));
jsondata = json.load(jsonhandle);
sections = []
for section in jsondata:
sections.append(LineString(section))
tree = STRtree(sections)
queryline = LineString([[57.5,17.5],[57.5,18.5]])
matches = tree.query(queryline);
print('Number of json matches: '+str(len(matches)))
if (switch is 'pickle'):
with open('resources/strtree.pickle', 'rb') as picklehandle:
data = pickle.load(picklehandle);
sections = []
for section in data:
sections.append(LineString(section))
tree = STRtree(sections)
queryline = LineString([[57.5,17.5],[57.5,18.5]])
matches = tree.query(queryline);
print('Number of pickle matches: '+str(len(matches)))
if (switch is 'json'):
with open('resources/strtree.json', 'r') as jsonhandle:
data = json.load(jsonhandle);
sections = []
for section in data:
sections.append(LineString(section))
tree = STRtree(sections)
queryline = LineString([[57.5,17.5],[57.5,18.5]])
matches = tree.query(queryline);
print('Number of json matches: '+str(len(matches)))
except Exception as error:
print_exc()
......@@ -106,9 +109,11 @@ def writeStatus(status):
def run():
try:
writeStatus("INITIAL")
jsondata = json.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.json'))));
coastlinedata = json.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.json'))))
# coastlinedata = pickle.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.pickle'))))
sections = []
for section in jsondata:
for section in coastlinedata:
sections.append(LineString(section))
strtree = STRtree(sections)
......@@ -147,6 +152,7 @@ def run():
To run in terminal call with python __init__.py
'''
if __name__ == "__main__":
storetree()
loadtree()
switch = 'json'
storetree(switch)
loadtree(switch)
\ No newline at end of file
......@@ -250,7 +250,9 @@ class Model(object):
allpoints, activepoints, activeindex, deactivepoints, category = self.updatepointarrays(pointsdata)
linestring = geometry.shape(exercisefeature['geometry'])
latlngpoints = [[latlng[1], latlng[0]] for latlng in linestring.coords]
matches = strtree.query(LineString(latlngpoints))
# matches = strtree.query(LineString(latlngpoints))
matches = strtree.query(LineString(latlngpoints).buffer(0.025))
print(len(matches))
for i, coord in enumerate(linestring.coords):
if (len(activepoints) > 0):
mp = geometry.MultiPoint(activepoints)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment