How to spatially join a csv database with a polygon shape file based on lon lat fields using ogr2ogr

32 views Asked by At

I have multiple databases in csv files (e.g. data.csv) with the following columns : id, lon, lat, val1, val2, val3, val4, val5, val6 I want to spatially join all the fields of data.csv with a grid file (grid.shp) projected on WGS84.

I used ogr2ogr as following

ogr2ogr -f "ESRI Shapefile" -dialect SQLite -sql "SELECT a.*, b.* FROM $Grid".shp" AS a LEFT JOIN $data".csv" AS b ON ST_Within(ST_PointFromText('POINT(' || b.lon || ' ' || b.lat || ')', 4326), a.geometry)" $Database_outdir/$filename"gridded.shp" $Grid".shp"

but it does not work since it always gives the error that it cannot open the datasource "data.csv". However the ogrinfo command works well with the file.

0

There are 0 answers