1. Working with coordinate systems in GeoPandas
In the previous video, we have learned about geographic and projected coordinates, and that there are different projection systems. In this video, we will see more in depth why it is important to pay attention to this topic and how to handle it in practice with GeoPandas.
2. CRS information in GeoPandas
We have already seen how geopandas stores CRS information in the crs attribute of GeoDataFrames and GeoSeries: everything that is needed to position coordinates on Earth is stored as the proj4 string or dictionary.
If the file contains CRS information, this is read automatically.
3. Setting a CRS manually
If there is no information, but you know which CRS the data are expressed in, you can add it manually using any of the supported formats.
4. Transforming to another CRS
Once the CRS is set, we can easily convert a GeoDataFrame to a different coordinate system by using the to_crs method.
Similar to setting the original one, expressing a target CRS can be done with a proj4 string or dictionary.
Or, as a shortcut, we can also specify the EPSG number.
In the example, we read a file expressed in Web Mercator (the CRS used in many web mapping applications), and convert it into the WGS84 system by specifying the epsg number.
5. Why converting the CRS?
So that is how to convert to another coordinate reference system, but, in which cases is it important to do this?
First, if you are working with multiple datasets, they can come in different coordinate systems. If you want to use the data together, you need to make sure they are expressed in the same CRS. That can be done by converting them to a common CRS, or as shown here, by converting one geodataframe to the CRS of the other geodataframe.
6. Why converting the CRS?
Secondly, you need to be aware of the distortion you might have when naively plotting longitude and latitude degrees, since one degree of latitude is not the same size everywhere on earth as one degree of longitude.
In the example shown here, you see the effect of this for the USA.
In these cases, you might want to use a more appropriate CRS when visualizing a dataset.
7. Why converting the CRS?
Last, and very important, if your analysis requires distance or area based calculations, your data needs to be in an appropriate projected coordinate system to ensure they are computed correctly and expressed in a meaningful unit such as metres or feet.
All the calculations that happen in geopandas and shapely assume that your data is in a 2D cartesian plane, and thus the result of those calculations will only be correct if your data is properly projected.
8. How to choose which CRS to use?
What is such an appropriate reference system?
This depends on the analysis you want to do and the regional extent of the area you are working in.
It is hard to have a good projection for the full earth, as there will always be some distortion in distance, area or direction.
But it is easier to project a small area of the earth's surface with a good accuracy without much distortion.
Therefore, there are many coordinate reference systems that are optimized for a specific area, and will give only a limited distortion when used within that area.
Many countries define a standard CRS for that use case.
Further, here are two online resources that can help you find your ideal CRS.
9. Summary
In this video, we have seen the importance to be aware of the Coordinate reference system of your data, especially when doing distance based calculations, and we have seen the `to_crs` method to convert to another CRS.
10. Let's practice!
Let's now do some actual exercises on this, going back to the Paris datasets.