Is it possible to index an attribute value of a shapefile in QGis, and if so save this as part of the project (similair to a spatial index)?

I have a large shapefile of land parcels (maybe about 1 000 000) and I would like to index them on their land parcel number so as to speed up queries on this number.

  • I am almost sure that it is not possible with QGIS. MapServer can be made faster by sorting dbf by one attribute with sortshp mapserver.org/utilities/sortshp.html. I would convert the data into SpatiaLite and create an index there.
    – user30184
    Aug 22 '16 at 12:00
  • In addition to the answer below, GIS administrators/architects/dba's/etc should really be considering alternative data structures and storage mechanisms when datasets are 1 million records. Your question is a result of poor solution design. Improve solution design and your problem doesn't happen.
    – nr_aus
    Oct 29 '20 at 1:38

QGIS uses OGR for accessing shapefiles. Looking at the OGR Shapefile driver page it says

Currently the OGR Shapefile driver only supports attribute indexes for looking up specific values in a unique key column. To create an attribute index for a column issue an SQL command of the form "CREATE INDEX ON tablename USING fieldname". To drop the attribute indexes issue a command of the form "DROP INDEX ON tablename". The attribute index will accelerate WHERE clause searches of the form "fieldname = value". The attribute index is actually stored as a mapinfo format index and is not compatible with any other shapefile applications.

So it depends on if your indexed attribute is unique.

As an alternative, you can also switch to a database like postgis, geopackage or spatialite which are designed for big data and indexing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.