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
dacfecb0
Commit
dacfecb0
authored
Apr 16, 2021
by
Sonja Tripkovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added geospatial: interpolate_series_at_distance; added plotting: plot_street_nodes
parent
754096cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
2 deletions
+47
-2
geospatial.py
measprocess/geospatial.py
+35
-2
plotting.py
measprocess/plotting.py
+12
-0
No files found.
measprocess/geospatial.py
View file @
dacfecb0
import
overpy
import
geopandas
as
gpd
from
shapely.geometry
import
LineString
,
Polygon
,
box
from
shapely.geometry
import
LineString
,
Polygon
,
Point
,
box
from
scipy.spatial.distance
import
cdist
import
numpy
as
np
import
warnings
...
...
@@ -156,4 +156,37 @@ def crop_geoseries_by_bounds(original_geoseries : gpd.GeoSeries, filter_geoserie
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
return
filtered_series
def
interpolate_series_at_distance
(
street_series
:
gpd
.
GeoSeries
,
distance
:
int
=
2
)
->
gpd
.
GeoSeries
:
'''
Interpolates along the geoseries streets_series to get nodes at a distance 'distance' apart.
Make sure to pass data in Cartesian coordinates (e.g. use street_series.to_crs('EPSG:31287') for Austria).
:param street_series: geopandas geoseries
:param distance: integer determining the spacing between interpolation points, default=2
:return: geopandas geoseries overlapping with original geoseries containing more frequent nodes
'''
if
street_series
.
crs
==
"EPSG:4326"
:
raise
ValueError
(
"Make sure to pass data in Cartesian coordinates (e.g. use street_series.to_crs('EPSG:31287') for Austria)"
)
if
distance
<=
0
:
raise
ValueError
(
"Distance has to be a positive number."
)
lines
=
[]
for
linestring
in
street_series
:
list_points
=
[]
# list to hold all the point coords
current_dist
=
distance
# set the current distance to place the point
line_length
=
linestring
.
length
# get the total length of the line (not number of points, but actual length)
list_points
.
append
(
Point
(
list
(
linestring
.
coords
[
0
])))
# append the starting coordinate to the list
while
current_dist
<
line_length
:
# while the current cumulative distance is less than the total length of the line
list_points
.
append
(
linestring
.
interpolate
(
current_dist
))
# use interpolate and increase the current distance
current_dist
+=
distance
list_points
.
append
(
Point
(
list
(
linestring
.
coords
[
-
1
])))
# append end coordinate to the list
line
=
LineString
(
list_points
)
lines
.
append
(
line
)
interpolated_street_series
=
gpd
.
GeoSeries
(
lines
)
return
interpolated_street_series
measprocess/plotting.py
View file @
dacfecb0
...
...
@@ -34,3 +34,15 @@ def plot_series_osm(gps_series : gpd.GeoSeries, c_series : np.ndarray = None, zo
plt
.
savefig
(
save_path
,
bbox_inches
=
"tight"
)
if
show
:
plt
.
show
()
def
plot_street_nodes
(
street_series
:
gpd
.
GeoSeries
,
axs
,
marker
:
str
=
'o'
,
color
:
str
=
'blue'
):
'''
Plots the street_series with nodes along each way.
:param street_series: geopandas series of LineStrings
:param axs: denotes the axis on which to plot
:param marker: marker for the nodes
:param color: color of the plotted lines and nodes
'''
for
linestring
in
street_series
:
axs
.
plot
(
np
.
array
(
linestring
)[:,
0
],
np
.
array
(
linestring
)[:,
1
],
marker
=
marker
,
color
=
color
)
\ 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