{"id":1269,"date":"2019-07-03T19:53:48","date_gmt":"2019-07-03T17:53:48","guid":{"rendered":"https:\/\/hannes.enjoys.it\/blog\/?p=1269"},"modified":"2019-07-03T19:57:47","modified_gmt":"2019-07-03T17:57:47","slug":"make-sure-you-actually-do-use-spatial-indexes","status":"publish","type":"post","link":"https:\/\/hannes.enjoys.it\/blog\/2019\/07\/make-sure-you-actually-do-use-spatial-indexes\/","title":{"rendered":"Make sure you actually do use spatial indexes"},"content":{"rendered":"\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Ever ran some GIS analysis in QGIS and it took longer than a second? Chances are that your data did not have spatial indexes for QGIS to utilise and that it could have been magnitudes faster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I realised just today, after years of using QGIS, that it did not automatically create a spatial index when saving a Shapefile. And because of that, lots of GIS stuff I did in the past, involving saving subsets of data to quick&#8217;n&#8217;dirty Shapefiles, was slower than necessary.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sadly QGIS does not communicate lack of spatial indexing to the user in any way. I added a feature request to <a href=\"https:\/\/github.com\/qgis\/QGIS\/issues\/30530\">make Processing warn if no indexing is available<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An example: Running &#8216;Count points in polygon&#8217; on 104 polygons with 223210 points:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Points in original GML file: 449 seconds<ul><li>GML is not a format for processing but meant for data transfer, never ever think of using it for anything else<\/li><\/ul><\/li><li><strong>Points in ESRI Shapefile: 30 seconds<\/strong><\/li><li>Points in GeoPackage: 3 seconds<\/li><li><strong>Points in ESRI Shapefile <em>with spatial index<\/em>: 3 seconds<\/strong><ul><li>Same Shapefile as before but this time I had created a .qix index<\/li><\/ul><\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"216\" src=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/shapefile-spatial-index.png\" alt=\"\" class=\"wp-image-1273\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/shapefile-spatial-index.png 699w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/shapefile-spatial-index-300x93.png 300w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/shapefile-spatial-index-624x193.png 624w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">So yeah, make sure you don&#8217;t only use a reasonable format for your data. And also make sure you do actually have an spatial index.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For Shapefiles, look for a .qix or .sbn side-car file somewhere in the heap of files. In QGIS you can create a spatial index for a vector layer either using the &#8220;Create spatial index&#8221; algorithm in Processing or the button of the same title in the layer properties&#8217; source tab.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PS: GeoPackages always have a spatial index. That&#8217;s reason #143 why they are awesome.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever ran some GIS analysis in QGIS and it took longer than a second? Chances are that your data did not have spatial indexes for QGIS to utilise and that it could have been magnitudes faster. I realised just today, after years of using QGIS, that it did not automatically create a spatial index when [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,29,52,31],"tags":[],"class_list":["post-1269","post","type-post","status-publish","format-standard","hentry","category-gdal","category-gis","category-performance","category-qgis"],"_links":{"self":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/1269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/comments?post=1269"}],"version-history":[{"count":6,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/1269\/revisions"}],"predecessor-version":[{"id":1276,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/1269\/revisions\/1276"}],"wp:attachment":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/media?parent=1269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/categories?post=1269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/tags?post=1269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}