1

I have a filename with the columns: lon, lat, val1, val2 etc. and I want to join it with a grid shapefile in WGS84. I use the following command but I get an error in ST_PointFromText

ogr2ogr -sql "SELECT a.*, b.* FROM '$Grid_shapefile".shp"'.$Grid_shapefile AS a LEFT JOIN '$filename".csv"'.$filename AS b ON ST_Within(ST_PointFromText('POINT('lon' 'lat')', 4326), a.geometry)" $filename"gridded.shp" $Grid_shapefile".shp"

I tried also this

  ogr2ogr -sql "SELECT a.*, b.* FROM '$Grid_shapefile".shp"'.$Grid_shapefile AS a LEFT JOIN '$filename".csv"'.$filename AS b ON ST_Within(ST_PointFromText('POINT(' || b.lon || ' ' || b.lat || ')', 4326), a.geometry)" $filename"gridded.shp" $Grid_shapefile".shp"

but I always get error

ERROR 1: SQL Expression Parsing Error: syntax error, unexpected identifier, expecting ')'. Occurred around :
b ON ST_Within(ST_PointFromText('POINT('lon' 'lat')', 4326), a.geometry)
3
  • You are passing literal strings instead of column names. Use the concatenate operator (||) and float-string formatting (or ST_Point)
    – Vince
    Commented Nov 15, 2023 at 14:53
  • @Vince could you please be more specific on how to use the ST_Point in the above code? since the concatenate operator didn't work either. thank you
    – nat
    Commented Nov 16, 2023 at 8:26
  • I used ST_Within(ST_PointFromText('POINT(|| b.lon || || b.lat ||)', 4326), a.geometry) where b is the $filename
    – nat
    Commented Nov 16, 2023 at 8:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.