alex_bn_lee

导航

【847】create geoDataFrame from dataframe

Ref: From WKT format

Firstly, we already have a dataframe, and there is a column of geometry. But this column is in the format of the string, therefore, we should change the data format from the string to the polygon.

There are two ways to implement this method.

The first method,

df = pd.DataFrame(
    {
        "City": ["Buenos Aires", "Brasilia", "Santiago", "Bogota", "Caracas"],
        "Country": ["Argentina", "Brazil", "Chile", "Colombia", "Venezuela"],
        "Coordinates": [
            "POINT(-58.66 -34.58)",
            "POINT(-47.91 -15.78)",
            "POINT(-70.66 -33.45)",
            "POINT(-74.08 4.60)",
            "POINT(-66.86 10.48)",
        ],
    }
)

from shapely import wkt

df["Coordinates"] = wkt.loads(df["Coordinates"])

gdf = geopandas.GeoDataFrame(df, geometry="Coordinates")

The second method,

df["Coordinates"] = geopandas.GeoSeries.from_wkt(df["Coordinates"])

gdf = geopandas.GeoDataFrame(df, geometry="Coordinates")

 

posted on 2023-06-30 08:54  McDelfino  阅读(23)  评论(0)    收藏  举报