Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
exercisemodel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
stw
wt
exercisemodel
Commits
dc0115f0
Commit
dc0115f0
authored
Dec 14, 2017
by
Tomas Pettersson
🏸
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
activated onland again now reading json instead of pickle
parent
558bcf75
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
32 deletions
+67
-32
cloudtrack.dat
cloudtrack.dat
+11
-11
exercisemodel/__init__.py
exercisemodel/__init__.py
+45
-10
exercisemodel/model.py
exercisemodel/model.py
+10
-11
exercisemodel/resources/strtree.json
exercisemodel/resources/strtree.json
+1
-0
exercisemodel/resources/strtree.pickle
exercisemodel/resources/strtree.pickle
+0
-0
No files found.
cloudtrack.dat
View file @
dc0115f0
2017-12-13 08:00 27.0119 60.0031 0.0000
2017-12-13 08:15 27.0113 60.0034 0.0000
2017-12-13 08:30 27.010
3 60.0036
0.0000
2017-12-13 08:45 27.0094 60.00
39
0.0000
2017-12-13 09:00 27.008
3
60.0043 0.0000
2017-12-13 08:30 27.010
2 60.0037
0.0000
2017-12-13 08:45 27.0094 60.00
40
0.0000
2017-12-13 09:00 27.008
4
60.0043 0.0000
2017-12-13 09:15 27.0075 60.0046 0.0000
2017-12-13 09:30 27.006
5
60.0052 0.0000
2017-12-13 09:30 27.006
4
60.0052 0.0000
2017-12-13 09:45 27.0059 60.0057 0.0000
2017-12-13 10:00 27.005
2
60.0061 0.0000
2017-12-13 10:00 27.005
3
60.0061 0.0000
2017-12-13 10:15 27.0047 60.0066 0.0000
2017-12-13 10:30 27.004
1
60.0072 0.0000
2017-12-13 10:30 27.004
0
60.0072 0.0000
2017-12-13 10:45 27.0034 60.0077 0.0000
2017-12-13 11:00 27.0028 60.0082 0.0000
2017-12-13 11:15 27.0025 60.0088 0.0000
2017-12-13 11:30 27.0022 60.0093 0.0000
2017-12-13 11:45 27.
5613 59.4504
0.0000
2017-12-13 12:00 32.
4847 54.5275
0.0000
2017-12-13 12:15 40.
9888 46.0239
0.0000
2017-12-13 12:30 50.
3883 36.6248
0.0000
2017-12-13 12:45 58.
3332 28.6800
0.0000
2017-12-13 11:45 27.
6732 59.3385
0.0000
2017-12-13 12:00 32.
3728 54.6394
0.0000
2017-12-13 12:15 40.
2055 46.8072
0.0000
2017-12-13 12:30 50.
2764 36.7366
0.0000
2017-12-13 12:45 58.
5570 28.4562
0.0000
2017-12-13 13:00 60.0117 27.0015 0.0000
2017-12-13 13:15 60.0117 27.0015 0.0000
2017-12-13 13:30 60.0117 27.0015 0.0000
...
...
exercisemodel/__init__.py
View file @
dc0115f0
...
...
@@ -4,6 +4,7 @@
import
os
import
sys
import
json
import
codecs
import
pickle
import
pkg_resources
from
traceback
import
print_exc
...
...
@@ -21,31 +22,58 @@ def storetree():
lines
=
coastlinefile
.
readlines
()
section
=
[]
sections
=
[]
jsonsections
=
[]
for
line
in
lines
:
# if len(section) == 1000:
# sections.append(LineString(section))
# section = []
if
len
(
section
)
==
10
:
sections
.
append
(
LineString
(
section
))
jsonsections
.
append
(
section
)
section
=
[]
if
'-999999'
in
line
:
if
len
(
section
)
>
0
:
#this will skip some points where section will end with only one coord. Possibly create a line from previous section on ending point
if
len
(
section
)
>
1
:
#this will skip some points where section will end with only one coord. Possibly create a line from previous section on ending point
sections
.
append
(
LineString
(
section
))
jsonsections
.
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
handle
:
pickle
.
dump
(
sections
,
handle
,
protocol
=
pickle
.
HIGHEST_PROTOCOL
)
# verify
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
))
except
Exception
as
error
:
print_exc
()
sys
.
exit
(
1
)
def
loadtree
():
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 matches: '
+
str
(
len
(
matches
)))
print
(
'Number of
json
matches: '
+
str
(
len
(
matches
)))
except
Exception
as
error
:
print_exc
()
sys
.
exit
(
1
)
# # tree = STRtree(sections)
def
read_properties
(
filepath
,
sep
=
'='
,
comment_char
=
'#'
):
props
=
{}
...
...
@@ -78,7 +106,13 @@ def writeStatus(status):
def
run
():
try
:
writeStatus
(
"INITIAL"
)
strtree
=
STRtree
(
pickle
.
load
(
pkg_resources
.
resource_stream
(
__name__
,
'/'
.
join
((
'resources'
,
'strtree.pickle'
)))))
# strtree = STRtree(pickle.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.pickle')))))
jsondata
=
json
.
load
(
pkg_resources
.
resource_stream
(
__name__
,
'/'
.
join
((
'resources'
,
'strtree.json'
))));
sections
=
[]
for
section
in
jsondata
:
sections
.
append
(
LineString
(
section
))
strtree
=
STRtree
(
sections
)
m
=
Model
()()
with
open
(
'input.json'
,
"r"
)
as
inputfile
:
print
(
"PARTIAL"
)
...
...
@@ -114,5 +148,6 @@ def run():
To run in terminal call with python __init__.py
'''
if
__name__
==
"__main__"
:
storetree
()
#storetree()
loadtree
()
\ No newline at end of file
exercisemodel/model.py
View file @
dc0115f0
...
...
@@ -286,21 +286,20 @@ class Model(object):
linestring
=
geometry
.
shape
(
exercisefeature
[
'geometry'
])
latlngpoints
=
[[
latlng
[
1
],
latlng
[
0
]]
for
latlng
in
linestring
.
coords
]
# print('before matches')
#
matches = strtree.query(LineString(latlngpoints))
matches
=
strtree
.
query
(
LineString
(
latlngpoints
))
# print('matches: '+str(matches))
for
i
,
coord
in
enumerate
(
linestring
.
coords
):
#
start = time.time()
#
if (len(mp.geoms) > 0):
points
=
self
.
centerPoints
(
coord
,
mp
.
centroid
,
mp
.
geoms
)
displacedpoints
=
self
.
displacePoints
(
pDist
,
points
)
#
activepoints, onlandpoints = self.onlandPoints(mp.geoms, displacedpoints, matches)
#
deactivepoints += onlandpoints
start
=
time
.
time
()
if
(
len
(
mp
.
geoms
)
>
0
):
points
=
self
.
centerPoints
(
coord
,
mp
.
centroid
,
mp
.
geoms
)
displacedpoints
=
self
.
displacePoints
(
pDist
,
points
)
activepoints
,
onlandpoints
=
self
.
onlandPoints
(
mp
.
geoms
,
displacedpoints
,
matches
)
deactivepoints
+=
onlandpoints
# print('active: '+str(len(activepoints)))
# print('onland: '+str(len(onlandpoints)))
#
end = time.time()
end
=
time
.
time
()
# print('onland: '+str(end-start))
# mp = geometry.MultiPoint(activepoints+deactivepoints)
mp
=
geometry
.
MultiPoint
(
displacedpoints
)
mp
=
geometry
.
MultiPoint
(
activepoints
+
deactivepoints
)
level
=
[
0
]
*
len
(
mp
.
geoms
)
category
=
[
2
]
*
len
(
mp
.
geoms
)
properties
=
self
.
createProperties
((
i
+
2
),
timearray
[
i
],
mp
.
centroid
,
level
,
category
)
...
...
@@ -308,7 +307,7 @@ class Model(object):
if
(
i
%
10
==
0
):
Cloudtrack
.
write
(
featurecollection
)
Particletrack
.
write
(
featurecollection
)
#
mp = geometry.MultiPoint(activepoints)
mp
=
geometry
.
MultiPoint
(
activepoints
)
print
(
'deactivepoints: '
+
str
(
len
(
deactivepoints
)))
...
...
exercisemodel/resources/strtree.json
0 → 100644
View file @
dc0115f0
This diff is collapsed.
Click to expand it.
exercisemodel/resources/strtree.pickle
View file @
dc0115f0
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment