Bug report #3148

ftools, buffering: error in shapefile writing

Added by Alessandro Pasotti almost 14 years ago. Updated over 7 years ago.

Status:Closed
Priority:Low
Assignee:cfarmer -
Category:Processing/QGIS
Affected QGIS version: Regression?:
Operating System:Debian Easy fix?:
Pull Request or Patch supplied: Resolution:fixed
Crashes QGIS or corrupts data: Copied to github as #:13208

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 : fieldsr0 }

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 : fieldsr0 }

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

History

#1 Updated by cfarmer - over 13 years ago

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

This problem should no longer be an issue as of c08e1a42 (SVN r15386).
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

#2 Updated by Giovanni Manghi over 7 years ago

The "ftools" category is being removed from the tracker, changing the category of this ticket to "Processing/QGIS" to not leave the category orphaned.

Also available in: Atom PDF