0
# Coordinate Transformations
1
2
Functions for transforming coordinates and geometries between different coordinate reference systems, essential for integrating data from different sources and projections.
3
4
## Capabilities
5
6
### Coordinate Transformation
7
8
Transform coordinate sequences between coordinate reference systems.
9
10
```python { .api }
11
def transform(src_crs, dst_crs, xs, ys):
12
"""
13
Transform coordinate sequences between CRS.
14
15
Parameters:
16
- src_crs: CRS or CRS-like, source coordinate reference system
17
- dst_crs: CRS or CRS-like, destination coordinate reference system
18
- xs: array-like, x coordinates (longitude or easting)
19
- ys: array-like, y coordinates (latitude or northing)
20
21
Returns:
22
tuple: (transformed_xs, transformed_ys) coordinate arrays
23
24
Raises:
25
- TransformError: If transformation fails
26
"""
27
```
28
29
### Geometry Transformation
30
31
Transform geometry objects between coordinate reference systems.
32
33
```python { .api }
34
def transform_geom(src_crs, dst_crs, geom, antimeridian_cutting=False, antimeridian_offset=10.0, precision=-1):
35
"""
36
Transform geometry objects between CRS.
37
38
Parameters:
39
- src_crs: CRS or CRS-like, source coordinate reference system
40
- dst_crs: CRS or CRS-like, destination coordinate reference system
41
- geom: dict, GeoJSON-like geometry object
42
- antimeridian_cutting: bool, cut geometries at antimeridian
43
- antimeridian_offset: float, offset for antimeridian cutting
44
- precision: int, coordinate precision (-1 for no rounding)
45
46
Returns:
47
dict: Transformed GeoJSON-like geometry
48
49
Raises:
50
- TransformError: If transformation fails
51
"""
52
```
53
54
#### Usage Examples
55
56
```python
57
from fiona.transform import transform, transform_geom
58
from fiona.crs import CRS
59
60
# Transform coordinate arrays
61
src_crs = CRS.from_epsg(4326) # WGS84
62
dst_crs = CRS.from_epsg(32610) # UTM Zone 10N
63
64
# San Francisco coordinates in WGS84
65
lons = [-122.4194]
66
lats = [37.7749]
67
68
# Transform to UTM
69
x_utm, y_utm = transform(src_crs, dst_crs, lons, lats)
70
print(f"UTM coordinates: {x_utm[0]:.2f}, {y_utm[0]:.2f}")
71
72
# Transform geometry objects
73
point_geom = {
74
'type': 'Point',
75
'coordinates': [-122.4194, 37.7749]
76
}
77
78
transformed_point = transform_geom(src_crs, dst_crs, point_geom)
79
print(f"Transformed point: {transformed_point}")
80
81
# Transform complex geometries
82
polygon_geom = {
83
'type': 'Polygon',
84
'coordinates': [[
85
[-122.5, 37.7], [-122.4, 37.7],
86
[-122.4, 37.8], [-122.5, 37.8],
87
[-122.5, 37.7]
88
]]
89
}
90
91
transformed_polygon = transform_geom(src_crs, dst_crs, polygon_geom)
92
```