gps_data_analyzer.gps_data module

class gps_data_analyzer.gps_data.GpsPoints(*args, local_crs: int = None, x_col: str = None, y_col: str = None, z_col: str = None, time_col: str = None, time_sort: bool = True, **kwargs)

Bases: gps_data_analyzer.gps_data._GpsBase

Class to store GPS points with Z coordinates and timestamps.

_has_time = True
_has_z = True
class gps_data_analyzer.gps_data.PoiPoints(*args, local_crs: int = None, x_col: str = None, y_col: str = None, z_col: str = None, time_col: str = None, time_sort: bool = True, **kwargs)

Bases: gps_data_analyzer.gps_data._GpsBase

Class to store PoI points with only X and Y coordinates.

_has_time = False
_has_z = False
class gps_data_analyzer.gps_data._GpsBase(*args, local_crs: int = None, x_col: str = None, y_col: str = None, z_col: str = None, time_col: str = None, time_sort: bool = True, **kwargs)

Bases: geopandas.geodataframe.GeoDataFrame

Class to wrap a geopandas.GeoDataFrame and format it in order to store GPS points.

datetime_format

The format used to convert strings into timestamps.

Type

str

_default_input_crs

The default EPSG code of input data (only used when input_crs is None).

Type

int

_has_z

Indicate whether the Z coordinate must be considered or not.

Type

bool

_has_time

Indicate whether the timestamps must be considered or not.

Type

bool

_default_x_col

The default column name of input data that contains X coordinates (only used when x_col is None).

Type

str

_default_y_col

The default column name of input data that contains Y coordinates (only used when y_col is None).

Type

str

_default_z_col

The default column name of input data that contains Z coordinates (only used when z_col is None and _has_z is True).

Type

str

_default_time_col

The default column name of input data that contains timestamps (only used when time_col is None and _has_time is True).

Type

str

_default_dt_col

The default column name to store delta times (only used when _has_time is True).

Type

str

_default_dist_col

The default column name to store distances (only used when _has_time is True).

Type

str

_default_velocity_col

The default column name to store velocities (only used when _has_time is True).

Type

str

_use_haversine

Indicate whether the distance computations must use the Haversine formula or not.

Type

bool

Parameters
  • df (pandas.DataFrame) – The data that will be formatted and stored.

  • input_crs (int) – The EPSG code of the input data.

  • local_crs (int) – The EPSG code of the local projection to which the data will be transformed.

  • keep_cols (list of str) – The columns that should not be discarded.

  • x_col (str) – The name of the column that contains X coordinates.

  • y_col (str) – The name of the column that contains Y coordinates.

  • z_col (str) – The name of the column that contains Z coordinates.

  • time_col (str) – The name of the column that contains timestamps.

  • time_sort (bool) – Sort data by ascending time (only used when _has_time is True).

property _constructor

Used when a manipulation result has the same dimensions as the original.

_default_dist_col = 'dist'
_default_dt_col = 'dt'
_default_input_crs = 4326
_default_time_col = 'datetime'
_default_velocity_col = 'velocity'
_default_x_col = 'x'
_default_y_col = 'y'
_default_z_col = 'z'
classmethod _format_data(df: pandas.core.frame.DataFrame, x_col: str, y_col: str, z_col: str = None, time_col: str = None, time_sort: bool = True) → None

Format a pandas.DataFrame or geopandas.GeoDataFrame.

Parameters
  • df (pandas.DataFrame or geopandas.GeoDataFrame) – The object to format.

  • x_col (str) – The name of the column containing X or lon coordinates.

  • y_col (str) – The name of the column containing Y or lat coordinates.

  • z_col (str, optional) – The name of the column containing Z coordinates.

  • time_col (str, optional) – The name of the column containing timestamps.

  • keep_cols (list of str, optional) – The names of the columns that should be kept (all others will be discarded).

time_sort (bool): Sort data by ascending time (only used when _has_time is

True).

Note

The column containing timestamps can be either in string format (and should thus follow the format given by datetime_format) or in a subtype of numpy.datetime64.

Returns

The formatted data.

Return type

geopandas.GeoDataFrame

_has_time = False
_has_z = True
classmethod _normalize_data(df) → None

Conpute time delta between consecutive points (in s).

_return_attr(attr) → pandas.core.series.Series
_use_haversine = True
add_attribute(attr: pandas.core.series.Series, name: str = None) → None

Add a column to the internal geopandas.GeoDataFrame.

Parameters
  • attr (pandas.Series) – The column to add.

  • name (str, optional) – The name of the new attribute. If not provided, the name of the pandas.Series is used.

Note

The labels of the given pandas.Series must be the same as the ones of the internal geopandas.GeoDataFrame.

property base_columns
copy(deep: bool = False)

Return a copy of the current object.

Parameters

deep (bool) – Make a deep copy, including a copy of the data and the indices. With deep=False neither the indices nor the data are copied.

datetime_format = '%Y/%m/%d-%H:%M:%S'
drop_from_mask(mask: geopandas.geodataframe.GeoDataFrame) → int

Drop points contained in the given mask.

Parameters

mask (geopandas.GeoDataFrame) – The mask used to drop internal points.

Note

  • The mask must be a _GpsBase or geopandas.GeoDataFrame object.

  • If the mask has a radius column, it will be used and drop all points at a distance smaller than the radius values.

Returns

The number of dropped points.

Return type

int

equals(other: geopandas.geodataframe.GeoDataFrame) → bool

Test whether self and other contain the same elements.

Parameters

other (geopandas.GeoDataFrame) – The other object to be compared with self.

Note

The two objects are converted to geopandas.GeoDataFrame then they are

compared using the equals method.

Returns

True if all elements are the same in both objects, False otherwise.

Return type

bool

segments() → geopandas.geodataframe.GeoDataFrame

Build segments from the consecutive points.

Returns

A geopandas.GeoDataFrame containing the segments.

Return type

geopandas.GeoDataFrame

property t

Get timestamps if _has_time is True or the t column otherwise.

Returns

Timestamps.

Return type

pandas.Series

property x

Get X coordinates from the geometry.

Type

pandas.Series

property xy

Array with a (x,y) couple of each point.

Type

numpy.array

property y

Get Y coordinates from the geometry.

Type

pandas.Series

property z

Get Z coordinates if _has_z is True or the z column otherwise.

Returns

Z coordinates.

Return type

pandas.Series

gps_data_analyzer.gps_data._convert_time(series, format: str = '%Y/%m/%d-%H:%M:%S')

Convert a pandas.Series containing timestamps as strings.

Parameters
  • series (pandas.Series) – The timestamps given as strings.

  • format (str, optional) – The format used for conversion.

Returns

The timestamps converted in pandas.datetime.

Return type

pandas.Series

gps_data_analyzer.gps_data.concatenate(data_sets: list, crs: int = None) → gps_data_analyzer.gps_data.GpsPoints

Concatenate several data sets.

Parameters
  • data_sets (list) – A list of data sets.

  • crs (int) – The EPSG code to which the data sets will be projected.

Returns

The new data set.

gps_data_analyzer.gps_data.load_gps_points(path: str) → gps_data_analyzer.gps_data.GpsPoints

Load GpsPoints from a file.

Parameters

path (str) – The path to the file.

Returns

The data loaded.

Return type

GpsPoints

gps_data_analyzer.gps_data.load_poi_points(path: str) → gps_data_analyzer.gps_data.PoiPoints

Load PoiPoints from a file.

Parameters

path (str) – The path to the file.

Returns

The data loaded.

Return type

PoiPoints