Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to reduce the file size of the shapefile by simplifying geometry in QGiS on OS X.

But I get the following error...

An error has occured while executing Python code:

Traceback (most recent call last):
  File "/Applications/QGIS.app/Contents/Resources/python/plugins/fTools/tools/doSimplify.py", line 255, in run
    self.runSimplify()
  File "/Applications/QGIS.app/Contents/Resources/python/plugins/fTools/tools/doSimplify.py", line 280, in runSimplify
    shapeFileWriter = QgsVectorFileWriter( self.outputFileName, self.outputEncoding, shapeFields, wkbType, crs )
TypeError: arguments did not match any overloaded call:
  QgsVectorFileWriter(QString, QString, dict-of-int-QgsField, QGis.WkbType, QgsCoordinateReferenceSystem, QString driverName="ESRI Shapefile", QStringList datasourceOptions=QStringList(), QStringList layerOptions=QStringList(), QString newFilename=None): argument 2 has unexpected type 'NoneType'
  QgsVectorFileWriter(QgsVectorFileWriter): argument 1 has unexpected type 'QString'

Python version:
2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]


QGIS version:
1.8.0-Lisboa Lisboa, 

Python path: ['/Applications/QGIS.app/Contents/MacOS/../Resources/python', '/Users/admin/.qgis//python', '/Users/admin/.qgis//python/plugins', '/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins', '/Library/Frameworks/SQLite3.framework/Versions/3/Python/2.7', '/Library/Python/2.7/site-packages/numpy-override', '/Library/Frameworks/GDAL.framework/Versions/1.9/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages', '/Applications/QGIS.app/Contents/Resources/python/plugins/fTools/tools']

Any idea what the issue could be ?

Gaurav

share|improve this question

1 Answer 1

I was dealing with the same problem today.

Try replacing shapeFields with: {}

At the very least confirm shapeFields is a dict-of-int-QgsField

Somehow this causes errors with the other parameters, maybe something to do with autocasting between str and QString.

Edit:

The error report indicates that the third parameter is being passed a None ( or NULL) value rather than the dictionary it expects.

I just had a look through the file (doSimplify.py) that contains the code throwing the error and shapeFields is being set to that value because the source layer's data provider is providing it. fTools is then taking the value on faith and the error occurs a few steps later.

If you wished you could open doSimplify.py and modify it to correct this assumption.

Backup the file then find line 280 and insert this code before it:

if shapeFields is None:
  shapeFields = {}

I have include a screen capture to show correct indenting.

modified code

Note that this will allow the code to run, but the bad response from the data provider may indicate a problem with the source layer, or maybe a something went wrong earlier with the tools. Ensure you have a backup before running the new code.

share|improve this answer
    
err I am newbie here. How do I replace shapefields ? How do I confirm shapefields is dict-od-int-QgsField. I am using census 2012 counties shapefile –  gaurav Nov 29 '12 at 7:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.