Skip to main content
Tweeted twitter.com/StackGIS/status/1335328121780834305
corrected spelling
Source Link
nmtoken
  • 13.6k
  • 5
  • 38
  • 89

How to extract long and lat from geometry column in geopandasGeoPandas?

I read a shape fileshapefile with geopandasGeoPandas and I get a nice table with a column "geometry". This column contains shapely.geometry.polygon.Polygon or shapely.geometry.multipolygon.MultiPolygon object.

import geopandas as gpd
gdf = gpd.GeoDataFrame.from_file("ashapefile.shp")

Now I would like to use this geoDataFrame to make such as a chloropeth plot or something else. Thus I would like to get the (x, y) coordinates, (latitude, longitude) of these polygons.

For example if I do :

for boundary in gdf.boundary:
    print(boundary.xy)

Thus boundary are shapely.geometry.linestring.LineString or MultiLineString. boundary.xy are what I am looking for. But for MultilineString I have to do a loop on all the line.

Is there the way to do that ? Or is there a more simple or straightforward way ?

EDIT : Issue with unary_union:

enter image description hereIssue with unary_union

How to extract long and lat from geometry column in geopandas?

I read a shape file with geopandas and I get a nice table with a column "geometry". This column contains shapely.geometry.polygon.Polygon or shapely.geometry.multipolygon.MultiPolygon object.

import geopandas as gpd
gdf = gpd.GeoDataFrame.from_file("ashapefile.shp")

Now I would like to use this geoDataFrame to make such as a chloropeth plot or something else. Thus I would like to get the (x, y) coordinates, (latitude, longitude) of these polygons.

For example if I do :

for boundary in gdf.boundary:
    print(boundary.xy)

Thus boundary are shapely.geometry.linestring.LineString or MultiLineString. boundary.xy are what I am looking for. But for MultilineString I have to do a loop on all the line.

Is there the way to do that ? Or is there a more simple or straightforward way ?

EDIT : Issue with unary_union:

enter image description here

How to extract long and lat from geometry column in GeoPandas?

I read a shapefile with GeoPandas and I get a nice table with a column "geometry". This column contains shapely.geometry.polygon.Polygon or shapely.geometry.multipolygon.MultiPolygon object.

import geopandas as gpd
gdf = gpd.GeoDataFrame.from_file("ashapefile.shp")

Now I would like to use this geoDataFrame to make such as a chloropeth plot or something else. Thus I would like to get the (x, y) coordinates, (latitude, longitude) of these polygons.

For example if I do :

for boundary in gdf.boundary:
    print(boundary.xy)

Thus boundary are shapely.geometry.linestring.LineString or MultiLineString. boundary.xy are what I am looking for. But for MultilineString I have to do a loop on all the line.

Is there the way to do that ? Or is there a more simple or straightforward way ?

EDIT : Issue with unary_union:

Issue with unary_union

added 126 characters in body
Source Link
Ger
  • 279
  • 1
  • 2
  • 7

I read a shape file with geopandas and I get a nice table with a column "geometry". This column contains shapely.geometry.polygon.Polygon or shapely.geometry.multipolygon.MultiPolygon object.

import geopandas as gpd
gdf = gpd.GeoDataFrame.from_file("ashapefile.shp")

Now I would like to use this geoDataFrame to make such as a chloropeth plot or something else. Thus I would like to get the (x, y) coordinates, (latitude, longitude) of these polygons.

For example if I do :

for boundary in gdf.boundary:
    print(boundary.xy)

Thus boundary are shapely.geometry.linestring.LineString or MultiLineString. boundary.xy are what I am looking for. But for MultilineString I have to do a loop on all the line.

Is there the way to do that ? Or is there a more simple or straightforward way ?

EDIT : Issue with unary_union:

enter image description here

I read a shape file with geopandas and I get a nice table with a column "geometry". This column contains shapely.geometry.polygon.Polygon or shapely.geometry.multipolygon.MultiPolygon object.

import geopandas as gpd
gdf = gpd.GeoDataFrame.from_file("ashapefile.shp")

Now I would like to use this geoDataFrame to make such as a chloropeth plot or something else. Thus I would like to get the (x, y) coordinates, (latitude, longitude) of these polygons.

For example if I do :

for boundary in gdf.boundary:
    print(boundary.xy)

Thus boundary are shapely.geometry.linestring.LineString or MultiLineString. boundary.xy are what I am looking for. But for MultilineString I have to do a loop on all the line.

Is there the way to do that ? Or is there a more simple or straightforward way ?

I read a shape file with geopandas and I get a nice table with a column "geometry". This column contains shapely.geometry.polygon.Polygon or shapely.geometry.multipolygon.MultiPolygon object.

import geopandas as gpd
gdf = gpd.GeoDataFrame.from_file("ashapefile.shp")

Now I would like to use this geoDataFrame to make such as a chloropeth plot or something else. Thus I would like to get the (x, y) coordinates, (latitude, longitude) of these polygons.

For example if I do :

for boundary in gdf.boundary:
    print(boundary.xy)

Thus boundary are shapely.geometry.linestring.LineString or MultiLineString. boundary.xy are what I am looking for. But for MultilineString I have to do a loop on all the line.

Is there the way to do that ? Or is there a more simple or straightforward way ?

EDIT : Issue with unary_union:

enter image description here

Source Link
Ger
  • 279
  • 1
  • 2
  • 7

How to extract long and lat from geometry column in geopandas?

I read a shape file with geopandas and I get a nice table with a column "geometry". This column contains shapely.geometry.polygon.Polygon or shapely.geometry.multipolygon.MultiPolygon object.

import geopandas as gpd
gdf = gpd.GeoDataFrame.from_file("ashapefile.shp")

Now I would like to use this geoDataFrame to make such as a chloropeth plot or something else. Thus I would like to get the (x, y) coordinates, (latitude, longitude) of these polygons.

For example if I do :

for boundary in gdf.boundary:
    print(boundary.xy)

Thus boundary are shapely.geometry.linestring.LineString or MultiLineString. boundary.xy are what I am looking for. But for MultilineString I have to do a loop on all the line.

Is there the way to do that ? Or is there a more simple or straightforward way ?