3

I have a geopandas Dataframe with one GeoSeries.

There is only one entry for this column, a shapely.geometry.linestring.LineString.

LineString (first_lon first_lat, second_lon second_lat, ...)

I could not find an easy way to get the coordinates of this LineString as a DataFrame like

LON           LAT
first_lon     first_LAT
second_lon    second_LAT
...

Is there a build in function for this?

Thx

1 Answer 1

5
x,y = LineStringObject.coords.xy
pd.DataFrame(list(zip(x,y)), columns=['LAT', 'LON'])

seem to do the job ok.

[EDIT]

x,y = LineStringObject.coords.xy
pd.DataFrame({'LAT':x,'LON':y})
2
  • Wouldn't this work just fine without the list() ? What does LineStringObject.coords.xy look like, why are you unpacking the result?
    – AMC
    Commented Feb 21, 2020 at 18:37
  • LineStringObject.coords.xy are of type tuple. x,y are arrays. Did not get it to work without the zip
    – Paul
    Commented Feb 22, 2020 at 17:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.