MovingPandas at PyDays Vienna 2019

Anita Graser
Anita GraserResearcher at the AIT - Austrian Institute of Technology
MOVINGPANDAS
https://github.com/anitagraser/movingpandas
Anita Graser
@underdarkGIS
MovingPandas at PyDays Vienna 2019
Unfortunately not this kind of Panda …
MOVINGPANDAS
… but this:
MOVINGPANDAS
https://pandas.pydata.org
MOTIVATION
https://anitagraser.com/2016/09/18/movement-data-in-gis-issues-ideas/
Movement data is …
… geographic
… temporal
 Geographic features with
timestamps?
 Timeseries with geometries?
MOTIVATION
e.g.
id,x,y,t,state,type_code
a,11.0,2.0,2012-01-17T12:33:51Z,walking,1
a,12.0,3.0,2012-01-17T12:36:11Z,walking,1
a,10.0,3.0,2012-01-17T12:36:51Z,walking,2
b,10.0,2.0,2012-01-17T12:33:51Z,walking,2
b,11.0,3.0,2012-01-17T12:36:51Z,walking,2
c,12.0,1.0,2012-01-17T12:33:51Z,vehicle,1
c,10.0,2.0,2012-01-17T12:35:21Z,vehicle,1
c,11.0,3.0,2012-01-17T12:36:51Z,vehicle,1
...
https://anitagraser.com/2017/10/15/movement-data-in-gis-9-trajectory-data-models/
GIS – AN OBVIOUS CHOICE?
704/05/2019
Simple Features
 Points
 No built-in logic @ chronological order & moving object identity
 Lines
 Only attributes for whole trajectory (segment)
 No timestamp for each location
GIS – AN OBVIOUS CHOICE?
Pandas
… developed in the context of financial modeling
 extensive set of tools for working with dates, times,
and time-indexed data
GeoPandas
… extends the datatypes used by pandas to allow spatial
operations on geometric types
 http://geopandas.org
