Opened 16 years ago

Closed 15 years ago

Last modified 15 years ago

#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)

alaska.zip (117.1 KB ) - added by gespiel 16 years ago.
spartial idex fail.jpg (197.7 KB ) - added by gespiel 16 years ago.
alaska.qix (33.7 KB ) - added by msieczka 16 years ago.
spatial index creted with r9278
patch_for1295.txt (3.5 KB ) - added by smizuno 16 years ago.
patch for #1295 / #1244

Download all attachments as: .zip

Change History (10)

by gespiel, 16 years ago

Attachment: alaska.zip added

by gespiel, 16 years ago

Attachment: spartial idex fail.jpg added

comment:1 by msieczka, 16 years ago

Component: Build/InstallVectors
Must Fix for Release: NoYes

comment:2 by msieczka, 16 years ago

Resolution: worksforme
Status: newclosed

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).

by msieczka, 16 years ago

Attachment: alaska.qix added

spatial index creted with r9278

comment:3 by smizuno, 16 years ago

Resolution: worksforme
Status: closedreopened

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 smizuno, 16 years ago

Owner: changed from nobody to jef
Status: reopenednew
Type: bugpatch

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.

by smizuno, 16 years ago

Attachment: patch_for1295.txt added

patch for #1295 / #1244

comment:5 by mhugent, 15 years ago

Resolution: fixed
Status: newclosed

Applied in r9787. Thanks!

comment:6 by (none), 15 years ago

Milestone: Version 1.0.0

Milestone Version 1.0.0 deleted

Note: See TracTickets for help on using tickets.