Commit 6b78d1c3 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

refactor, handling on shore category

parent acf24cb7
2017-12-14 13:00 18.3609 58.7568 0.0000
2017-12-14 13:15 18.3595 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.3273 58.7730 0.0000
2017-12-14 14:15 18.3063 58.7805 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.7994 0.0000
2017-12-14 15:15 18.2335 58.8036 0.0000
2017-12-14 15:30 18.2256 58.8064 0.0000
2017-12-14 15:45 18.2184 58.8093 0.0000
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.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: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
2017-12-14 19:30 18.2112 58.8274 0.0000
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.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
2017-12-14 21:30 18.2019 58.8370 0.0000
2017-12-14 21:45 18.1999 58.8376 0.0000
2017-12-14 22:00 18.1975 58.8384 0.0000
2017-12-14 22:15 18.1954 58.8392 0.0000
2017-12-14 22:30 18.1934 58.8397 0.0000
2017-12-14 22:45 18.1913 58.8404 0.0000
2017-12-14 23:00 18.1889 58.8409 0.0000
2017-12-14 23:15 18.1872 58.8416 0.0000
2017-12-14 23:30 18.1851 58.8424 0.0000
2017-12-14 23:45 18.1827 58.8431 0.0000
2017-12-15 00:00 18.1807 58.8436 0.0000
2017-12-15 00:15 18.1786 58.8441 0.0000
2017-12-15 00:30 18.1769 58.8448 0.0000
2017-12-15 00:45 18.1748 58.8456 0.0000
2017-12-15 01:00 18.1728 58.8461 0.0000
2017-12-15 01:15 18.1704 58.8470 0.0000
2017-12-15 01:30 18.1686 58.8477 0.0000
2017-12-15 01:45 18.1666 58.8482 0.0000
2017-12-15 02:00 18.1645 58.8489 0.0000
2017-12-15 02:15 18.1621 58.8495 0.0000
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.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
2017-12-15 04:15 18.1501 58.8566 0.0000
2017-12-15 04:30 18.1487 58.8574 0.0000
2017-12-15 04:45 18.1470 58.8583 0.0000
2017-12-15 05:00 18.1456 58.8592 0.0000
2017-12-15 05:15 18.1443 58.8601 0.0000
2017-12-15 05:30 18.1429 58.8610 0.0000
2017-12-15 05:45 18.1412 58.8617 0.0000
2017-12-15 06:00 18.1395 58.8624 0.0000
2017-12-15 06:15 18.1383 58.8628 0.0000
2017-12-15 06:30 18.1381 58.8630 0.0000
2017-12-15 06:45 18.1378 58.8633 0.0000
2017-12-15 07:00 18.1377 58.8636 0.0000
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.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
2017-12-15 09:00 18.1348 58.8652 0.0000
2017-12-15 09:15 18.1345 58.8654 0.0000
2017-12-15 09:30 18.1343 58.8656 0.0000
2017-12-15 09:45 18.1340 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.8662 0.0000
2017-12-15 10:45 18.1331 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:45 18.1326 58.8666 0.0000
2017-12-15 12:00 18.1326 58.8666 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
2017-12-15 13:00 18.1326 58.8667 0.0000
2017-12-14 13:15 18.3609 58.7568 0.0000
2017-12-14 13:30 18.3609 58.7568 0.0000
2017-12-14 13:45 18.3609 58.7568 0.0000
2017-12-14 14:00 18.3609 58.7568 0.0000
2017-12-14 14:15 18.3609 58.7568 0.0000
2017-12-14 14:30 18.3609 58.7568 0.0000
2017-12-14 14:45 18.3609 58.7568 0.0000
2017-12-14 15:00 18.3609 58.7568 0.0000
2017-12-14 15:15 18.3609 58.7568 0.0000
2017-12-14 15:30 18.3609 58.7568 0.0000
2017-12-14 15:45 18.3609 58.7568 0.0000
2017-12-14 16:00 18.3609 58.7568 0.0000
2017-12-14 16:15 18.3609 58.7568 0.0000
2017-12-14 16:30 18.3609 58.7568 0.0000
2017-12-14 16:45 18.3609 58.7568 0.0000
2017-12-14 17:00 18.3609 58.7568 0.0000
2017-12-14 17:15 18.3609 58.7568 0.0000
2017-12-14 17:30 18.3609 58.7568 0.0000
2017-12-14 17:45 18.3609 58.7568 0.0000
2017-12-14 18:00 18.3609 58.7568 0.0000
2017-12-14 18:15 18.3609 58.7568 0.0000
2017-12-14 18:30 18.3609 58.7568 0.0000
2017-12-14 18:45 18.3609 58.7568 0.0000
2017-12-14 19:00 18.3609 58.7568 0.0000
2017-12-14 19:15 18.3609 58.7568 0.0000
2017-12-14 19:30 18.3609 58.7568 0.0000
2017-12-14 19:45 18.3609 58.7568 0.0000
2017-12-14 20:00 18.3609 58.7568 0.0000
2017-12-14 20:15 18.3609 58.7568 0.0000
2017-12-14 20:30 18.3609 58.7568 0.0000
2017-12-14 20:45 18.3609 58.7568 0.0000
2017-12-14 21:00 18.3609 58.7568 0.0000
2017-12-14 21:15 18.3609 58.7568 0.0000
2017-12-14 21:30 18.3609 58.7568 0.0000
2017-12-14 21:45 18.3609 58.7568 0.0000
2017-12-14 22:00 18.3609 58.7568 0.0000
2017-12-14 22:15 18.3609 58.7568 0.0000
2017-12-14 22:30 18.3609 58.7568 0.0000
2017-12-14 22:45 18.3609 58.7568 0.0000
2017-12-14 23:00 18.3609 58.7568 0.0000
2017-12-14 23:15 18.3609 58.7568 0.0000
2017-12-14 23:30 18.3609 58.7568 0.0000
2017-12-14 23:45 18.3609 58.7568 0.0000
2017-12-15 00:00 18.3609 58.7568 0.0000
2017-12-15 00:15 18.3609 58.7568 0.0000
2017-12-15 00:30 18.3609 58.7568 0.0000
2017-12-15 00:45 18.3609 58.7568 0.0000
2017-12-15 01:00 18.3609 58.7568 0.0000
2017-12-15 01:15 18.3609 58.7568 0.0000
2017-12-15 01:30 18.3609 58.7568 0.0000
2017-12-15 01:45 18.3609 58.7568 0.0000
2017-12-15 02:00 18.3609 58.7568 0.0000
2017-12-15 02:15 18.3609 58.7568 0.0000
2017-12-15 02:30 18.3609 58.7568 0.0000
2017-12-15 02:45 18.3609 58.7568 0.0000
2017-12-15 03:00 18.3609 58.7568 0.0000
2017-12-15 03:15 18.3609 58.7568 0.0000
2017-12-15 03:30 18.3609 58.7568 0.0000
2017-12-15 03:45 18.3609 58.7568 0.0000
2017-12-15 04:00 18.3609 58.7568 0.0000
2017-12-15 04:15 18.3609 58.7568 0.0000
2017-12-15 04:30 18.3609 58.7568 0.0000
2017-12-15 04:45 18.3609 58.7568 0.0000
2017-12-15 05:00 18.3609 58.7568 0.0000
2017-12-15 05:15 18.3609 58.7568 0.0000
2017-12-15 05:30 18.3609 58.7568 0.0000
2017-12-15 05:45 18.3609 58.7568 0.0000
2017-12-15 06:00 18.3609 58.7568 0.0000
2017-12-15 06:15 18.3609 58.7568 0.0000
2017-12-15 06:30 18.3609 58.7568 0.0000
2017-12-15 06:45 18.3609 58.7568 0.0000
2017-12-15 07:00 18.3609 58.7568 0.0000
2017-12-15 07:15 18.3609 58.7568 0.0000
2017-12-15 07:30 18.3609 58.7568 0.0000
2017-12-15 07:45 18.3609 58.7568 0.0000
2017-12-15 08:00 18.3609 58.7568 0.0000
2017-12-15 08:15 18.3609 58.7568 0.0000
2017-12-15 08:30 18.3609 58.7568 0.0000
2017-12-15 08:45 18.3609 58.7568 0.0000
2017-12-15 09:00 18.3609 58.7568 0.0000
2017-12-15 09:15 18.3609 58.7568 0.0000
2017-12-15 09:30 18.3609 58.7568 0.0000
2017-12-15 09:45 18.3609 58.7568 0.0000
2017-12-15 10:00 18.3609 58.7568 0.0000
2017-12-15 10:15 18.3609 58.7568 0.0000
2017-12-15 10:30 18.3609 58.7568 0.0000
2017-12-15 10:45 18.3547 58.7598 0.0000
2017-12-15 11:00 18.3354 58.7690 0.0000
2017-12-15 11:15 18.2913 58.7901 0.0000
2017-12-15 11:30 18.2000 58.8339 0.0000
2017-12-15 11:45 18.1425 58.8614 0.0000
2017-12-15 12:00 18.1324 58.8662 0.0000
2017-12-15 12:15 18.1324 58.8662 0.0000
2017-12-15 12:30 18.1324 58.8662 0.0000
2017-12-15 12:45 18.1324 58.8662 0.0000
2017-12-15 13:00 18.1324 58.8662 0.0000
......@@ -140,9 +140,7 @@ class Model(object):
return featurecollection
def onlandPoints(self, beforepoints, nowpoints, matches):
active = []
deactive = []
def shorePoints(self, pointsdata, beforepoints, nowpoints, activeindex, matches):
for i in range(len(beforepoints)):
queryline = LineString([[beforepoints[i].y,beforepoints[i].x],[nowpoints[i][1],nowpoints[i][0]]])
intersection = None
......@@ -151,60 +149,16 @@ class Model(object):
if match.intersects(queryline):
intersection = match.intersection(queryline)
if (intersection is not None):
pointsdata[activeindex[i]][1] = 7 # on shore category
if (intersection.geom_type is 'Point'):
deactive.append([intersection.y,intersection.x])
pointsdata[activeindex[i]][0] = [intersection.y,intersection.x]
# deactive.append([intersection.y,intersection.x])
if (intersection.geom_type is 'MultiPoint'):
deactive.append([intersection.geoms[0].y,intersection.geoms[0].x])
else:
active.append(nowpoints[i])
intersectionend = time.time()
return active, deactive
pointsdata[activeindex[i]][0] = [intersection.geoms[0].y,intersection.geoms[0].x]
# deactive.append([intersection.geoms[0].y,intersection.geoms[0].x])
def onlandPoints2(self, beforepoints, nowpoints, matches):
active = []
deactive = []
multilines = []
intersectionstart = time.time()
for i in range(len(beforepoints)):
multilines.append(LineString([[beforepoints[i].y,beforepoints[i].x],[nowpoints[i][1],nowpoints[i][0]]]))
intercepts = [match.intersection(MultiLineString(multilines)) for match in matches]
# if (len(matches) == 3):
# print(len(matches[2].coords))
# print(matches[2].intersection(query))
# intercepts = [match.intersection(query) for match in matches]
# if (len(intercepts)):
# print(intercepts)
# for i in range(len(multilines)):
# intercepts = [multilines[i] for match in matches if match.intersects(multilines[i])]
# if (len(intercepts)):
# print(intercepts)
active = list(nowpoints)
# if (len(matches) > 0):
# print(len(matches))
# for i in range(len(multilines)):
# intersection = None
# for match in matches:
# intersection = match.intersection(multilines[i])
# if (not intersection.is_empty):
# break
# # if match.intersects(multilines[i]):
# print(intersection)
# if (intersection.is_empty):
# active.append(nowpoints[i])
# else:
# deactive.append([intersection.y,intersection.x])
intersectionend = time.time()
print('intersection: '+str(intersectionend-intersectionstart))
return pointsdata
return active, deactive
def calculateRadius(self, pDist, points):
radius = [pDist] * len(points)
......@@ -214,8 +168,6 @@ class Model(object):
return radius
def displacePoints(self, pDist, points):
p = 0
......@@ -275,6 +227,21 @@ class Model(object):
properties['level'] = level
return properties
def updatepointarrays(self, pointsdata):
activepoints = []
deactivepoints = []
activeindex = []
allpoints = []
category = []
for i,pointdata in enumerate(pointsdata):
allpoints.append(pointdata[0])
category.append(pointdata[1])
if (category[i] is 2): # active
activepoints.append(pointdata[0])
activeindex.append(i)
else: # not active
deactivepoints.append(pointdata[0])
return allpoints, activepoints, activeindex, deactivepoints, category
def createOutput(self, starttime, pDist, multipoint, exercisefeature, strtree):
......@@ -284,23 +251,22 @@ class Model(object):
properties = self.createProperties(1, starttime, multipoint.centroid, [0] * len(multipoint.geoms), [2] * len(multipoint.geoms))
features.append(self.createFeature(multipoint, properties))
activepoints = []
deactivepoints = []
for point in multipoint.geoms:
activepoints.append([point.x, point.y])
pointsdata = ()
for i,point in enumerate(multipoint.geoms):
pointsdata += ([[point.x, point.y], 2],) # default category 2 = active in water
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))
for i, coord in enumerate(linestring.coords):
if (len(activepoints) > 0):
mp = geometry.MultiPoint(activepoints)
points = self.centerPoints(coord, mp.centroid, mp.geoms)
displacedpoints = self.displacePoints(pDist, points)
activepoints, onlandpoints = self.onlandPoints(mp.geoms, displacedpoints, matches)
deactivepoints += onlandpoints
mp = geometry.MultiPoint(activepoints+deactivepoints)
centeredpoints = self.centerPoints(coord, mp.centroid, mp.geoms)
displacedpoints = self.displacePoints(pDist, centeredpoints)
pointsdata = self.shorePoints(pointsdata, mp.geoms, displacedpoints, activeindex, matches)
allpoints, activepoints, activeindex, deactivepoints, category = self.updatepointarrays(pointsdata)
mp = geometry.MultiPoint(allpoints)
level = [0] * len(mp.geoms)
category = [2] * len(mp.geoms)
properties = self.createProperties((i+2), timearray[i], mp.centroid, level, category)
features.append(self.createFeature(mp, properties))
if (i % 10 == 0):
......
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"simulation":{"forwardCalculation":true,"startDate":1513256400000,"stopDate":1513342800000,"oilclass":"Oil classes","substance":"Medium oils (100-1000 cSt)","fresh":true,"amount":"10","amountUnit":"m3","uncertainty":false,"mode":"Normal"},"primary":"PADM","type":"exercise","subtype":"instant","meanLat":58.75680543225761,"meanLng":18.360900878906254,"observation":[{"id":null,"provider":"USER","providerDataRef":null,"providerImgRef":null,"providerType":null,"type":"MANUAL","date":1513256400000}],"domain":"HELCOM","model":"NEMO"},"geometry":{"type":"Point","coordinates":[18.360900878906254,58.75680543225761]}},{"type":"Feature","properties":{"auxiliary":"exercise","time":[1513257300000,1513258200000,1513259100000,1513260000000,1513260900000,1513261800000,1513262700000,1513263600000,1513264500000,1513265400000,1513266300000,1513267200000,1513268100000,1513269000000,1513269900000,1513270800000,1513271700000,1513272600000,1513273500000,1513274400000,1513275300000,1513276200000,1513277100000,1513278000000,1513278900000,1513279800000,1513280700000,1513281600000,1513282500000,1513283400000,1513284300000,1513285200000,1513286100000,1513287000000,1513287900000,1513288800000,1513289700000,1513290600000,1513291500000,1513292400000,1513293300000,1513294200000,1513295100000,1513296000000,1513296900000,1513297800000,1513298700000,1513299600000,1513300500000,1513301400000,1513302300000,1513303200000,1513304100000,1513305000000,1513305900000,1513306800000,1513307700000,1513308600000,1513309500000,1513310400000,1513311300000,1513312200000,1513313100000,1513314000000,1513314900000,1513315800000,1513316700000,1513317600000,1513318500000,1513319400000,1513320300000,1513321200000,1513322100000,1513323000000,1513323900000,1513324800000,1513325700000,1513326600000,1513327500000,1513328400000,1513329300000,1513330200000,1513331100000,1513332000000,1513332900000,1513333800000,1513334700000,1513335600000,1513336500000,1513337400000,1513338300000,1513339200000,1513340100000,1513341000000,1513341900000,1513342800000]},"geometry":{"type":"LineString","coordinates":[[18.35952758789063,58.758229977465014],[18.352317810058597,58.76196913085653],[18.344078063964847,58.766063932525924],[18.32725524902344,58.773006189137675],[18.30631256103516,58.780480914164364],[18.28330993652344,58.787954030623865],[18.264770507812504,58.79364675410282],[18.24760437011719,58.79933854403445],[18.233528137207035,58.80360677390105],[18.22563171386719,58.80645196879573],[18.21842193603516,58.809296930358116],[18.21567535400391,58.810719323643475],[18.213615417480472,58.81178608032933],[18.210525512695316,58.81320837154076],[18.20915222167969,58.814097273929185],[18.207092285156254,58.81516392672157],[18.205375671386722,58.8160527789875],[18.206748962402347,58.81694160847107],[18.20915222167969,58.817652655654896],[18.21018218994141,58.81871919909263],[18.21018218994141,58.82085218755376],[18.21018218994141,58.82245184278951],[18.210525512695316,58.823518238609786],[18.210868835449222,58.82458460162793],[18.21121215820313,58.82600636796106],[18.21121215820313,58.82742807598191],[18.21121215820313,58.829027427805926],[18.210868835449222,58.830271317092986],[18.210525512695316,58.83133747237921],[18.20915222167969,58.83275896174271],[18.208122253417972,58.83400271710735],[18.206062316894535,58.83506875760534],[18.204345703125004,58.83613476530816],[18.20194244384766,58.83702308000908],[18.199882507324222,58.83755605789824],[18.19747924804688,58.83844433616154],[18.19541931152344,58.83915494237557],[18.193359375000004,58.839687887471506],[18.191299438476566,58.8403984681802],[18.188896179199222,58.84093139414738],[18.18717956542969,58.841641949351306],[18.185119628906254,58.84235248998134],[18.18271636962891,58.84306301603768],[18.180656433105472,58.84359590101607],[18.178596496582035,58.844128777796925],[18.176879882812504,58.84483926741984],[18.174819946289066,58.84554974246974],[18.17276000976563,58.84608258919371],[18.170356750488285,58.846970648851176],[18.168640136718754,58.84768108018313],[18.166580200195316,58.84821389411899],[18.16452026367188,58.84892429994956],[18.162117004394535,58.849457094759636],[18.160057067871097,58.85016747508943],[18.15799713134766,58.850522659789966],[18.156623840332035,58.851410605603746],[18.15525054931641,58.8522985286499],[18.154563903808597,58.853364006252534],[18.153190612792972,58.854429451070985],[18.151817321777347,58.85567242859108],[18.150100708007816,58.856560242357794],[18.14872741699219,58.85744803335905],[18.14701080322266,58.8583358015952],[18.145637512207035,58.859223547066584],[18.14426422119141,58.86011126977364],[18.142890930175785,58.860998969716675],[18.141174316406254,58.8617091132813],[18.139457702636722,58.862419242277376],[18.138341903686527,58.86277430131227],[18.138084411621097,58.86304059319835],[18.137826919555668,58.86330688303576],[18.137655258178714,58.863573170824544],[18.13748359680176,58.863839456564726],[18.13731193542481,58.864105740256264],[18.136968612670902,58.86432764176763],[18.136625289916996,58.86454954185634],[18.13628196716309,58.86477144052246],[18.13576698303223,58.86490457903925],[18.13525199890137,58.86503771704389],[18.134822845458988,58.86521523358677],[18.134608268737797,58.86534837039643],[18.134436607360843,58.86545931734657],[18.134222030639652,58.865548074650626],[18.133964538574222,58.86563683172708],[18.133707046508793,58.86570339938503],[18.1334924697876,58.86579215606313],[18.13323497772217,58.86588091251365],[18.132977485656742,58.86594747970213],[18.132677078247074,58.866014046762594],[18.132376670837406,58.86610280264405],[18.132076263427738,58.866191558297885],[18.13181877136231,58.86628031372411],[18.13156127929688,58.86632469135188],[18.13130378723145,58.866413446436695],[18.131089210510257,58.86652438997262],[18.130917549133304,58.86663533315288]]}}]}
\ No newline at end of file
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