evetion / GeoDataFrames.jl

Simple geographical vector interaction built on top of ArchGDAL
https://www.evetion.nl/GeoDataFrames.jl/dev/
MIT License
67 stars 6 forks source link

Feature request: Reading from CSV #61

Closed rotsee closed 11 months ago

rotsee commented 11 months ago

Reading point data from columns in a csv file is a very common task, and it would be nice to have a shortcut here, something like GeoDataFrames.open(fn, crs="espg:3006", geom_columns=(...))

evetion commented 11 months ago

That makes sense. Did you try reading a csv? I think it should work out of the box, with the exception of setting the CRS.

rotsee commented 11 months ago

Oh, sorry, I might be doing something wrong then. Is it documented somewhere how I tell it what columns to use for coordinates?

evetion commented 11 months ago

This can be better documented, but for now:

fn = "latlon.csv"  # csv file with Latitude, Longitude headers (=points)
df = GeoDataFrames.read(fn, options=GeoDataFrames.stringlist(Dict("X_POSSIBLE_NAMES"=>"Longitude", "Y_POSSIBLE_NAMES"=>"Latitude")))
fn = "geometry.csv"  # csv file with Geometry column with quoted WKT strings
df = GeoDataFrames.read(fn, options=GeoDataFrames.stringlist(Dict("GEOM_POSSIBLE_NAMES"=>"Geometry", "KEEP_GEOM_COLUMNS"=>"NO")))

Essentially, all kwargs to read are passed to ArchGDAL (like options, documented here), which in turns pass it to GDAL itself (csv driver details here.

Let me know if this works for you.

rotsee commented 11 months ago

Thank you, I'll try that! Sorry for making this into a support thread