In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces GeoPandas how to achieve the coordinate reference system, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
02-coordinate reference system
Please see the source code here.
% matplotlib inlineimport pandas as pdimport geopandascountries = geopandas.read_file ("zip://data/ne_110m_admin_0_countries.zip") cities = geopandas.read_file ("zip://data/ne_110m_populated_places.zip") rivers = geopandas.read_file ("zip://data/ne_50m_rivers_lake_centerlines.zip") 2.1coordinate reference system
So far, we have used geometric data with specific coordinates without further wondering what these coordinates mean or how they are expressed.
* * coordinate reference system (CRS) * * Associates coordinates with specific locations on Earth
Detailed explanation of coordinate reference system: https://docs.qgis.org/2.8/en/docs/gentle_gis_introduction/coordinate_reference_systems.html
2.1.1 Geographic coordinate system
Latitude and longitude
For example, 48 °51 °N, 2 °17 °E
The most common types of coordinates are geographical coordinates, latitude and longitude to define the position of the earth relative to the equator and the prime meridian
With this coordinate system, we can easily specify any location on Earth, for example, in the Global Positioning system, if you look at the coordinates of a location on Google Maps, you will see latitude and longitude.
Note the use of (latitude, longitude) (lon,lat) in Python to represent geographic coordinates
Longitude: [- 180,180]
Latitude: [- 90,90]
2.1.2 projection coordinate system
The coordinates are usually in meters or feet.
Although the earth is a sphere, in fact we usually represent it on a plane, such as a map of life, or a map we make on a computer screen with Python
From three-dimensional earth to plane map is what we call projection.
We project the surface of the earth onto a 2D plane so that we can represent the position on the plane with Cartesian x and y coordinates. On this plane, we usually use units of length, such as meters, rather than degrees, which makes the analysis more convenient and effective.
However, it is important that the three-dimensional earth can never be rendered perfectly on a two-dimensional map, so the projection will inevitably introduce distortion. To minimize this error, there are different projection methods, each of which has specific advantages and disadvantages.
Some projection systems will try to maintain the area size of the geometry, such as Ebers area projection (Albers Equal Area). Other projection systems try to preserve the angle, such as the Mercator projection, but will see large deformations in the area. Every projection system always has some distortion of area, angle or distance.
AlbersEqualArea
Mercator
Robinson
Comparison between projection size and actual size
2.2 coordinate reference system in Python and GeoPandas
GeoDataFrame or GeoSeries has a .CRS property that holds (optional) the description of the geometric reference system:
Countries.crsName: WGS 84Axis Info [ellipsoidal]:-Lat [north]: Geodetic latitude (degree)-Lon [east]: Geodetic longitude (degree) Area of Use:- name: World- bounds: (- 180.0,-90.0, 180.0, 90.0) Datum: World Geodetic System 1984-Ellipsoid: WGS 84-Prime Meridian: Greenwich
As you can see, for the countries data frame, the EPSG 4326 / WGS84 lon/lat reference system is used, which is one of the most commonly used systems in the geographic coordinate system.
It uses coordinates as the degrees of latitude and longitude, as can be seen from the xUnix y label on the graph:
Countries.plot ()
The return value of the .crs property is a dictionary type, in which case it only indicates the EPSG code, but it can also contain the full proj4 string (in dictionary form)
Possible CRS expressions:
Proj4 string
For example: + proj=longlat + datum=WGS84 + no_defs or {'proj':' longlat', 'datum':' WGS84', 'no_defs': True}
EPSG code
For example: EPSG:4326 = WGS84 Geographic coordinate system (longitude, latitude)
Rich text (Well-Know-Text,WKT) representation (PROJ6 provides better support in the next version of GeoPandas)
For example: https://epsg.io/4326
On the backend, GeoPandas uses the pyproj/PROJ library to handle reprojection
More information: http://geopandas.readthedocs.io/en/latest/projections.html
2.3 Transformation of coordinate system
In GeoDataFrame, to_crs function is used to transform coordinate system.
For example, change the countries to the Mercator projection (http://epsg.io/3395):
# because Mercator projection cannot handle poles, remove Antarctic countries=countries [(countries ['name']! = "Antarctica")] countries_mercator=countries.to_crs (epsg=3395) # or use .to _ crs ({' init': 'epsg:3395'}) countries_mercator.plot ()
Pay attention to comparing the difference between the x and y axis scale here and the projection in the geographic coordinate system
2.4 reasons for using different CRS
Different source data with different CRS-> need to be converted to the same CRS
Df1 = geopandas.read_file (...) df2 = geopandas.read_file (...) df2 = df2.to_crs (df1.crs)
Map mapping (due to distortion of shape and distance)
Distance / area-based calculations-> ensure that the appropriate projection coordinate system is used in meaningful units, such as meters or feet (not degrees)
Note:
All calculations that occur on the surface assume that the data are on a 2D Cartesian plane, so the results of these calculations are correct only if the data are projected correctly.
2.5 practice
Using the Paris dataset again, so far, we have provided a suitable dataset in projection CRS for the exercise.
But the original data are actually geographic coordinates.
In the following exercise, we will start with the raw data
The original dataset, now available in the GeoJSON ("data/paris_districts.geojson") file of the geographic coordinate system
In order to convert to projection coordinates, we will use the French standard projection coordinate system, the RGF93 / Lambert-93 reference system, with the reference number EPSG:2154 (Belgium is Lambert 72 and EPSG is 31370).
2.5.1 exercise 1: project the GeoDataFrame
Read the regional dataset ("data/paris_districts.geojson") into the GeoDataFrame named districts
View the CRS properties of districts
Simple drawing of districts data sets
Calculate the area of all areas
Project the districts (EPSG:2154 is used in France) and call the new dataset districts_RGF93
Draw a similar districts_RGF93 diagram
Calculate the area of all areas again for districts_RGF93 (the result is now represented by m ²)
Districts=geopandas.read_file ("data/paris_districts.geojson") districts.crsName: WGS 84Axis Info [ellipsoidal]:-Lat [north]: Geodetic latitude (degree)-Lon [east]: Geodetic longitude (degree) Area of Use:- name: World- bounds: (- 180.0,-90.0, 180.0, 90.0) Datum: World Geodetic System 1984-Ellipsoid: WGS 84-Prime Meridian: Greenwichdistricts.plot (figsize=
Districts.geometry.area0 0.0001071 0.0000512 0.0000343 0.0000334 0.000023... 75 0.00015976 0.00009977 0.00018278 0.00019679 0.000256Length: 80, dtype: float64districts_RGF93=districts.to_crs (epsg=2154) districts_RGF93.plot (figsize= (12Co6))
Districts_RGF93.geometry.area0 8.690007e+051 4.124585e+052 2.736968e+053 2.694568e+054 1.880122e+05... 75 1.294988e+0676 8.065686e+0577 1.486971e+0678 1.599002e+0679 2.090904e+06Length: 80, dtype: float64
You can see that the area values of the same area are different under different coordinate systems.
In the 01-Geographic data introduction, we did an exercise to draw the location of the Paris cycling station and add a background map to it using the contextily package
Contextily "assumes that the data coordinate system is the network Mercator projection (Web Mercator projection), which is the system used by most web mapping services. In the first exercise, we provided the data in the appropriate CRS, so we don't need to care about this.
However, in general, the reference coordinate system of the data will not be the network Mercator projection (Web Mercator projection), so we must align them with the network background map ourselves.
2.5.2 exercise 2: project GeoDataFrame
Read the bicycle station data set (data/paris_bike_stations.geojson) into the GeoDataFrame named stations
Convert a stations dataset to a network Mercator projection (EPSG:3857) named stations_webmercator
Draw a map of the projected dataset (specify a marker size of 5) and add a background map using contextily
Stations=geopandas.read_file ('data/paris_bike_stations.geojson') stations_webmercator=stations.to_crs (epsg=3857) stations_webmercator.head ()
.dataframe tbody tr th:only-of-type {vertical-align: middle;}
.dataframe tbody tr th {vertical-align: top;}. Dataframe thead th {text-align: right;}
Name bike_stands available_bikes geometry 0 14002-RASPAIL QUINET 44 4 POINT (259324.887 6247620.771) 1 20503-COURS DE VINCENNES PYR É N É ES 21 3 POINT (267824.377 6249062.894) 2 20011-PYR É N ES-DAGORNO 21 0 POINT (267742.135 6250378.469) 3 31008-VINCENNES (MONTREUIL) 56 0 POINT (271326.638 6250750.824) 4 43006-MINIMES (VINCENNES) 28 27 POINT (270594.689 6248007.705)
Import contextily as ctxax = stations_webmercator.plot (figsize= (10, 10), markersize=5, alpha=0.5, edgecolor='k') ctx.add_basemap (ax, source=ctx.providers.Stamen.TonerLite) Thank you for reading this article carefully. I hope the article "how to implement the coordinate reference system in GeoPandas" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.