Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
measprocess
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lukas Eller
measprocess
Commits
754096cd
Commit
754096cd
authored
Apr 14, 2021
by
Sonja Tripkovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added crop_geoseries_by_bound(); updated get_geoseries_streets() to include crop option
parent
474ff57c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
3 deletions
+28
-3
geospatial.py
measprocess/geospatial.py
+28
-3
No files found.
measprocess/geospatial.py
View file @
754096cd
import
overpy
import
overpy
import
geopandas
as
gpd
import
geopandas
as
gpd
from
shapely.geometry
import
LineString
,
Polygon
from
shapely.geometry
import
LineString
,
Polygon
,
box
from
scipy.spatial.distance
import
cdist
from
scipy.spatial.distance
import
cdist
import
numpy
as
np
import
numpy
as
np
import
warnings
import
warnings
import
time
import
time
import
matplotlib.pyplot
as
plt
def
make_overpy_request
(
request_body
:
str
,
retries
:
int
):
def
make_overpy_request
(
request_body
:
str
,
retries
:
int
):
for
_
in
range
(
retries
):
for
_
in
range
(
retries
):
...
@@ -19,11 +20,13 @@ def make_overpy_request(request_body : str, retries : int):
...
@@ -19,11 +20,13 @@ def make_overpy_request(request_body : str, retries : int):
else
:
else
:
return
result
return
result
def
get_geoseries_streets
(
measurement_coords
:
gpd
.
GeoSeries
,
retries
:
int
=
5
)
->
gpd
.
GeoSeries
:
def
get_geoseries_streets
(
measurement_coords
:
gpd
.
GeoSeries
,
retries
:
int
=
5
,
crop
:
bool
=
False
)
->
gpd
.
GeoSeries
:
'''
'''
Obtain the street shapes in the area spanned by the measurement_coords.
Obtain the street shapes in the area spanned by the measurement_coords.
:param measurement_coords: A geopandas geoseries of Points(lon, lat) representing the measurement positions in a EPSG:4326 projection
:param measurement_coords: A geopandas geoseries of Points(lon, lat) representing the measurement positions in a EPSG:4326 projection
:param retries: Number of retries for overpy requests, default:5
:param crop: Set to True if the returned geoseries should be fixed to bounding box determined by measurement_coords, default: False
:return: A geopandas geoseries consiting of LineStrings representing the streets in EPSG:4326
:return: A geopandas geoseries consiting of LineStrings representing the streets in EPSG:4326
'''
'''
...
@@ -49,10 +52,13 @@ def get_geoseries_streets(measurement_coords : gpd.GeoSeries, retries : int = 5)
...
@@ -49,10 +52,13 @@ def get_geoseries_streets(measurement_coords : gpd.GeoSeries, retries : int = 5)
street_series
=
gpd
.
GeoSeries
(
street_series
=
gpd
.
GeoSeries
(
LineString
(
LineString
(
((
node
.
lon
,
node
.
lat
)
for
node
in
way
.
nodes
)
((
node
.
lon
,
node
.
lat
)
for
node
in
way
.
nodes
if
len
(
way
.
nodes
)
>
1
)
)
for
way
in
result
.
ways
)
for
way
in
result
.
ways
)
.
set_crs
(
"EPSG:4326"
)
)
.
set_crs
(
"EPSG:4326"
)
if
crop
==
True
:
street_series
=
crop_geoseries_by_bounds
(
street_series
,
measurement_coords
)
return
street_series
return
street_series
def
get_geoseries_blockages
(
measurement_coords
:
gpd
.
GeoSeries
,
retries
:
int
=
5
)
->
gpd
.
GeoSeries
:
def
get_geoseries_blockages
(
measurement_coords
:
gpd
.
GeoSeries
,
retries
:
int
=
5
)
->
gpd
.
GeoSeries
:
...
@@ -132,3 +138,22 @@ def project_onto_streets(point_series : gpd.GeoSeries, street_series : gpd.GeoSe
...
@@ -132,3 +138,22 @@ def project_onto_streets(point_series : gpd.GeoSeries, street_series : gpd.GeoSe
plt
.
show
()
plt
.
show
()
return
projected
,
deviation_projection
return
projected
,
deviation_projection
def
crop_geoseries_by_bounds
(
original_geoseries
:
gpd
.
GeoSeries
,
filter_geoseries
:
gpd
.
GeoSeries
)
->
gpd
.
GeoSeries
:
"""
Returns cut off geoseries from 'original_geoseries' which lies within the bounds on the filter_geoseries
:param original_geoseries: A geopandas geoseries of points/streets/polygons to be filtered, represented in a EPSG:4326 projection
:param filter_geoseries: A geopandas geoseries based on which a bounding box is for filter is made
:return: geopandas geoseries of same format as original_geoseries
"""
if
original_geoseries
.
crs
!=
"EPSG:4326"
or
filter_geoseries
.
crs
!=
"EPSG:4326"
:
raise
ValueError
(
"Make sure to pass data with EPSG:4326 projection"
)
filter_bounds
=
filter_geoseries
.
total_bounds
bound_box
=
box
(
filter_bounds
[
0
],
filter_bounds
[
1
],
filter_bounds
[
2
],
filter_bounds
[
3
])
bound_box
=
gpd
.
GeoDataFrame
(
geometry
=
gpd
.
GeoSeries
(
bound_box
))
.
set_crs
(
"EPSG:4326"
)
# create geodataframe for overlay
filtered_series
=
(
gpd
.
overlay
(
gpd
.
GeoDataFrame
(
geometry
=
original_geoseries
),
bound_box
,
how
=
'intersection'
))
.
geometry
return
filtered_series
\ No newline at end of file
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