WHY PANDAS?
https://anitagraser.com/2018/11/18/movement-data-in-gis-16-towards-pure-python-trajectories-using-geopandas/
Trajectory
id: string
df: GeoDataFrame
crs: string
parent: Trajectory
__str__()
set_crs(crs)
has_parent(): boolean
to_linestring(): shapely.geometry.LineString
to_linestringm_wkt(): string
get_start_location(): shapely.geometry.Point
get_end_location(): shapely.geometry.Point
get_bbox(): (minx, miny, maxx, maxy) tuple
get_start_time(): datetime
get_end_time(): datetime
get_duration(): timedelta
get_length(): float
get_direction(): float
get_row_at(timestamp, method='nearest'):
pandas.Series
get_position_at(timestamp, method='nearest'):
shapely.geometry.Point
get_linestring_between(timestamp1,
timestamp2): shapely.geometry.LineString
get_segment_between(timestamp1, timestamp2):
Trajectory
add_direction()
add_speed()
make_line(df): shapely.geometry.LineString
clip(shapely.geometry.polygon): Trajectory
intersection(fiona.feature): Trajectory
MOVINGPANDAS TRAJECTORY CLASS
Graser (in press) MovingPandas: Efficient Structures for Movement Data in Python. GI_Forum ‒ Journal of Geographic Information Science
>>> import pandas as pd
>>> from geopandas import read_file
>>> from shapely.geometry import Polygon
>>> from trajectory import Trajectory
>>> df = read_file('demodata_geolife.gpkg')
>>> df['t'] = pd.to_datetime(df['t'])
>>> df = df.set_index('t')
>>> print("Finished reading {} rows".format(len(df)))
Finished reading 5908 rows
EXAMPLE:
READING TRAJECTORY DATA FROM GEOPACKAGE
Graser (in press) MovingPandas: Efficient Structures for Movement Data in Python. GI_Forum ‒ Journal of Geographic Information Science
>>> trajectories = []
>>> for key, values in df.groupby(['trajectory_id']):
>>> trajectory = Trajectory(key, values)
>>> print(trajectory)
>>> trajectories.append(trajectory)
>>> print("Finished creating {} trajectories".format(len(trajectories)))
Trajectory 1 (2008-12-11 04:42:14 to 2008-12-11 05:15:46) | Size: 466 | Length: 6210.1m
LINESTRING (116.391305 39.898573, 116.391317 39.898617, 116.390928 39.898613, ...
Trajectory 2 (2009-06-29 07:02:25 to 2009-06-29 11:13:12) | Size: 897 | Length: 38728.7m
LINESTRING (116.590957 40.071961, 116.590905 40.072007, 116.590879 40.072027, ...
Trajectory 3 (2009-02-04 04:32:53 to 2009-02-04 11:20:12) | Size: 1810 | Length: 12739.2m
LINESTRING (116.385689 39.899773, 116.385654 39.899651, 116.385548 39.899699, ...
...
Finished creating 5 trajectories
EXAMPLE:
READING TRAJECTORY DATA FROM GEOPACKAGE
Graser (in press) MovingPandas: Efficient Structures for Movement Data in Python. GI_Forum ‒ Journal of Geographic Information Science
>>> xmin, xmax, ymin, ymax = 116.3685035,116.3702945,39.904675,39.907728
>>> polygon = Polygon([(xmin,ymin), (xmin,ymax), (xmax,ymax), (xmax,ymin), (xmin,ymin)])
>>> intersections = []
>>> for key, values in df.groupby(['trajectory_id']):
>>> traj = Trajectory(key, values)
>>> for intersection in traj.clip(polygon):
>>> intersections.append(intersection)
>>> print("Found {} intersections".format(len(intersections)))
Found 3 intersections
EXAMPLE:
… AND CLIPPING BY POLYGON
Graser (in press) MovingPandas: Efficient Structures for Movement Data in Python. GI_Forum ‒ Journal of Geographic Information Science
EXAMPLE:
TIME SERIES USE CASE IN AGRICULTURE
04/05/2019
Offset function
keep time/location & shift value
def apply_offset_seconds(self, column, offset):
self.df[column] = self.df[column]
.shift(offset, freq='1s’)
https://anitagraser.com/2019/01/27/dealing-with-delayed-measurements-in-geopandas/
LIVE DEMO ON MYBINDER.ORG
https://anitagraser.com/2018/11/18/movement-data-in-gis-16-towards-pure-python-trajectories-using-geopandas/
Trajectools plugin
for Processing toolbox
MOVINGPANDAS INTEGRATION IN QGIS
https://anitagraser.com/2019/02/02/movement-data-in-gis-20-trajectools-v1-released/
1704/05/2019
https://anitagraser.com/2019/01/26/movement-data-in-gis-19-splitting-trajectories-by-date/
1804/05/2019
https://anitagraser.com/2019/01/26/movement-data-in-gis-19-splitting-trajectories-by-date/
 Looking for contributors  talks & workshops to spread the word
 More features & tests
 Create a MovingPandas Python package
NEXT STEPS
anita.graser@ait.ac.at
@underdarkGIS
anitagraser.com
ANITA GRASER
1 of 20

Recommended

Find Transitive closure of a Graph Using Warshall's Algorithm by
Find Transitive closure of a Graph Using Warshall's AlgorithmFind Transitive closure of a Graph Using Warshall's Algorithm
Find Transitive closure of a Graph Using Warshall's AlgorithmSafayet Hossain
4.1K views18 slides
Anita Graser: Analyzing Movment Data with MovingPandas by
Anita Graser: Analyzing Movment Data  with MovingPandas Anita Graser: Analyzing Movment Data  with MovingPandas
Anita Graser: Analyzing Movment Data with MovingPandas Vienna Data Science Group
232 views32 slides
Introduction To PostGIS by
Introduction To PostGISIntroduction To PostGIS
Introduction To PostGISmleslie
6.5K views59 slides
IGARSS11_takaku_dsm_report.ppt by
IGARSS11_takaku_dsm_report.pptIGARSS11_takaku_dsm_report.ppt
IGARSS11_takaku_dsm_report.pptgrssieee
395 views32 slides
Big Spatial(!) Data Processing mit GeoMesa. AGIT 2019, Salzburg, Austria. by
Big Spatial(!) Data Processing mit GeoMesa. AGIT 2019, Salzburg, Austria.Big Spatial(!) Data Processing mit GeoMesa. AGIT 2019, Salzburg, Austria.
Big Spatial(!) Data Processing mit GeoMesa. AGIT 2019, Salzburg, Austria.Anita Graser
451 views27 slides
مقاله موبایل واعتمادزناشویی by
مقاله موبایل واعتمادزناشوییمقاله موبایل واعتمادزناشویی
مقاله موبایل واعتمادزناشوییs.kamaleddin mousavi
421 views21 slides

More Related Content

More from Anita Graser

Trajectory Visualization in Notebook Environments @ GI_Salzburg 2022 by
Trajectory Visualization in Notebook Environments @ GI_Salzburg 2022Trajectory Visualization in Notebook Environments @ GI_Salzburg 2022
Trajectory Visualization in Notebook Environments @ GI_Salzburg 2022Anita Graser
97 views19 slides
Movement Data in GIS - Geobeer Lightning Talk, 2021-03-08 by
Movement Data in GIS - Geobeer Lightning Talk, 2021-03-08Movement Data in GIS - Geobeer Lightning Talk, 2021-03-08
Movement Data in GIS - Geobeer Lightning Talk, 2021-03-08Anita Graser
258 views9 slides
Exploratory Analysis of Massive Movement Data (RGS-IBG GIScience Research Gro... by
Exploratory Analysis of Massive Movement Data (RGS-IBG GIScience Research Gro...Exploratory Analysis of Massive Movement Data (RGS-IBG GIScience Research Gro...
Exploratory Analysis of Massive Movement Data (RGS-IBG GIScience Research Gro...Anita Graser
465 views28 slides
From Simple Features to Moving Features and Beyond? at OGC Member Meeting, Se... by
From Simple Features to Moving Features and Beyond? at OGC Member Meeting, Se...From Simple Features to Moving Features and Beyond? at OGC Member Meeting, Se...
From Simple Features to Moving Features and Beyond? at OGC Member Meeting, Se...Anita Graser
150 views15 slides
Data-driven Trajectory Prediction in Maritime LBS by
Data-driven Trajectory Prediction in Maritime LBSData-driven Trajectory Prediction in Maritime LBS
Data-driven Trajectory Prediction in Maritime LBSAnita Graser
462 views15 slides
QGIS das Opensource GIS at Linuxwochen Wien 2019 by
QGIS das Opensource GIS at Linuxwochen Wien 2019QGIS das Opensource GIS at Linuxwochen Wien 2019
QGIS das Opensource GIS at Linuxwochen Wien 2019Anita Graser
542 views26 slides

More from Anita Graser(20)

Trajectory Visualization in Notebook Environments @ GI_Salzburg 2022 by Anita Graser
Trajectory Visualization in Notebook Environments @ GI_Salzburg 2022Trajectory Visualization in Notebook Environments @ GI_Salzburg 2022
Trajectory Visualization in Notebook Environments @ GI_Salzburg 2022
Anita Graser97 views
Movement Data in GIS - Geobeer Lightning Talk, 2021-03-08 by Anita Graser
Movement Data in GIS - Geobeer Lightning Talk, 2021-03-08Movement Data in GIS - Geobeer Lightning Talk, 2021-03-08
Movement Data in GIS - Geobeer Lightning Talk, 2021-03-08
Anita Graser258 views
Exploratory Analysis of Massive Movement Data (RGS-IBG GIScience Research Gro... by Anita Graser
Exploratory Analysis of Massive Movement Data (RGS-IBG GIScience Research Gro...Exploratory Analysis of Massive Movement Data (RGS-IBG GIScience Research Gro...
Exploratory Analysis of Massive Movement Data (RGS-IBG GIScience Research Gro...
Anita Graser465 views
From Simple Features to Moving Features and Beyond? at OGC Member Meeting, Se... by Anita Graser
From Simple Features to Moving Features and Beyond? at OGC Member Meeting, Se...From Simple Features to Moving Features and Beyond? at OGC Member Meeting, Se...
From Simple Features to Moving Features and Beyond? at OGC Member Meeting, Se...
Anita Graser150 views
Data-driven Trajectory Prediction in Maritime LBS by Anita Graser
Data-driven Trajectory Prediction in Maritime LBSData-driven Trajectory Prediction in Maritime LBS
Data-driven Trajectory Prediction in Maritime LBS
Anita Graser462 views
QGIS das Opensource GIS at Linuxwochen Wien 2019 by Anita Graser
QGIS das Opensource GIS at Linuxwochen Wien 2019QGIS das Opensource GIS at Linuxwochen Wien 2019
QGIS das Opensource GIS at Linuxwochen Wien 2019
Anita Graser542 views
GIScience for Dynamic Transportation Systems, GIScience Colloquium, Universit... by Anita Graser
GIScience for Dynamic Transportation Systems, GIScience Colloquium, Universit...GIScience for Dynamic Transportation Systems, GIScience Colloquium, Universit...
GIScience for Dynamic Transportation Systems, GIScience Colloquium, Universit...
Anita Graser848 views
QGIS Neuigkeiten @ AGIT2017 by Anita Graser
QGIS Neuigkeiten @ AGIT2017QGIS Neuigkeiten @ AGIT2017
QGIS Neuigkeiten @ AGIT2017
Anita Graser726 views
Landmark-based instructions for pedestrian navigation systems using OSM by Anita Graser
Landmark-based instructions for pedestrian navigation systems using OSMLandmark-based instructions for pedestrian navigation systems using OSM
Landmark-based instructions for pedestrian navigation systems using OSM
Anita Graser16.5K views
QGIS Processing at Linuxwochen Wien / PyDays 2017 by Anita Graser
QGIS Processing at Linuxwochen Wien / PyDays 2017QGIS Processing at Linuxwochen Wien / PyDays 2017
QGIS Processing at Linuxwochen Wien / PyDays 2017
Anita Graser2.9K views
Integrating Open Spaces into OSM Routing Graphs for Realistic Crossing Behavi... by Anita Graser
Integrating Open Spaces into OSM Routing Graphs for Realistic Crossing Behavi...Integrating Open Spaces into OSM Routing Graphs for Realistic Crossing Behavi...
Integrating Open Spaces into OSM Routing Graphs for Realistic Crossing Behavi...
Anita Graser11.1K views
Neuigkeiten vom QGIS-Projekt - AGIT 2016 by Anita Graser
Neuigkeiten vom QGIS-Projekt - AGIT 2016Neuigkeiten vom QGIS-Projekt - AGIT 2016
Neuigkeiten vom QGIS-Projekt - AGIT 2016
Anita Graser10.8K views
Spatial Data Analysis & Visualization with QGIS - Vienna Data Science Meetup by Anita Graser
Spatial Data Analysis & Visualization with QGIS - Vienna Data Science MeetupSpatial Data Analysis & Visualization with QGIS - Vienna Data Science Meetup
Spatial Data Analysis & Visualization with QGIS - Vienna Data Science Meetup
Anita Graser954 views
Better Urban Travel Time Estimates Using Street Network Centrality #Eurocarto15 by Anita Graser
Better Urban Travel Time Estimates Using Street Network Centrality #Eurocarto15Better Urban Travel Time Estimates Using Street Network Centrality #Eurocarto15
Better Urban Travel Time Estimates Using Street Network Centrality #Eurocarto15
Anita Graser1.1K views
Time Manager Vortrag vom QGIS-DE Anwendertreffen 2015 by Anita Graser
Time Manager Vortrag vom QGIS-DE Anwendertreffen 2015Time Manager Vortrag vom QGIS-DE Anwendertreffen 2015
Time Manager Vortrag vom QGIS-DE Anwendertreffen 2015
Anita Graser800 views
Time Manager Workshop vom QGIS-DE Anwendertreffen 2015 by Anita Graser
Time Manager Workshop vom QGIS-DE Anwendertreffen 2015Time Manager Workshop vom QGIS-DE Anwendertreffen 2015
Time Manager Workshop vom QGIS-DE Anwendertreffen 2015
Anita Graser687 views
Improving Navigation: Automated Name Extraction for Separately Mapped Pedestr... by Anita Graser
Improving Navigation: Automated Name Extraction for Separately Mapped Pedestr...Improving Navigation: Automated Name Extraction for Separately Mapped Pedestr...
Improving Navigation: Automated Name Extraction for Separately Mapped Pedestr...
Anita Graser22K views
Routing mit OSM - #AGIT2015 by Anita Graser
Routing mit OSM - #AGIT2015Routing mit OSM - #AGIT2015
Routing mit OSM - #AGIT2015
Anita Graser23.2K views
QGIS jenseits von zwei Dimensionen - KAGIS-Fachtagung 2015 by Anita Graser
QGIS jenseits von zwei Dimensionen - KAGIS-Fachtagung 2015QGIS jenseits von zwei Dimensionen - KAGIS-Fachtagung 2015
QGIS jenseits von zwei Dimensionen - KAGIS-Fachtagung 2015
Anita Graser1.6K views
Time Manager Workshop at #QGIS2015 Conference in Nodebo by Anita Graser
Time Manager Workshop at #QGIS2015 Conference in NodeboTime Manager Workshop at #QGIS2015 Conference in Nodebo
Time Manager Workshop at #QGIS2015 Conference in Nodebo
Anita Graser38.8K views

Recently uploaded

Throughput by
ThroughputThroughput
ThroughputMoisés Armani Ramírez
36 views11 slides
Transcript: The Details of Description Techniques tips and tangents on altern... by
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...BookNet Canada
130 views15 slides
PharoJS - Zürich Smalltalk Group Meetup November 2023 by
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023Noury Bouraqadi
120 views17 slides
Web Dev - 1 PPT.pdf by
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdfgdsczhcet
55 views45 slides
.conf Go 2023 - Data analysis as a routine by
.conf Go 2023 - Data analysis as a routine.conf Go 2023 - Data analysis as a routine
.conf Go 2023 - Data analysis as a routineSplunk
93 views12 slides
Top 10 Strategic Technologies in 2024: AI and Automation by
Top 10 Strategic Technologies in 2024: AI and AutomationTop 10 Strategic Technologies in 2024: AI and Automation
Top 10 Strategic Technologies in 2024: AI and AutomationAutomationEdge Technologies
14 views14 slides

Recently uploaded(20)

Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada130 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi120 views
Web Dev - 1 PPT.pdf by gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet55 views
.conf Go 2023 - Data analysis as a routine by Splunk
.conf Go 2023 - Data analysis as a routine.conf Go 2023 - Data analysis as a routine
.conf Go 2023 - Data analysis as a routine
Splunk93 views
Combining Orchestration and Choreography for a Clean Architecture by ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs169 views
[2023] Putting the R! in R&D.pdf by Eleanor McHugh
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh38 views
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by Vadym Kazulkin
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin75 views
handbook for web 3 adoption.pdf by Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex19 views
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by NUS-ISS
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
NUS-ISS16 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab15 views
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze by NUS-ISS
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng TszeDigital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
NUS-ISS19 views
Future of Learning - Yap Aye Wee.pdf by NUS-ISS
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdf
NUS-ISS41 views

MovingPandas at PyDays Vienna 2019

  • 3. Unfortunately not this kind of Panda … MOVINGPANDAS
  • 6. Movement data is … … geographic … temporal  Geographic features with timestamps?  Timeseries with geometries? MOTIVATION e.g. id,x,y,t,state,type_code a,11.0,2.0,2012-01-17T12:33:51Z,walking,1 a,12.0,3.0,2012-01-17T12:36:11Z,walking,1 a,10.0,3.0,2012-01-17T12:36:51Z,walking,2 b,10.0,2.0,2012-01-17T12:33:51Z,walking,2 b,11.0,3.0,2012-01-17T12:36:51Z,walking,2 c,12.0,1.0,2012-01-17T12:33:51Z,vehicle,1 c,10.0,2.0,2012-01-17T12:35:21Z,vehicle,1 c,11.0,3.0,2012-01-17T12:36:51Z,vehicle,1 ... https://anitagraser.com/2017/10/15/movement-data-in-gis-9-trajectory-data-models/
  • 7. GIS – AN OBVIOUS CHOICE? 704/05/2019
  • 8. Simple Features  Points  No built-in logic @ chronological order & moving object identity  Lines  Only attributes for whole trajectory (segment)  No timestamp for each location GIS – AN OBVIOUS CHOICE?
  • 9. Pandas … developed in the context of financial modeling  extensive set of tools for working with dates, times, and time-indexed data GeoPandas … extends the datatypes used by pandas to allow spatial operations on geometric types  http://geopandas.org WHY PANDAS? https://anitagraser.com/2018/11/18/movement-data-in-gis-16-towards-pure-python-trajectories-using-geopandas/
  • 10. Trajectory id: string df: GeoDataFrame crs: string parent: Trajectory __str__() set_crs(crs) has_parent(): boolean to_linestring(): shapely.geometry.LineString to_linestringm_wkt(): string get_start_location(): shapely.geometry.Point get_end_location(): shapely.geometry.Point get_bbox(): (minx, miny, maxx, maxy) tuple get_start_time(): datetime get_end_time(): datetime get_duration(): timedelta get_length(): float get_direction(): float get_row_at(timestamp, method='nearest'): pandas.Series get_position_at(timestamp, method='nearest'): shapely.geometry.Point get_linestring_between(timestamp1, timestamp2): shapely.geometry.LineString get_segment_between(timestamp1, timestamp2): Trajectory add_direction() add_speed() make_line(df): shapely.geometry.LineString clip(shapely.geometry.polygon): Trajectory intersection(fiona.feature): Trajectory MOVINGPANDAS TRAJECTORY CLASS Graser (in press) MovingPandas: Efficient Structures for Movement Data in Python. GI_Forum ‒ Journal of Geographic Information Science
  • 11. >>> import pandas as pd >>> from geopandas import read_file >>> from shapely.geometry import Polygon >>> from trajectory import Trajectory >>> df = read_file('demodata_geolife.gpkg') >>> df['t'] = pd.to_datetime(df['t']) >>> df = df.set_index('t') >>> print("Finished reading {} rows".format(len(df))) Finished reading 5908 rows EXAMPLE: READING TRAJECTORY DATA FROM GEOPACKAGE Graser (in press) MovingPandas: Efficient Structures for Movement Data in Python. GI_Forum ‒ Journal of Geographic Information Science
  • 12. >>> trajectories = [] >>> for key, values in df.groupby(['trajectory_id']): >>> trajectory = Trajectory(key, values) >>> print(trajectory) >>> trajectories.append(trajectory) >>> print("Finished creating {} trajectories".format(len(trajectories))) Trajectory 1 (2008-12-11 04:42:14 to 2008-12-11 05:15:46) | Size: 466 | Length: 6210.1m LINESTRING (116.391305 39.898573, 116.391317 39.898617, 116.390928 39.898613, ... Trajectory 2 (2009-06-29 07:02:25 to 2009-06-29 11:13:12) | Size: 897 | Length: 38728.7m LINESTRING (116.590957 40.071961, 116.590905 40.072007, 116.590879 40.072027, ... Trajectory 3 (2009-02-04 04:32:53 to 2009-02-04 11:20:12) | Size: 1810 | Length: 12739.2m LINESTRING (116.385689 39.899773, 116.385654 39.899651, 116.385548 39.899699, ... ... Finished creating 5 trajectories EXAMPLE: READING TRAJECTORY DATA FROM GEOPACKAGE Graser (in press) MovingPandas: Efficient Structures for Movement Data in Python. GI_Forum ‒ Journal of Geographic Information Science
  • 13. >>> xmin, xmax, ymin, ymax = 116.3685035,116.3702945,39.904675,39.907728 >>> polygon = Polygon([(xmin,ymin), (xmin,ymax), (xmax,ymax), (xmax,ymin), (xmin,ymin)]) >>> intersections = [] >>> for key, values in df.groupby(['trajectory_id']): >>> traj = Trajectory(key, values) >>> for intersection in traj.clip(polygon): >>> intersections.append(intersection) >>> print("Found {} intersections".format(len(intersections))) Found 3 intersections EXAMPLE: … AND CLIPPING BY POLYGON Graser (in press) MovingPandas: Efficient Structures for Movement Data in Python. GI_Forum ‒ Journal of Geographic Information Science
  • 14. EXAMPLE: TIME SERIES USE CASE IN AGRICULTURE 04/05/2019 Offset function keep time/location & shift value def apply_offset_seconds(self, column, offset): self.df[column] = self.df[column] .shift(offset, freq='1s’) https://anitagraser.com/2019/01/27/dealing-with-delayed-measurements-in-geopandas/
  • 15. LIVE DEMO ON MYBINDER.ORG https://anitagraser.com/2018/11/18/movement-data-in-gis-16-towards-pure-python-trajectories-using-geopandas/
  • 16. Trajectools plugin for Processing toolbox MOVINGPANDAS INTEGRATION IN QGIS https://anitagraser.com/2019/02/02/movement-data-in-gis-20-trajectools-v1-released/
  • 19.  Looking for contributors  talks & workshops to spread the word  More features & tests  Create a MovingPandas Python package NEXT STEPS

Editor's Notes

  1. https://anitagraser.com/2019/01/26/movement-data-in-gis-19-splitting-trajectories-by-date/