#1295 closed patch (fixed)
spatial index fails
Reported by: | gespiel | Owned by: | jef |
---|---|---|---|
Priority: | major: does not work as expected | Milestone: | |
Component: | Vectors | Version: | Trunk |
Keywords: | Cc: | ||
Must Fix for Release: | Yes | Platform: | Windows |
Platform Version: | XP sp2 | Awaiting user input: | no |
Description
in shp layers properity, the spatial index button terminates with following popup message: "The spatial index could not create"
Attachments (4)
Change History (10)
by , 16 years ago
Attachment: | alaska.zip added |
---|
by , 16 years ago
Attachment: | spartial idex fail.jpg added |
---|
comment:1 by , 16 years ago
Component: | Build/Install → Vectors |
---|---|
Must Fix for Release: | No → Yes |
comment:2 by , 16 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:3 by , 16 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
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.
What happens is the SQL statement passed to OGR has something like C:\gis\somefile
for the layer name instead of somefile
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.
comment:4 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
Type: | bug → patch |
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.
Thanks for submitting detailed info and sample data.
I can't reproduce the error in the latest SVN trunk r9278 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).