mappymatch.constructs.trace#

Classes

Trace(frame)

A Trace is a collection of coordinates that represents a trajectory to be matched.

class mappymatch.constructs.trace.Trace(frame)[source]#

A Trace is a collection of coordinates that represents a trajectory to be matched.

Attributes:

coords: A list of all the coordinates crs: The CRS of the trace index: The index of the trace

Parameters:

frame (GeoDataFrame)

property index: Index#

Get index to underlying GeoDataFrame.

property coords: List[Coordinate]#

Get coordinates as Coordinate objects.

property crs: CRS#

Get Coordinate Reference System(CRS) to underlying GeoDataFrame.

classmethod from_geo_dataframe(frame, xy=True)[source]#

Builds a trace from a geopandas dataframe

Expects the dataframe to have geometry column

Return type:

Trace

Parameters:
  • frame (GeoDataFrame)

  • xy (bool)

Args:

frame: geopandas dataframe with _one_ trace xy: should the trace be projected to epsg 3857?

Returns:

The trace built from the geopandas dataframe

classmethod from_dataframe(dataframe, xy=True, lat_column='latitude', lon_column='longitude')[source]#

Builds a trace from a pandas dataframe

Expects the dataframe to have latitude / longitude information in the epsg 4326 format

Return type:

Trace

Parameters:
  • dataframe (DataFrame)

  • xy (bool)

  • lat_column (str)

  • lon_column (str)

Args:

dataframe: pandas dataframe with _one_ trace xy: should the trace be projected to epsg 3857? lat_column: the name of the latitude column lon_column: the name of the longitude column

Returns:

The trace built from the pandas dataframe

classmethod from_gpx(file, xy=True)[source]#

Builds a trace from a gpx file.

Expects the file to have simple gpx structure: a sequence of lat, lon pairs

Return type:

Trace

Parameters:
  • file (str | Path)

  • xy (bool)

Args:

file: the gpx file xy: should the trace be projected to epsg 3857?

Returns:

The trace built from the gpx file

classmethod from_csv(file, xy=True, lat_column='latitude', lon_column='longitude')[source]#

Builds a trace from a csv file.

Expects the file to have latitude / longitude information in the epsg 4326 format

Return type:

Trace

Parameters:
  • file (str | Path)

  • xy (bool)

  • lat_column (str)

  • lon_column (str)

Args:

file: the csv file xy: should the trace be projected to epsg 3857? lat_column: the name of the latitude column lon_column: the name of the longitude column

Returns:

The trace built from the csv file

classmethod from_parquet(file, xy=True)[source]#

Read a trace from a parquet file

Args:

file: the parquet file xy: should the trace be projected to epsg 3857?

Returns:

The trace built from the parquet file

Parameters:
  • file (str | Path)

  • xy (bool)

classmethod from_geojson(file, index_property=None, xy=True)[source]#

Reads a trace from a geojson file; If index_property is not specified, this will set any property columns as the index.

Args:

file: the geojson file index_property: the name of the property to use as the index xy: should the trace be projected to epsg 3857?

Returns:

The trace built from the geojson file

Parameters:
  • file (str | Path)

  • index_property (str | None)

  • xy (bool)

downsample(npoints)[source]#

Downsample the trace to a given number of points

Return type:

Trace

Parameters:

npoints (int)

Args:

npoints: the number of points to downsample to

Returns:

The downsampled trace

drop(index=typing.List)[source]#

Remove points from the trace specified by the index parameter

Return type:

Trace

Args:

index: the index of the points to drop (0 based index)

Returns:

The trace with the points removed

to_crs(new_crs)[source]#

Converts the crs of a trace to a new crs

Return type:

Trace

Parameters:

new_crs (CRS)

Args:

new_crs: the new crs to convert to

Returns:

A new trace with the new crs

to_geojson(file)[source]#

Write the trace to a geojson file

Args:

file: the file to write to

Parameters:

file (str | Path)