Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG2900
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sara Savanovic Djordjevic
PROG2900
Commits
81b0bc99
Commit
81b0bc99
authored
11 months ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
add: lake relations directory path to consts
parent
46002dd4
No related branches found
Branches containing commit
No related tags found
1 merge request
!12
Clhp map
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
server/consts.py
+4
-2
4 additions, 2 deletions
server/consts.py
server/main.py
+3
-5
3 additions, 5 deletions
server/main.py
server/map_handler/add_lake.py
+3
-2
3 additions, 2 deletions
server/map_handler/add_lake.py
server/map_handler/process_lake.py
+2
-17
2 additions, 17 deletions
server/map_handler/process_lake.py
with
12 additions
and
26 deletions
server/consts.py
+
4
−
2
View file @
81b0bc99
...
...
@@ -9,5 +9,7 @@ CERT_DIR = "server/certificates/"
SSL_KEY_PATH
=
CERT_DIR
+
"
testKey.key
"
SSL_CERT_PATH
=
CERT_DIR
+
"
testCert.crt
"
# Measurement specs
AREA_SIZE
=
20
# File paths
MAP_HANDLER_PATH
=
"
server/map_handler/
"
LAKE_RELATIONS_PATH
=
MAP_HANDLER_PATH
+
"
lake_relations/
"
This diff is collapsed.
Click to expand it.
server/main.py
+
3
−
5
View file @
81b0bc99
...
...
@@ -7,9 +7,10 @@ from http.server import HTTPServer, BaseHTTPRequestHandler
from
consts
import
SSL_CERT_PATH
,
SSL_KEY_PATH
,
HOST
,
PORT
from
map_handler.add_lake
import
cut_map
from
server.consts
import
LAKE_RELATIONS_PATH
from
map_handler.process_lake
import
get_divided_map
from
map_handler.get_measurements
import
get_all_markers
from
map_handler.input_new_data
import
input_new_Lidar_data
from
map_handler.process_lake
import
get_divided_map
,
get_ids_and_centers
app
=
Flask
(
__name__
)
terminate_server
=
0
...
...
@@ -42,7 +43,7 @@ class IceHTTP(BaseHTTPRequestHandler):
self
.
wfile
.
write
(
b
"
Root path hit!
"
)
elif
self
.
path
==
'
/get_lake_names
'
:
with
open
(
'
server/map_handler/lake_relations/
all_lake_names.json
'
,
'
r
'
)
as
file
:
with
open
(
LAKE_RELATIONS_PATH
+
'
all_lake_names.json
'
,
'
r
'
)
as
file
:
lake_names
=
json
.
load
(
file
)
# Disable ensure_ascii to keep 'ø'
...
...
@@ -64,9 +65,6 @@ class IceHTTP(BaseHTTPRequestHandler):
get_divided_map
(
self
,
'
Mjosa
'
)
# NB temp hardcoded value
elif
self
.
path
==
'
/divide_new_relation
'
:
cut_map
(
self
,
'
Mjosa
'
)
elif
self
.
path
==
'
/test
'
:
get_ids_and_centers
(
'
server/map_handler/lake_relations/mjosa_div.json
'
)
def
do_POST
(
self
):
if
self
.
path
==
'
/new_lidar_data
'
:
input_new_Lidar_data
(
self
,
self
.
cursor
,
1
,
'
Mjosa
'
)
# hardcoded body of water must change later
...
...
This diff is collapsed.
Click to expand it.
server/map_handler/add_lake.py
+
3
−
2
View file @
81b0bc99
...
...
@@ -3,12 +3,13 @@ from shapely.geometry import Polygon, LineString, MultiLineString
from
shapely.ops
import
linemerge
,
unary_union
,
polygonize
import
json
import
os
from
server.consts
import
LAKE_RELATIONS_PATH
# Read a json file with relation data and send to response object
def
cut_map
(
self
,
body_of_water
:
str
):
# NB: implement body_of_water
# Read relation from GeoJson file and extract all polygons
geo_data
=
gpd
.
read_file
(
"
server/map_handler/lake_relations/
mjosa.geojson
"
)
geo_data
=
gpd
.
read_file
(
LAKE_RELATIONS_PATH
+
"
mjosa.geojson
"
)
polygon_data
=
geo_data
[
geo_data
[
'
geometry
'
].
geom_type
==
'
Polygon
'
]
polygons
=
[
Polygon
(
polygon
.
exterior
)
for
polygon
in
polygon_data
[
'
geometry
'
]]
...
...
@@ -90,7 +91,7 @@ def cut_map(self, body_of_water: str): # NB: implement body_of_water
# NB currently hardcoded file path
# Create the txt file specified by the path
with
open
(
"
server/map_handler/lake_relations/
mjosa_centers.txt
"
,
'
w
'
)
as
file
:
with
open
(
LAKE_RELATIONS_PATH
+
"
mjosa_centers.txt
"
,
'
w
'
)
as
file
:
# Iterate over the list and write each element to the file
for
sub_div_id
,
x
,
y
in
sub_div_center_list
:
file
.
write
(
f
"
{
sub_div_id
}
,
{
x
}
,
{
y
}
\n
"
)
# Write each list entry on a new line
...
...
This diff is collapsed.
Click to expand it.
server/map_handler/process_lake.py
+
2
−
17
View file @
81b0bc99
import
json
from
server.consts
import
LAKE_RELATIONS_PATH
# Writes contents of a lake json file to the response
...
...
@@ -8,23 +8,8 @@ def get_divided_map(self, file_name):
self
.
end_headers
()
# Extract contents from JSON file
with
open
(
"
server/map_handler/lake_relations/
"
+
file_name
+
"
_div.json
"
,
"
r
"
)
as
file
:
with
open
(
LAKE_RELATIONS_PATH
+
file_name
+
"
_div.json
"
,
"
r
"
)
as
file
:
data
=
file
.
read
()
# Write contents of the JSON file to response
self
.
wfile
.
write
(
data
.
encode
(
'
utf-8
'
))
# Returns a list of all sub_division ids and their center coordinates for a given lake
def
get_ids_and_centers
(
file_path
):
# NB buggy
# Expected format: [(sub_div_id, [x,y]), (sub_div_id, [x,y]), ...]
return_list
=
[]
f
=
open
(
file_path
)
data
=
json
.
load
(
f
)
for
measurement
in
data
[
'
measurement
'
]:
for
sub_div
in
measurement
[
'
Subdivisions
'
]:
return_list
.
append
((
sub_div
[
'
SubdivID
'
],
(
sub_div
[
'
CenLatitude
'
],
sub_div
[
'
CenLongitude
'
])))
return
return_list
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment