Git Product home page Git Product logo

movingpandas's Introduction

MovingPandas

pypi Conda Version Conda Downloads Conda Recipe Conda Platforms Project Status: Active – The project has reached a stable, usable state and is being actively developed. Tests docs status codecov DOI pyOpenSci Code style: black StandWithUkraine

Mastodon Follow

SWUbanner

MovingPandas implements a Trajectory class and corresponding methods based on GeoPandas.

Visit movingpandas.org for details!

You can run MovingPandas examples on MyBinder - no installation required: Binder (These examples use the latest MovingPandas release version.)

To try the cutting-edge dev version, use this MyBinder link.

Documentation

We recommend starting your MovingPandas journey with the tutorial notebooks on the official homepage

The official API documentation is hosted on ReadTheDocs

Examples

Trajectory plots View Jupyter Notebook

Create interactive trajectory plots, including multiple linked plots with ease

movingpandas_animated

For all types of tracking data, e.g. video-based trajectories

Bicycle tracks from object tracking in videos

Including plots in custom projections View Jupyter Notebook

MovingPandas Iceberg trajectory in custom SouthPolarStereo projection

Stop detection View Jupyter Notebook

Detect stops in trajectories, extract them as points or segments, and use them to split trajectories

movingpandas_stop_detection

Trajectory generalization View Jupyter Notebook

Generalize trajectories using spatial, temporal, and spatiotemporal methods

movingpandas_generalize

Trajectory cleaning & smoothing View Jupyter Notebook

Clean and sooth trajectories by removing outliers and applying Kalman filters

movingpandas smooth

Trajectory aggregation View Jupyter Notebook

Aggregate trajectories to explore larger patterns

movingpandas_ais

Installation

MovingPandas for Python >= 3.7 and all its dependencies are available from conda-forge and can be installed using

conda install -c conda-forge movingpandas

or faster using

mamba install -c conda-forge movingpandas

Note that it is NOT recommended to install MovingPandas from PyPI! If you are using Windows or Mac, many GeoPandas / MovingPandas dependencies may not install correctly with pip (for details see the corresponding notes in the GeoPandas documentation). On Ubuntu, pip install may fail, e.g. on cartopy with "Proj 4.9.0 must be installed".

Development installation

Use the following steps to run the notebooks using the current development version:

Using conda / mamba

conda env create -f environment.yml

Develop mode

To install MovingPandas in "develop" or "editable" mode you may use:

python setup.py develop

Contributing to MovingPandas GitHub contributors

All contributions, bug reports, bug fixes, documentation improvements, enhancements and ideas are welcome.

A detailed overview on how to contribute can be found in the contributing guide on GitHub.

Related Python packages

For a more comprehensive list, including non-Python solutions, check https://github.com/anitagraser/movement-analysis-tools

scikit-mobility is a similar package which also deals with movement data. It implements TrajectoryDataFrames and FlowDataFrames on top of Pandas instead of GeoPandas. There is little overlap in the covered use cases and implemented functionality (comparing MovingPandas tutorials and scikit-mobility tutorials). MovingPandas focuses on spatio-temporal data exploration with corresponding functions for data manipulation and analysis. scikit-mobility on the other hand focuses on computing human mobility metrics, generating synthetic trajectories and assessing privacy risks. Plotting is based on Folium.

Traja extends the capabilitis of Pandas DataFrames specific for animal trajectory analysis in 2D. Plots (static) are based on seaborn.

PyMove provides functionality similar to MovingPandas. It implements PandasMoveDataFrames and DaskMoveDataFrame on top of Pandas and Dask DataFrames. Plotting is based on Folium.

Tracktable is a related Python package with its core data structures and algorithms implemented in C++, i.e. it is not based on Pandas. Plotting is based on Cartopy (for still images) and Folium (for interactive rendering).

Citation information

Please cite [0] when using MovingPandas in your research and reference the appropriate release version. All releases of MovingPandas are listed on Zenodo where you will find citation information, including DOIs.

Publications

About MovingPandas

[0] Graser, A. (2019). MovingPandas: Efficient Structures for Movement Data in Python. GI_Forum ‒ Journal of Geographic Information Science 2019, 1-2019, 54-68. doi:10.1553/giscience2019_01_s54.

@article{graser_movingpandas_2019,
	title = {{MovingPandas}: {Efficient} {Structures} for {Movement} {Data} in {Python}},
	volume = {7},
	number = {1},
	issn = {2308-1708, 2308-1708},
	shorttitle = {{MovingPandas}},
	url = {https://hw.oeaw.ac.at?arp=0x003aba2b},
	doi = {10.1553/giscience2019_01_s54},
	language = {en},
	urldate = {2023-04-19},
	journal = {GI\_Forum ‒ Journal of Geographic Information Science},
	author = {Graser, Anita},
	year = {2019},
	pages = {54--68},
}

[1] Graser, A. & Dragaschnig, M. (2020). Exploring movement data in notebook environments. Presented at MoVIS 2020, IEEE VIS 2020.

[2] Graser, A. (2021). Exploratory Movement Data Analysis. GeoPython 2021. – 🎬 video

Scientific publications using MovingPandas

Full Google Scholar list

Platforms using MovingPandas

Teaching materials referencing MovingPandas

Workshop videos

WorkshopVideo ogh2023

movingpandas's People

Contributors

anitagraser avatar apulverizer avatar astrojuanlu avatar bamacgabhann avatar boiko avatar brl0 avatar eumiro avatar gaspardmerten avatar giorgostheo avatar git-it avatar gprichter avatar javibecerra avatar jgaboardi avatar loic5 avatar lucadelu avatar m-kuhn avatar martinfleis avatar menegon avatar naarlack avatar ocefpaf avatar parnelandr avatar radical-squared avatar rahfar avatar raybellwaves avatar renegaderyu avatar rlukevie avatar robinlovelace avatar sglvladi avatar snelmes avatar stfnj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

movingpandas's Issues

Should functions clean up temporary df columns?

Currently, functions such as __str__() and plot() add columns to the Trajectory.df. Should functions have to clean up after themselves? Or is it better to keep these columns once they have been calculated to avoid having to recompute them again and again?

Making a conda-forge package?

I saw on twitter you released on PyPI (congrats!), so was thinking it would be good to have a conda-forge package so people can install it more easily with the rest of the geospatial stack provided by conda-forge?

For a pure python package, it is relatively easy to add a package (creating a PR at https://github.com/conda-forge/staged-recipes/). But gladly to help with that if you have any problems.

Division by zero in get_position_at

Interpolated method fails if provided timestamp equals an exiting node:

df = pd.DataFrame([
  {'geometry':Point(0,0), 't':datetime(2018,1,1,12,0,0)},
  {'geometry':Point(6,0), 't':datetime(2018,1,1,12,6,0)},
  {'geometry':Point(6,6), 't':datetime(2018,1,1,12,10,0)},
  {'geometry':Point(9,9), 't':datetime(2018,1,1,12,15,0)}
]).set_index('t')
geo_df = GeoDataFrame(df, crs={'init': '31256'})
traj = Trajectory(1,geo_df)
traj.get_position_at(datetime(2018,1,1,12,6,0), method='interpolated')    

Support raster value sampling

For example, it might be interesting to support sampling of average temperature rasters along the trajectory and to store an aggregate for the segment.

How to install movingpandas?

Hi,

I am still new with python and am a bit confused. The trajectory.py code has a line

import movingpandas as mp

how exactly do I install movingpandas? I have downloaded a clone of the files and can't seem to install it.

Thanks for any help!

Hvplot: No response Kernal Die in both Jupyter Notebook and Spyder

I am implementing the DBSCAN on my vehicle tracking data, where after converting the all data into individual trajectories i used your DBSCAN code for clustering, but when i start running the .hvplot method it exit without showing any output (Spyder) or kernal will start automatically (Jupyter Notebook). The issue is not specific to just DBSCAN, but whenever i start using hvplot it gives me no response.Need your help in this issue. Thank you

Implement trajectory distance measures

Useful distance measures include but are not limited to:

For more details, see Zheng & Zhou (2011) who distinguish global and local distance measures:

  • Euclidean distance
  • Alignment-based distance (incl dynamic time warping)
  • MBR-based distance
  • Trajectory-Hausdorff distance
  • Trajectory-segment distance

Others mentioned by Pelekis & Theodoridis (2016)

  • DISSIM (extension of Euclidean distance)
  • Earth Movers Distance (EMD)
  • TRACLUS

References

  • Zheng, Y., & Zhou, X. (Eds.). (2011). Computing with Spatial Trajectories. doi:10.1007/978-1-4614-1629-6
  • Pelekis, N., & Theodoridis Y. (2016). Mobility Data Management & Exploration. Presentation of the Data Science Lab, University of Piraeus, Greece.

Installing issue

Hello,

I'm using Windows 10 with Python 3.7 via Anaconda (Using the February 2020 edition from their website). When I try to use the conda install method for movingpandas, I get a series of errors that say that the specifications are incompatible with the existing python installation (See below image). Is there anything I'm missing/not doing right?

Python error screenshot

Columns other than "t" do not work when adding speed

It looks like there's some hard-coded stuff related to the time column.

This modified example from the tutorial highlights it.

import pandas as pd
import geopandas as gpd
import movingpandas as mpd
from shapely.geometry import Point
from datetime import datetime
from fiona.crs import from_epsg

CRS_METRIC = from_epsg(31256)

df = pd.DataFrame([
  {'geometry':Point(0,0), 'time':datetime(2018,1,1,12,0,0)},
  {'geometry':Point(6,0), 'time':datetime(2018,1,1,12,6,0)},
  {'geometry':Point(6,6), 'time':datetime(2018,1,1,12,10,0)},
  {'geometry':Point(9,9), 'time':datetime(2018,1,1,12,15,0)}
]).set_index('time')
geo_df = gpd.GeoDataFrame(df, crs=CRS_METRIC)
toy_traj = mpd.Trajectory(geo_df, 1)
toy_traj.add_speed(overwrite=True)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-25-c9bc7cc01417> in <module>
----> 1 traj.add_speed(overwrite=True)
      2 traj.df

~/anaconda3/envs/experiment/lib/python3.7/site-packages/movingpandas/trajectory.py in add_speed(self, overwrite)
    568         if SPEED_COL_NAME in self.df.columns and not overwrite:
    569             raise RuntimeError('Trajectory already has speed values! Use overwrite=True to overwrite exiting values.')
--> 570         self.df = self._get_df_with_speed()
    571 
    572     def _get_df_with_speed(self):

~/anaconda3/envs/experiment/lib/python3.7/site-packages/movingpandas/trajectory.py in _get_df_with_speed(self)
    576             times = temp_df.t
    577         else:
--> 578             times = temp_df.reset_index().t
    579         temp_df = temp_df.assign(delta_t=times.diff().values)
    580         try:

~/anaconda3/envs/experiment/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5272             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5273                 return self[name]
-> 5274             return object.__getattribute__(self, name)
   5275 
   5276     def __setattr__(self, name: str, value) -> None:

AttributeError: 'GeoDataFrame' object has no attribute 't'

Changing the column from time back to t resolves the issue but that's less than ideal when pulling in data from other sources.

Does 0.1.dev2 from conda-forge include TrajectoryManager?

Sad error here.
Clean install into dedicated environment on Windows 10.
environment.yml records version as

movingpandas=0.1.dev2=py37h39e3cac_0

When trying to use the TrajectoryManager class from the tutorial it fails saying the module has no such attribute.

I can't see any releases on github so wondered if conda has lagged behind github?

Trajectory.get_linestring_between() needs more parameters to use Trajectory._make_line()

The Trajectory.get_linestring_between() method asks for two datetime objects as parameters and tries the Trajectory._make_line() method with the Trajectory.get_segment_between() method.

However, Trajectory._make_line() is expecting a DataFrame that has a length but is receiving a trajectory.Trajectory object that doesn't have a length from the Trajectory.get_segment_between() method.

The error received is - TypeError: object of type 'Trajectory' has no len()

CRSError is df does not have crs

In case of creating Trajectory from GeoDataFrame without set CRS, it fails. As you moved CRS check to init, it now fails during the creation, before it failed once is_latlon() was called, so no big difference.

df = pd.DataFrame([
  {'geometry':Point(0,0), 't':datetime(2018,1,1,12,0,0)},
  {'geometry':Point(6,0), 't':datetime(2018,1,1,12,6,0)},
  {'geometry':Point(6,6), 't':datetime(2018,1,1,12,10,0)},
  {'geometry':Point(9,9), 't':datetime(2018,1,1,12,15,0)}
]).set_index('t')
geo_df = GeoDataFrame(df)
toy_traj = mpd.Trajectory(geo_df, 1)

It might be expected behaviour not to allow Trajectory without set CRS. If so, I would check for missing CRS and raise more informative error. Alternatively you can assume lat-lon and raise a warning that this assumption is there.

Current CRSError: Invalid CRS input: None is quite easy to understand unlike previous TypeError: ("'NoneType' object is not subscriptable", 'occurred at index 2018-01-01 12:06:00'), but it could be pointing to a specific reason and a solution.

cc pyOpenSci/software-submission#18

relationship to scikit-mobility

Hi, thanks for putting this package together! Seems pretty great.

I'm curious about the overall scope and goals of the project. The emphasis on pandas suggests this library is about providing fundamental data structures for data spatio-temporal data analysis. By contrast, the folks over at scikit-mobility seem to have implemented similar data structures, but afaict their emphasis is on modeling flows (hence the emphasis on scikit rather than pandas). There may be some differences in the implementations if they support different goals, but since both of these prominent packages are defining a specification for a space-time geodataframe that could become the defacto standard, I'm curious if there's an opportunity for these packages to speak to one another?

'NoneType' object has no attribute 'is_ccw'

Crashing while trying to hvplot a TrajectoryCollection. The DataFrame under one of the trajectory is the following:

geometry	trajectory_id
t		
2007-05-03 00:59:08	POINT (28.918 118.052)	0
2007-05-03 01:02:54	POINT (28.918 118.052)	0
2007-05-03 01:03:24	POINT (28.918 118.052)	0
2007-05-03 01:07:03	POINT (28.918 118.053)	0
2007-05-03 01:08:40	POINT (28.918 118.053)	0
...	...	...
2007-05-03 05:07:57	POINT (28.903 118.062)	0
2007-05-03 05:08:08	POINT (28.903 118.062)	0
2007-05-03 05:08:27	POINT (28.903 118.062)	0
2007-05-03 05:08:44	POINT (28.903 118.062)	0
2007-05-03 05:11:19	POINT (28.903 118.062)	0
~/.local/lib/python3.7/site-packages/cartopy/crs.py in _project_polygon(self, polygon, src_crs)
    352             is_ccw = True
    353         else:
--> 354             is_ccw = polygon.exterior.is_ccw
    355         # Project the polygon exterior/interior rings.
    356         # Each source ring will result in either a ring, or one or more

AttributeError: 'NoneType' object has no attribute 'is_ccw'

[pyopensci-review] Tutorial 1: AttributeError: 'GeoDataFrame' object has no attribute 'as_matrix'

Tutorial 1, on binder, the input number 30:

origins['lat'] = origins.geometry.y
origins['lon'] = origins.geometry.x
matrix = origins.as_matrix(columns=['lat', 'lon'])

is raising the follow error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-30-c2a4f564a8ef> in <module>
      1 origins['lat'] = origins.geometry.y
      2 origins['lon'] = origins.geometry.x
----> 3 matrix = origins.as_matrix(columns=['lat', 'lon'])

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5271             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5272                 return self[name]
-> 5273             return object.__getattribute__(self, name)
   5274 
   5275     def __setattr__(self, name: str, value) -> None:

AttributeError: 'GeoDataFrame' object has no attribute 'as_matrix'

ref: pyOpenSci/software-submission#18

ValueError: The truth value of a GeoDataFrame is ambiguous.

I'm trying to follow the ship data tutorial, using another historical dataset on voyages of sail ships.
This is my notebook:
https://gist.github.com/FrieseWoudloper/6423a4bc55b9019540ae1aafef5844ab
Everything seems to work fine, however when I try to plot an inidividual trajectory using hvplot() I get an error message:
ValueError: The truth value of a GeoDataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I installed the latest available versions of geopandas, movingpandas and hvplot using conda-forge (respectively 0.6.3, 0.2rc1, and 0.5.2).

Known Rasterio Issue

I noticed this in your known issues:
On Windows, importing rasterio can lead to DLL errors. If this happens, downgrade the rasterio version to 1.0.13.

I was having a similar problem and I found that by import gdal before rasterio, this went away. GDAL is required by raterio anyway, but seems help rasterio find the correct DLLs.

Just a suggestion to try in case you need newer version of rasterio.

Missing badges

Necessary missing badges for pyOpenSci review:

  • Code coverage
  • pyOpenSci peer-review
  • repostatus.org

Change from checking with `type()` to `isinstance()`

I was trying to figure out why my data was not plotting or showing correct distances for trajectories.

The issue seems to be all of the statements like:
https://github.com/anitagraser/movingpandas/blob/90b3e810a79598407954796e195e760d99c021a2/movingpandas/trajectory.py#L445

The problem is this doesn't account for when something is sub-classed. In my example the points in the geodataframe are all actually PointAdapter which is sub-classing the Point class.

So in my case, the existing type checking was incorrectly flagging it as not a point. The solution is to use isinstance method throughout the code base.

if not isinstance(pt0, Point):
    return 0.0

I did this in a few spots and it was working as expected.

Installation instructions

Hi,
this is a part of pyOpenSci/software-submission#18.

Naive installation
As a naive user, if I make a new python environment and do pip install movingpandas, the installation fails on Mac.

Collecting movingpandas
  Downloading movingpandas-0.2rc1.tar.gz (20 kB)
Collecting numpy
  Downloading numpy-1.18.1-cp38-cp38-macosx_10_9_x86_64.whl (15.2 MB)
     |████████████████████████████████| 15.2 MB 5.2 MB/s 
Collecting matplotlib
  Downloading matplotlib-3.1.2-cp38-cp38-macosx_10_9_x86_64.whl (13.2 MB)
     |████████████████████████████████| 13.2 MB 4.1 MB/s 
Collecting shapely
  Using cached Shapely-1.6.4.post2.tar.gz (225 kB)
Collecting pandas
  Using cached pandas-0.25.3-cp38-cp38-macosx_10_9_x86_64.whl (10.3 MB)
Collecting geopandas
  Using cached geopandas-0.6.2-py2.py3-none-any.whl (919 kB)
Collecting hvplot
  Downloading hvplot-0.5.2-py2.py3-none-any.whl (2.5 MB)
     |████████████████████████████████| 2.5 MB 4.5 MB/s 
Collecting cartopy
  Using cached Cartopy-0.17.0.tar.gz (8.9 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/martin/anaconda3/envs/movingpandas/bin/python /Users/martin/anaconda3/envs/movingpandas/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /var/folders/d0/qyf0yvzd0n9ctn2wr3r4l1vw0000gn/T/tmpcf10m5i7
       cwd: /private/var/folders/d0/qyf0yvzd0n9ctn2wr3r4l1vw0000gn/T/pip-install-9up68k4a/cartopy
  Complete output (1 lines):
  Proj 4.9.0 must be installed in Conda environment "movingpandas".
  ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/martin/anaconda3/envs/movingpandas/bin/python /Users/martin/anaconda3/envs/movingpandas/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /var/folders/d0/qyf0yvzd0n9ctn2wr3r4l1vw0000gn/T/tmpcf10m5i7 Check the logs for full command output.

Using conda install -c anitagraser movingpandas works, but you'll get a mixture of channels (conda-forge and defaults), which is known to cause issues. Moreover, you get geopandas from defaults in older version that is on conda-forge.

It is worth documenting possible issues and workarounds (strict channel priority) as the default installation instructions do not follow GeoPandas recommendations.

Dev installation

Current dev installation instructions expect using Anaconda. I'd say that most dev people will just make a new environment using conda env create -f environment.yml, but it has to be derived from the Aanconda instructions. I'd just add a sentence saying that dev env should use environment.yml and keep Anaconda instructions as one of the options only.

Minor question - conda installs movingpandas 0.1.dev2, while the review issue says Version submitted: 0.2. Should I assume that 0.2 will be released after the review?

setup of environment: dependency issues

The bokeh update from 1.4.0 to 2.0.0 causes issues (I suppose a problem of hvplot).
Therefore, I get an error when running the 0_getting_started.ipynb notebook.
(bokeh.plotting.helpers not found) -> was removed in 2.0.0

Manually downgrading to bokeh=1.4.0 or specifying bokeh=1.4.0 in the environment.yml fixed the issue.

Use Geopy to compute distances

Shapely does not support coordinate system transformations. All operations on two or more features presume that the features exist in the same Cartesian plane.
https://shapely.readthedocs.io/en/stable/manual.html#coordinate-systems

Geopy can calculate geodesic distance between two points using the geodesic distance or the great-circle distance, with a default of the geodesic distance available as the function geopy.distance.distance.
https://geopy.readthedocs.io/en/stable/#module-geopy.distance

TrajectoryCollection.plot ignores some kwargs

TrajectoryCollection.plot() ignores some kwargs which should be passed to GeoDataFrame.plot(), like figsize.

While Trajectory.plot(figsize=(12, 12)) works as expected, TrajectoryCollection.plot(figsize=(12, 12)) ignores figsize. I am not sure what is the intention here, if all kwargs should go to gdf.plot() or just a selection, but difference in behaviour between Trajectory and TrajectoryCollection is unexpected.

cc pyOpenSci/software-submission#18

Trajectory.plot does not work with geometry columns not named "geometry"

It looks like the plotting method(s) assume the geometry column is named geometry. Geopandas supports any column name and that name can be accessed like geo_df.geometry.name

Code to reproduce:

import pandas as pd
import geopandas as gpd
import movingpandas as mpd
from shapely.geometry import Point
from datetime import datetime
from fiona.crs import from_epsg

CRS_METRIC = from_epsg(31256)

df = pd.DataFrame([
  {'shape':Point(0,0), 'time':datetime(2018,1,1,12,0,0)},
  {'shape':Point(6,0), 'time':datetime(2018,1,1,12,6,0)},
  {'shape':Point(6,6), 'time':datetime(2018,1,1,12,10,0)},
  {'shape':Point(9,9), 'time':datetime(2018,1,1,12,15,0)}
]).set_index('time')
geo_df = gpd.GeoDataFrame(df, geometry='shape', crs=CRS_METRIC)
toy_traj = mpd.Trajectory(geo_df, 1)
toy_traj.plot()
Stack Trace:
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/anaconda3/envs/experiment/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2645             try:
-> 2646                 return self._engine.get_loc(key)
   2647             except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'geometry'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-5-c8305ed7f723> in <module>
     16 geo_df = gpd.GeoDataFrame(df, geometry='shape', crs=CRS_METRIC)
     17 toy_traj = mpd.Trajectory(geo_df, 1)
---> 18 toy_traj.plot()

~/anaconda3/envs/experiment/lib/python3.7/site-packages/movingpandas/trajectory.py in plot(self, *args, **kwargs)
    122         >>> trajectory.plot(column='speed', legend=True, figsize=(9,5))
    123         """
--> 124         return _TrajectoryPlotter(self, *args, **kwargs).plot()
    125 
    126     def hvplot(self, *args, **kwargs):

~/anaconda3/envs/experiment/lib/python3.7/site-packages/movingpandas/trajectory_plotter.py in plot(self)
     73         if not self.ax:
     74             self.ax = plt.figure(figsize=self.figsize).add_subplot(1, 1, 1)
---> 75         ax = self._plot_trajectory(self.data)
     76         self.kwargs['legend'] = False  # has to be removed after the first iteration, otherwise we get multiple legends!
     77         self.kwargs.pop('column', None)  # has to be popped, otherwise there's an error in the following plot call if we don't remove column from kwargs

~/anaconda3/envs/experiment/lib/python3.7/site-packages/movingpandas/trajectory_plotter.py in _plot_trajectory(self, traj)
     45 
     46     def _plot_trajectory(self, traj):
---> 47         temp_df = self._make_line_df(traj)
     48         if self.column and self.column_to_color:
     49             try:

~/anaconda3/envs/experiment/lib/python3.7/site-packages/movingpandas/trajectory_plotter.py in _make_line_df(self, traj)
     40                 temp.add_speed(overwrite=True)
     41 
---> 42         line_gdf = temp._to_line_df().drop(['geometry', 'prev_pt'], axis=1)
     43         line_gdf = line_gdf.rename(columns={'line': 'geometry'}).set_geometry('geometry')
     44         return line_gdf

~/anaconda3/envs/experiment/lib/python3.7/site-packages/movingpandas/trajectory.py in _to_line_df(self)
    874     def _to_line_df(self):
    875         line_df = self.df.copy()
--> 876         line_df['prev_pt'] = line_df['geometry'].shift()
    877         line_df['t'] = self.df.index
    878         line_df['prev_t'] = line_df['t'].shift()

~/anaconda3/envs/experiment/lib/python3.7/site-packages/geopandas/geodataframe.py in __getitem__(self, key)
    574         GeoDataFrame.
    575         """
--> 576         result = super(GeoDataFrame, self).__getitem__(key)
    577         geo_col = self._geometry_column_name
    578         if isinstance(key, str) and key == geo_col:

~/anaconda3/envs/experiment/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self, key)
   2798             if self.columns.nlevels > 1:
   2799                 return self._getitem_multilevel(key)
-> 2800             indexer = self.columns.get_loc(key)
   2801             if is_integer(indexer):
   2802                 indexer = [indexer]

~/anaconda3/envs/experiment/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2646                 return self._engine.get_loc(key)
   2647             except KeyError:
-> 2648                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   2649         indexer = self.get_indexer([key], method=method, tolerance=tolerance)
   2650         if indexer.ndim > 1 or indexer.size > 1:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'geometry'

Workaround:

geo_df.rename_geometry('geometry', inplace=True) 

[pyopensci-review] Pip installation issue

Currently the pip installation is raising the follow error:

21:09 $ pip install movingpandas
ERROR: Could not find a version that satisfies the requirement movingpandas (from versions: none)
ERROR: No matching distribution found for movingpandas

Change get_linestring_between(self, t1, t2) to interpolate by default

Temporal access function such as, e.g. get_position_at(self, t, method='nearest') currently return the position that is closest to the given timestamp. They do not interpolate positions.

https://github.com/anitagraser/movingpandas/blob/18b42ffea1821d4f3ff543c6674d220d38fa85b5/trajectory.py#L116

On the other hand, geographic access functions, such as clip(self, polygon, pointbased=False) - by default - perform interpolation.

https://github.com/anitagraser/movingpandas/blob/18b42ffea1821d4f3ff543c6674d220d38fa85b5/trajectory.py#L218

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.