I am a newbie to geospatial data. I was wondering if there are any ways to extract lat/lon points from a shape file or a csv file(MULLTILINE)
I have tried coding it using Geopy,Fiona etc to convert a government shape file to lat and lon but I am not reaching anywhere. Any leads would be appreciated.
Depends on what latitude and longitude do you want. Check the figure below, for a multiline - you can get individual vertexes (multiple points per record) or you can get starts and ends (if it is multiline, again multiple starts and ends per records) or you can get the centroid of the bounding box (a single point that may not be on the individual lines but shows roughly where the lines are)
To access the geometry you can do as follows:
LineStrings
LineStrings are single objects so you can simply access their coordiantes by referring to the coords property and then the xy property.
Access coordinates xy arrays of a geometry object:
As we see in the results, we have a tuple of coordinate arrays (latitude and longitude in my case).
Centroid of a line:
A single centroid point of the line
Start and end of the line:
You can use boundary property which will give you a multipoint object:
MultiLineString
Similar to what we have done for the multipoint object, if you want to access geometry coordinates you need to iterate over .geoms of the multi.
Access individual coordinates:
Access centroids
or access a single centroid for all of the objects:
Starts and ends
How to do when you have a dataframe
Some example, as I cannot cover all different ways here. Data can be found here: https://data.hydrosheds.org/file/HydroRIVERS/HydroRIVERS_v10_eu_shp.zip
centroid in one column
centroid coordinates in two columns (x,y or latitude, longitude)
all vertices of line strings in two x, y columns