add_warnings.diff

proposed patch - Alexander Bruy, 2010-04-14 12:25 AM

Download (7.33 KB)

View differences:

python/plugins/fTools/tools/doJoinAttributes.py (working copy)
101 101
        useTable = True
102 102
      joinField = self.joinField.currentText()
103 103
      outPath = self.outShape.text()
104
      self.compute(inName, inField, joinName, joinField, outPath, keep, useTable, self.progressBar)
104
      res = self.compute(inName, inField, joinName, joinField, outPath, keep, useTable, self.progressBar)
105 105
      self.outShape.clear()
106
      addToTOC = QMessageBox.question(self, self.tr("Join Attributes"), self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg( unicode(self.shapefileName) ), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
107
      if addToTOC == QMessageBox.Yes:
108
        if not ftools_utils.addShapeToCanvas( unicode( outPath ) ):
109
          QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( outPath ) ))
106
      if res:
107
        addToTOC = QMessageBox.question(self, self.tr("Join Attributes"),
108
            self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?")
109
            .arg( unicode(self.shapefileName) ), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
110
        if addToTOC == QMessageBox.Yes:
111
          if not ftools_utils.addShapeToCanvas( unicode( outPath ) ):
112
            QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" )
113
            .arg( unicode( outPath ) ))
110 114
    self.progressBar.setValue(0)
111 115

  
112 116
  def outFile(self):
......
171 175
    seq = range(0, len(fieldList1) + len(fieldList2))
172 176
    fieldList1.extend(fieldList2)
173 177
    fieldList1 = dict(zip(seq, fieldList1))
178
    # check for correct field names
179
    longNames = ftools_utils.checkFieldNameLenght( fieldList1 )
180
    if not longNames.isEmpty():
181
      QMessageBox.warning( self, self.tr( 'Incorrect field names' ),
182
                  self.tr( 'Following field names are longer then 10 characters:\n%1' )
183
                  .arg( longNames.join( '\n' ) ) )
184
      return False
174 185
    sRs = provider1.crs()
175 186
    progressBar.setValue(13)
176 187
    check = QFile(self.shapefileName)
177 188
    if check.exists():
178 189
      if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName):
179
        return
190
        QMessageBox.warning( self, self.tr( 'Error deleting shapefile' ),
191
                    self.tr( "Can't delete existing shapefile\n%1" ).arg( self.shapefileName ) )
192
        return False
180 193
    writer = QgsVectorFileWriter(self.shapefileName, self.encoding, fieldList1, provider1.geometryType(), sRs)
181 194
    inFeat = QgsFeature()
182 195
    outFeat = QgsFeature()
......
215 228
      nElement += 1
216 229
      progressBar.setValue(nElement)
217 230
    del writer
231
    return True
218 232

  
219 233
  def createFieldList(self, table, joinField):
220 234
    fieldList = {}
......
236 250
      fieldList[item] = field
237 251
      item = item + 1
238 252
    return (fieldList, index2)
239

  
240
  def testForUniqueness(self, fieldList1, fieldList2):
241
    changed = True
242
    while changed:
243
      changed = False
244
      for i in fieldList1:
245
        for j in fieldList2:
246
          if j.name() == i.name():
247
            j = ftools_utils.createUniqueFieldName(j)
248
            changed = True
249
    return fieldList2
python/plugins/fTools/tools/doSpatialJoin.py (working copy)
86 86
                outName = outPath.right((outPath.length() - outPath.lastIndexOf("/")) - 1)
87 87
            if outName.endsWith(".shp"):
88 88
                outName = outName.left(outName.length() - 4)
89
            self.compute(inName, joinName, outPath, summary, sumList, keep, self.progressBar)
89
            res = self.compute(inName, joinName, outPath, summary, sumList, keep, self.progressBar)
90 90
            self.outShape.clear()
91
            addToTOC = QMessageBox.question(self, self.tr("Spatial Join"), self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg(unicode(outPath)), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
92
            if addToTOC == QMessageBox.Yes:
91
            if res:
92
              addToTOC = QMessageBox.question(self, self.tr("Spatial Join"),
93
                      self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?")
94
                      .arg(unicode(outPath)), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
95
              if addToTOC == QMessageBox.Yes:
93 96
                self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
94 97
                QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
95 98
        self.progressBar.setValue(0)
......
136 139
            seq = range(0, len(fieldList1))
137 140
            fieldList1 = dict(zip(seq, fieldList1))
138 141

  
142
        # check for correct field names
143
        longNames = ftools_utils.checkFieldNameLenght( fieldList1 )
144
        if not longNames.isEmpty():
145
            QMessageBox.warning( self, self.tr( 'Incorrect field names' ),
146
                        self.tr( 'No output will be produced.\nFollowing field names are longer then 10 characters:\n%1' )
147
                        .arg( longNames.join( '\n' ) ) )
148
            return False
149

  
139 150
        sRs = provider1.crs()
140 151
        progressBar.setValue(13)
141 152
        check = QFile(self.shapefileName)
142 153
        if check.exists():
143 154
            if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName):
144
                return
155
                QMessageBox.warning( self, self.tr( 'Error deleting shapefile' ),
156
                            self.tr( "Can't delete existing shapefile\n%1" ).arg( self.shapefileName ) )
157
                return False
145 158
        writer = QgsVectorFileWriter(self.shapefileName, self.encoding, fieldList1, provider1.geometryType(), sRs)
146 159
        #writer = QgsVectorFileWriter(outName, "UTF-8", fieldList1, provider1.geometryType(), sRs)
147 160
        inFeat = QgsFeature()
......
215 228
            start = start + add
216 229
            progressBar.setValue(start)
217 230
        del writer
231
        return True
python/plugins/fTools/tools/ftools_utils.py (working copy)
12 12
# extractPoints( QgsGeometry )
13 13
# testForUniqueness( QList *QgsField, QList *QgsField )
14 14
# createUniqueFieldName( QgsField.name() )
15
# checkFieldNameLenght( QgsFieldMap )
15 16
# getLayerNames( QGis.vectorType() )
16 17
# getFieldNames( QgsVectorLayer )
17 18
# getVectorLayerByName( QgsVectorLayer.name() )
......
158 159
        field.setName( field.name() + "_2" )
159 160
    return field
160 161

  
162
# Return list of field names with length more than 10 characters
163
def checkFieldNameLenght( fieldList ):
164
    longNames = QStringList()
165
    for num, field in fieldList.iteritems():
166
        if field.name().size() > 10:
167
            longNames << unicode( field.name() )
168
    return longNames
169

  
161 170
# Return list of names of all layers in QgsMapLayerRegistry
162 171
def getLayerNames( vTypes ):
163 172
    layermap = QgsMapLayerRegistry.instance().mapLayers()