L Blauw
L Blauw

Reputation: 1

Geopandas: dataframe to geodataframe with different espg code

I have a dataframe (df2): wherein x,y are specified in rd new epsg:28992 coordinates.

            x           y      z     batch_nr  batch_description
0  117298.377  560406.392  0.612         5800   PRF Grasland (l)
1  117297.803  560411.756  1.015                                
2  117296.327  560419.840  1.580                                
3  117295.470  560425.716  2.490                                
4  117296.875  560429.976  4.529

more CRS info:

# def CRS, used in geopandas
from pyproj import CRS
crs_rd = CRS.from_user_input(28992)
crs_rd
<Derived Projected CRS: EPSG:28992>
Name: Amersfoort / RD New
Axis Info [cartesian]:
- X[east]: Easting (metre)
- Y[north]: Northing (metre)
Area of Use:
- name: Netherlands - onshore, including Waddenzee, Dutch Wadden Islands and 12-mile offshore coastal zone.
- bounds: (3.2, 50.75, 7.22, 53.7)
Coordinate Operation:
- name: RD New
- method: Oblique Stereographic
Datum: Amersfoort
- Ellipsoid: Bessel 1841
- Prime Meridian: Greenwich

How can I convert df2 to a geodatafame where the geometry is set as CRS: EPSG 28992?

Upvotes: 0

Views: 374

Answers (1)

Rob Raymond
Rob Raymond

Reputation: 31226

It's a simple case of using GeoPandas constructor with crs parameter and points_from_xy()

import geopandas as gpd
import pandas as pd
import io

df2 = pd.read_csv(io.StringIO("""            x           y      z     batch_nr  batch_description
0  117298.377  560406.392  0.612         5800   PRF Grasland (l)
1  117297.803  560411.756  1.015                                
2  117296.327  560419.840  1.580                                
3  117295.470  560425.716  2.490                                
4  117296.875  560429.976  4.529"""), sep="\s\s+", engine="python")

gdf = gpd.GeoDataFrame(df2, geometry=gpd.points_from_xy(df2["x"], df2["y"], df2["z"]), crs="epsg:28992")

gdf

output

x y z batch_nr batch_description geometry
0 117298 560406 0.612 5800 PRF Grasland (l) POINT Z (117298.377 560406.392 0.612)
1 117298 560412 1.015 nan POINT Z (117297.803 560411.756 1.015)
2 117296 560420 1.58 nan POINT Z (117296.327 560419.84 1.58)
3 117295 560426 2.49 nan POINT Z (117295.47 560425.716 2.49)
4 117297 560430 4.529 nan POINT Z (117296.875 560429.976 4.529)

Upvotes: 2

Related Questions