I would like to join the attributes of two shapefiles by location but with a command line (Linux). This feature is easy in QGIS but it is VERY slow.
Is there a way of doing this with ogr or PyQGIS?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
These kinds of queries can run quicker with a spatial index. If the file is from Esri, it may have
.sbx files, which OGR 1.10 can use. However, if you've created/modified the shapefile with QGIS, you may need to create/update a
.qix spatial index. You can find some buttons in QGIS' Layer Properties, under General > Coordinate reference system, look for Create spatial index and Update extents. Or from a shell, similar:
ogrinfo -sql "CREATE SPATIAL INDEX ON \"your-geoms\"" your-geoms.shp
Either method will create/update a
.qix, which is a quadtree spatial index file.
Once you have a good spatial index, QGIS and other OGR-related things should have better spatial join performance. And for a spatial join from a command line, see this example.