latlon2epsg {GTFSwizard} | R Documentation |
Transform Spatial Data to a Local UTM Coordinate System
Description
The 'latlon2epsg' function determines the appropriate UTM (Universal Transverse Mercator) EPSG code for a given 'sf' object based on its centroid's latitude and longitude. It then transforms the object to the identified coordinate reference system (CRS).
Usage
latlon2epsg(sf_obj)
Arguments
sf_obj |
An 'sf' object representing spatial features. This object must have a valid CRS with latitude and longitude coordinates. |
Details
The function calculates the geographic centroid of the input spatial object and determines its latitude and longitude. Based on the latitude:
- Latitudes above 84°
The object is transformed to EPSG:3413 (North Pole).
- Latitudes below -80°
The object is transformed to EPSG:3031 (South Pole).
- Latitudes between -80° and 84°
The function calculates the UTM zone based on longitude and transforms the object to the appropriate UTM EPSG code (EPSG:326XX for the Northern Hemisphere, EPSG:327XX for the Southern Hemisphere).
Value
An 'sf' object transformed to the appropriate UTM coordinate reference system.
Note
The function requires that the input 'sf' object already has a valid CRS defined (e.g., WGS84).
See Also
[sf::st_transform()], [sf::st_centroid()], [sf::st_union()]
Examples
latlon2epsg(get_shapes_sf(for_bus_gtfs)$shapes)