1

I have a dataframe with a column of linestrings. I want to convert the linestrings to its corresponding latitude/longitude so that I can plot it with basemap. My code is as follows:

gdf = gpd.read_file('./call2016.shp') #read the data into a variable

streetsaslinestring = gdf.loc[: , "geometry"] #getting the linestring column

Next, I want to convert the data as described as lon/lat.

streetsinlatlong    = convert_etrs89_to_lonlat(streetsaslinestring)

streetsinlatlong.to_file('./streetslonglat.shp') #store it as .shp in order to plot it with basemap

m.readshapefile('./streetslonglat', 'streets') #read as shape file

The geometry column looks like this:geometry column

How can I convert the longstring data?

christheliz
  • 176
  • 2
  • 15
  • What does the data in your "geometry" column look like? E.g. what is the content of the `streetsaslinestring` variable? Also, in the first line of code you read the shapefile using `gpd.read_file()`, but in the last line of code you read another shapefile using `m.readshapefile()` - why? – jberrio Oct 16 '18 at 00:03
  • the geometry column consists of linestring elements. So for every entry in the column there exists one lineshape. In the first line I read the shape file which has various columns, e.g street names, zip codes etc. and in the last column I am using `m.readshapefile()` to plot the converted shapefile into a map using basemap. – christheliz Oct 18 '18 at 12:57
  • Can you edit your question to include examples of the contents of the geometry column? – jberrio Oct 19 '18 at 08:00
  • Yes of course. It contains linestring and multilinestrings. Sadly they are not iterable... – christheliz Oct 20 '18 at 11:07
  • Update: So I used a different approach: `stations = pd.read_csv(path) ` #transforming longitude and latitude to an other projection `geometry = [Point(xy) for xy in zip(stations['lon'], stations['lat'])] ` `crs = {'init': 'epsg:4326'} ` `geoDF_stations = gpd.GeoDataFrame(stations, crs=crs, geometry=geometry) ` `geoDF_stations_new = geoDF_stations.to_crs({'init': 'epsg:25830'}) ` – christheliz Feb 10 '20 at 00:25

1 Answers1

1

I think you can simply use

Lats, Lons = LineStringObject.coords.xy

It will return the latitude and longitude array separately.