Opened 14 years ago

Closed 13 years ago

#3148 closed bug (fixed)

ftools, buffering: error in shapefile writing

Reported by: elpaso Owned by: cfarmer
Priority: critical: causes crash or data corruption Milestone: Version 1.7.0
Component: fTools Version:
Keywords: ftools, shapefile, buffering Cc:
Must Fix for Release: No Platform: Debian
Platform Version: Awaiting user input: no

Description

this is a more general issue, because QGIS fails to save shapefiles when there are conflicts in field names after DBF 8 char truncation.

The perfect solution would be an automated conflict resolving systen when truncating field names, but I did not (yet) indagate how shapefiles are written (OGR or what?).

A quick and dirty hack to solve the ftool->geoprocessing->buffer issue, consists in considering only the first field when creating the shapefile:

diff tmp/ftool.mod /usr/share/qgis/python/plugins/fTools/tools/doGeoprocessing.py 297,298d296 < # ABP: < fields = { 0 : fields[0] }

Full story:

I'm preparing a QGIS demo for tomorrow's italian Linux Day meeting and I'm hitting an error with Ftools->buffering.

Basically, I'm building a 20 m buffer around a selected linestring (first I select one geometry from a postgis vector layer, but I get the same result if the selected geometry comes from a sqlite file), I'm saving the buffer in /home/me/tmp/buf.shp, the plugin says :

Shapefile in ouput creato:

/home/me/tmp/buf.shp

but the file is not there (and this is a bug: the message shouldn't say the the file has been created when it is not), adding to the legend throws an error since the file does not exists and cannot be loaded.

The problem originates from QGIS shapefile writer which cannot resolve conflicts between field names (which are truncated at 8 chars or so AFAIK).

I soved hacking the ftools plugin code

$ diff tmp/ftool.mod /usr/share/qgis/python/plugins/fTools/tools/doGeoprocessing.py 297,298d296 < # ABP: < fields = { 0 : fields[0] }

a couple of thoughts:

1 - fTools (or QgsVectorFileWriter ?) should better handle errors when shapefile conversion - save fails 2 - an option to save buffer and other results to temporary in-memory layer should be provided 3 - is it really necessary to copy all source vector fields in the result file ? Not in the buffer function, maybe in the other tools ? 4 - the docs say QgsFileWriter will support other output formats, is there a roadmap for this feature ? This could eventually solve many conversion errors due to shapefile (DBF) limitations 5 - it's not clear to me how to catch QgsFileWriter errors from python code while delegating real writing to the destructor (see: "del writer" in the plugin's code), this could solve point 1 in this

Change History (3)

comment:1 by borysiasty, 14 years ago

Owner: changed from borysiasty to cfarmer

comment:2 by pcav, 13 years ago

Component: Python plugins and bindingsfTools

comment:3 by cfarmer, 13 years ago

Resolution: fixed
Status: newclosed

This problem should no longer be an issue as of r15385. Vector file writer now gracefully handles duplicate truncated names, and where this isn't caught by the writer, fTools now catches and returns an error.

This basically addresses the posters first suggestion. Since multiple output types are on the 'TODO' this, I will close this ticket as the current issue is now resolved. As always, if the problem persists, please reopen the ticket.

Note: The OP may want to open a new 'enhancement' ticket suggesting multiple output types to address their 2nd and 4th suggestions, though note that these are already known enhancement requests.

Regards,

Carson

Note: See TracTickets for help on using tickets.