Convert the coordinates of a shapefile in Geopandas

江枫思渺然 提交于 2020-01-23 17:40:26

问题


I am new at spatial analysis, but I cant find this answer anywhere.

I have a list of post codes in CRS coordinates, latitude and longitude, and London's Boroughs shape file in OSN coordinates, and I would like to map them together, but this is what happens. This is the head of the postcodes

london_post_codes.head()
Out[81]:
postcode    latitude    longitude
0   WD6 1GS 51.658021   -0.255663
1   WD17 1LA    51.660366   -0.397525
2   WC2N 6LE    51.509413   -0.121676
3   WC2N 6NA    51.508363   -0.124454
4   WC2N 6ND    51.508216   -0.123829

while this is the shape file read in geopandas

borough = gpd.read_file('London_Borough_Excluding_MHW.shp')
borough.head()
borough.head()

NAME    GSS_CODE    geometry
0   Kingston upon Thames    E09000021   POLYGON ((516401.6 160201.8, 516407.3 160210.5...
1   Croydon E09000008   POLYGON ((535009.2 159504.7, 535005.5 159502, ...
2   Bromley E09000006   POLYGON ((540373.6 157530.4, 540361.2 157551.9...
3   Hounslow    E09000018   POLYGON ((521975.8 178100, 521967.7 178096.8, ...
4   Ealing  E09000009   POLYGON ((510253.5 182881.6, 510249.9 182886, ...

we can see how the coordinates of the polygons are different from those of the postcodes. I and when I plot them together I get

fig, ax = plt.subplots()
borough.plot(ax = ax)
borough = gpd.read_file('statistical-gis-boundaries-london/ESRI/London_Borough_Excluding_MHW.shp')
london_post_codes.plot(kind='scatter',s=10, x='longitude', y='latitude',ax=ax)

Any suggestions ?


回答1:


The solution is simply to change the CRS (Coordinate Reference System). These go by codes, which are called epsg. The lat/long CRS has a code of epsg=4326. Therefore

borough = gpd.read_file('London_Borough_Excluding_MHW.shp')
borough = borough.to_crs(epsg=4326)

and then the rest.



来源:https://stackoverflow.com/questions/47203938/convert-the-coordinates-of-a-shapefile-in-geopandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!