1

In a python script, I can't access the geometry of my tables :

SQL_req = 'SELECT id_parcel, id_melba FROM parcels, network WHERE st_intersects(parcels.geometry, network.geometry)'
grass.write_command("db.select", input='-', stdin=SQL_req, stdout = DEVNULL, stderr = DEVNULL)

gives :

DBMI-SQLite driver error:
Error in sqlite3_prepare():
SELECT id_parcel, id_melba FROM parcels, network WHERE st_intersects(parcels.geometry, network.geometry)
no such column: parcels.geometry

Shapefiles were imported with v.in.ogr and other sql requests are correctly ending. That's when I try to use spatial functions that it don't work.

Any suggest or example?

1 Answer 1

1

In the GRASS vector model, there is no geometry stored in the SQL database. The backend SQL database is for attributes only. Geometry is stored in a special set of GRASS files.

You should be looking at the native GRASS modules for selection/intersection. etc such as v.overlay or v.select.

5
  • Or, use GRASS to export to shapefile, and load the shapefile directly in Python to work with the geometry. Commented Apr 26, 2017 at 20:50
  • Thanks! What do you mean by loading shapefile directly? Commented Apr 27, 2017 at 7:57
  • I'd like to use spatial functions. For example : st_split because I didn't find a module in GRASS that splits polygons with a polyline. Commented Apr 27, 2017 at 8:12
  • Loading the shapefile directly into python means using pyshp or gdal python bindings, not GRASS. Commented Apr 27, 2017 at 13:39
  • Regarding spliting polygons in GRASS, Did you see the answer posted here: [gis.stackexchange.com/questions/237818/… Commented Apr 28, 2017 at 12:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.