Feature request #1295

spatial index fails

Added by Gerhard Spieles over 14 years ago. Updated over 13 years ago.

Assignee:Jürgen Fischer
Pull Request or Patch supplied: Resolution:fixed
Easy fix?:No Copied to github as #:11355


in shp layers properity, the spatial index button terminates with following popup message: "The spatial index could not create"

alaska.zip (117 KB) Gerhard Spieles, 2008-09-05 08:38 AM

spartial_idex_fail.jpg (198 KB) Gerhard Spieles, 2008-09-05 08:38 AM

alaska.qix - spatial index creted with r9278 (33.7 KB) Maciej Sieczka -, 2008-09-07 05:45 AM

patch_for1295.txt Magnifier - patch for #1295 / #1244 (3.5 KB) Steven Mizuno, 2008-10-08 07:20 PM


#1 Updated by Maciej Sieczka - over 14 years ago

  • Resolution set to worksforme
  • Status changed from Open to Closed

Thanks for submitting detailed info and sample data.

I can't reproduce the error in the latest SVN trunk 6b106195 (SVN r9279) on Debian testing amd64. Attached is the output QGIS spatial index file (alaska.qix).

I'll close the ticket. Once there is a 1.0 preview or RC released for windows, please check if this issue is also fixed on that platform (I don't see a reason it should not, but you never know).

#2 Updated by Steven Mizuno over 14 years ago

  • Resolution deleted (worksforme)
  • Status changed from Closed to Feedback

This is a Windows problem, specifically the \\ (backslash) path separator.

I tried changing the path separators to forward slashes for a layer file in a project file and then tried to create a spatial index on the layer. This works.

In QgsOgrProvider::createSpatialIndex(), line 723 where the filename is extracted using dataSourceUri().section(), the separator parameter is '/'. If it is changed to '\\\\' then create spatial index works on Windows. Of course, it now won't work for Linux.

I believe it is not a good idea to just have the separator be a backslash for Windows (and forward slash for other OS) since Windows will accept forward slashes as well. Perhaps a test for which kind of separator was used should be done first. Then the resulting character is used in dataSourceUri().section(). Or there may be a Qt function to change the separators?

There is also a problem with the file name if it contains spaces or possibly other special characters as the name is not quoted in the SQL string. I assume that someone will use these characters, so this should be fixed.

#3 Updated by Steven Mizuno over 14 years ago

  • Status changed from Feedback to Open

I am providing a patch that fixes this problem and also #1244 (spaces in file names).

This uses QFileInfo::completeBaseName() to extract the file name to use as the layer name in createSpatialIndex(). It handles both / and \\. It also deals with a potential problem with multiple dots (.) in a file name. Identifier quoting is also applied.

I also noticed that deleteFeatures() fails in the REPACK statement as well, although it is silent. The feature count isn't correct. So completeBaseName() is used here, too. Note that REPACK is very particular - it doesn't work with quotes, but it does accept spaces in the layer name, even a leading space.

Addtionally, mEncoding->fromUnicode() was applied to the calls to OGR for better i18n handling as has been done in some other functions.

I also used QFileInfo::completeBaseName(), replacing QFileInfo::baseName(), in several other functions calling the layer name in similar ways in SQL statements.

I have only tested this with GDAL/OGR 1.5.2, so I'm not sure how other versions will work with this patch.

#4 Updated by Marco Hugentobler over 14 years ago

  • Resolution set to fixed
  • Status changed from Open to Closed

Applied in 3b6f972c (SVN r9788). Thanks!

#5 Updated by Anonymous over 13 years ago

Milestone Version 1.0.0 deleted

Also available in: Atom PDF