I have GIS data with a very large layer stored within a geopackage from where I want to select features that fall within a bounding box calculated in my R session. I begin by creating a query string:
query<-"SELECT * FROM buildings where ST_Intersects(geom, 'SRID=3006; POLYGON((753028 , 7084328, 764500,7093410))');" Then I use it in an st_read call:
buildings<-st_read(dsn="database.gpkg",layer="buildings", query=query,driver="GPKG") The result is the entire layer, and not the subset that I had intended. Is there anything else I have to do in order to be able to run these spatial queries?
EDIT: I have also tried a different version of the query:
query<-"SELECT * FROM buildings where ST_Intersects(geom, ST_GeomFromText( POLYGON((753028 , 7084328, 764500,7093410))',3006)));"
sfst_bboxto apaste()call that builds the query.st_bbox( )gives me coordinates in the order:xmin, ymin, xmax, ymax. Do you reckon that I'd need them to bexmin, xmax, ymin, ymaxinstead?