Skip to content

Commit

Permalink
ch06 corrections - reprojecting vector
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldorman committed Oct 7, 2023
1 parent b25999b commit 613d3c5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions 06-reproj.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -439,22 +439,22 @@ The last section, shows how to create custom map projections (@sec-custom-map-pr
@sec-spatial-class demonstrated how vector geometries are made-up of points, and how points form the basis of more complex objects such as lines and polygons.
Reprojecting vectors thus consists of transforming the coordinates of these points, which form the vertices of lines and polygons.

@sec-geometry-operations-on-projected-and-unprojected-data contains an example in which at least one `GeoDataFrame` object must be transformed into an equivalent object with a different CRS to calculate the distance between two objects.
@sec-geometry-operations-on-projected-and-unprojected-data contains an example in which at a `GeoDataFrame` had to be transformed into an equivalent object, with a different CRS, to calculate the distance between two objects:

```{python}
lnd_layer2 = lnd_layer.to_crs(27700)
```

Now that a transformed version of `lnd_layer` has been created, using the `.distance` method, the distance between the two representations of London can be found.
It may come as a surprise that `lnd_layer` and `lnd_layer2` are just over 2 km apart!
The difference in location between the two points is not due to imperfections in the transforming operation (which is in fact very accurate) but the low precision of the manually-created coordinates that created `lnd_layer` and `lnd_layer_proj`:
Now that a transformed version of `lnd_layer` has been created, using the `.distance` method, the distance between the two representations of London can be found:

```{python}
lnd_layer2.distance(lnd_layer_proj)
```

Functions for querying and reprojecting CRSs are demonstrated below with reference to `cycle_hire_osm`, a point layer that represents 'docking stations' where you can hire bicycles in London.
The CRS of `GeoSeries` and `GeoDataFrame` objects can be queried---as we learned in @sec-querying-and-setting-coordinate-systems set---using the `.crs` property and the `.set_crs` method, respectively.
It may come as a surprise that `lnd_layer` and `lnd_layer2` are just over 2 $km$ apart!
The difference in location between the two points is not due to imperfections in the transforming operation (which is in fact very accurate) but the low precision of the manually-created coordinates that created `lnd_layer` and `lnd_layer_proj`:

The CRS of `GeoSeries` and `GeoDataFrame` objects can be queried and set---as we learned in @sec-querying-and-setting-coordinate-systems---using the `.crs` property and the `.set_crs` method, respectively.
The output is printed as multiple lines of text containing information about the coordinate system:

```{python}
Expand All @@ -479,6 +479,7 @@ crs_lnd.to_epsg()
As mentioned in @sec-coordinate-reference-systems, WKT representation, accessible through `.to_wkt()` of the `crs_lnd` object is the ultimate source of truth.
This means that the outputs of the previous code chunk are queries from the WKT representation provided by PROJ, rather than inherent attributes of the object and its CRS.

Reprojecting to a different CRS is also demonstrated below using `cycle_hire_osm`, a point layer that represents 'docking stations' where you can hire bicycles in London.
The contents of the CRS object associated with a given geometry column is changed when the object's CRS is transformed.
In the code chunk below, we create a new version of `cycle_hire_osm` with a projected CRS:

Expand All @@ -487,7 +488,7 @@ cycle_hire_osm_projected = cycle_hire_osm.to_crs(27700)
cycle_hire_osm_projected.crs
```

The resulting object has a new CRS with an EPSG code 27700. But how to find out more details about this EPSG code, or any code?
The resulting object has a new CRS with an EPSG code `27700`. But how to find out more details about this EPSG code, or any code?
One option is to search for it online.
Another option is to create a standalone CRS object within the Python environment (using `pyproj.CRS.from_string` or `pyproj.CRS.from_epsg`, see @sec-coordinate-reference-systems), and then query its properties:

Expand All @@ -496,7 +497,7 @@ crs_lnd_new = pyproj.CRS.from_epsg(27700)
crs_lnd_new.name, crs_lnd_new.to_proj4(), crs_lnd_new.to_wkt()
```

The result shows that the EPSG code 27700 represents the British National Grid, a result that could have been found by searching online for "[EPSG 27700](https://www.google.com/search?q=CRS+27700)".
The result shows that the EPSG code `27700` represents the British National Grid, a result that could have been found by searching online for "[EPSG 27700](https://www.google.com/search?q=CRS+27700)".

## Reprojecting raster geometries {#sec-reprojecting-raster-geometries}

Expand Down

0 comments on commit 613d3c5

Please sign in to comment.