mappymatch.constructs.coordinate#

Classes

Coordinate(coordinate_id, geom, crs)

Represents a single geographic coordinate point with a coordinate reference system (CRS).

class mappymatch.constructs.coordinate.Coordinate(coordinate_id: Any, geom: Point, crs: CRS)[source]#

Represents a single geographic coordinate point with a coordinate reference system (CRS).

A Coordinate is an immutable object that combines a spatial point geometry with its coordinate reference system, allowing for accurate coordinate transformations between different projection systems.

Attributes:

coordinate_id: The unique identifier for this coordinate (can be any hashable type) geom: The Shapely Point geometry representing the spatial location crs: The pyproj CRS (Coordinate Reference System) defining the coordinate space x: The x-coordinate value (longitude in lat/lon systems, easting in projected systems) y: The y-coordinate value (latitude in lat/lon systems, northing in projected systems)

Examples:
>>> from mappymatch.constructs.coordinate import Coordinate
>>> # Create a coordinate from latitude and longitude
>>> coord = Coordinate.from_lat_lon(40.7128, -74.0060)
>>> print(coord.x, coord.y)
-74.0060 40.7128
>>> # Transform to a different CRS (Web Mercator)
>>> web_mercator = coord.to_crs('EPSG:3857')
>>> print(web_mercator.crs.to_epsg())
3857
coordinate_id: Any#

Alias for field number 0

geom: Point#

Alias for field number 1

crs: CRS#

Alias for field number 2

classmethod from_lat_lon(lat: float, lon: float) Coordinate[source]#

Create a coordinate from latitude and longitude values in WGS84 (EPSG:4326).

This is a convenience method for creating coordinates from standard GPS coordinates. The resulting coordinate will use the LATLON_CRS (EPSG:4326) coordinate system.

Args:

lat: The latitude in decimal degrees (range: -90 to 90) lon: The longitude in decimal degrees (range: -180 to 180)

Returns:

A new Coordinate instance in EPSG:4326 CRS with no coordinate_id

Examples:
>>> # New York City coordinates
>>> nyc = Coordinate.from_lat_lon(40.7128, -74.0060)
>>> print(f"Lat: {nyc.y}, Lon: {nyc.x}")
Lat: 40.7128, Lon: -74.0060
property x: float#
property y: float#
to_crs(new_crs: Any) Coordinate[source]#

Transform this coordinate to a different coordinate reference system (CRS).

This method reprojects the coordinate geometry from its current CRS to the target CRS using pyproj transformations. If the target CRS is the same as the current CRS, the original coordinate is returned unchanged.

Args:
new_crs: The target CRS. Can be a pyproj.CRS object, an EPSG code as a string

(e.g., 'EPSG:4326'), an integer EPSG code, or any CRS format that pyproj.CRS() accepts

Returns:

A new Coordinate instance with transformed geometry in the target CRS. The coordinate_id is preserved from the original coordinate.

Raises:
ValueError: If the new_crs cannot be parsed into a valid CRS, or if the

transformation results in infinite coordinate values (indicating an invalid transformation)

Examples:
>>> # Transform from lat/lon to Web Mercator
>>> coord = Coordinate.from_lat_lon(40.7128, -74.0060)
>>> mercator_coord = coord.to_crs('EPSG:3857')
>>>
>>> # Transform using EPSG integer code
>>> utm_coord = coord.to_crs(32618)  # UTM Zone 18N