15 changes: 11 additions & 4 deletions python/core/qgsfeature.sip
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ typedef QVector<QVariant> QgsAttributes;
// Set the list elements.
for (int i = 0; i < sipCpp->size(); ++i)
{
QVariant* v = new QVariant(sipCpp->at(i));
QVariant* v = new QVariant( sipCpp->at(i) );
PyObject *tobj;

if ( v->isNull() )
{
tobj = Py_None;
delete v;
}
else if ((tobj = sipConvertFromType(v, sipType_QVariant,Py_None)) == NULL)
else if ((tobj = sipConvertFromNewType(v, sipType_QVariant,Py_None)) == NULL)
{
delete v;
return NULL;
}

Expand Down Expand Up @@ -200,11 +202,16 @@ class QgsFeature
}
else
{
QVariant* v = new QVariant(attrs[a0]);
QVariant* v = new QVariant(attrs.at(a0));
if ( v->isNull() )
{
delete v;
sipRes = Py_None;
}
else
sipRes = sipConvertFromInstance( v, sipClass_QVariant, Py_None );
{
sipRes = sipConvertFromNewInstance( v, sipClass_QVariant, Py_None );
}
}
%End

Expand Down
1 change: 1 addition & 0 deletions python/core/qgsfield.sip
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public:
int fieldOriginIndex( int fieldIdx ) const;

int indexFromName( const QString& name ) const;
void extend( const QgsFields& other );


QgsField& operator[](int i);
Expand Down
7 changes: 1 addition & 6 deletions python/plugins/fTools/tools/doMeanCoords.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,8 @@ def accept(self):
else:
inName = self.inShape.currentText()
outPath = self.outShape.text()
outName = ftools_utils.getShapefileName(outPath)

if outPath.contains("\\"):
outName = outPath.right((outPath.length() - outPath.lastIndexOf("\\")) - 1)
else:
outName = outPath.right((outPath.length() - outPath.lastIndexOf("/")) - 1)
if outName.endsWith(".shp"):
outName = outName.left(outName.length() - 4)
self.compute(inName, outPath, self.weightField.currentText(), self.sizeValue.value(), self.uniqueField.currentText())
self.progressBar.setValue(100)
self.outShape.clear()
Expand Down
7 changes: 1 addition & 6 deletions python/plugins/fTools/tools/doPointDistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,7 @@ def accept(self):
else: matType = "Summary"
if self.chkNearest.isChecked(): nearest = self.spnNearest.value()
else: nearest = 0
if outPath.contains("\\"):
outName = outPath.right((outPath.length() - outPath.lastIndexOf("\\")) - 1)
else:
outName = outPath.right((outPath.length() - outPath.lastIndexOf("/")) - 1)
if outName.endsWith(".csv"):
outName = outName.left(outName.length() - 4)
outName = ftools_utils.getShapefileName(outPath,'.csv')
self.outFile.clear()
self.compute(point1, point2, field1, field2, outPath, matType, nearest, self.progressBar)
self.progressBar.setValue(100)
Expand Down
7 changes: 1 addition & 6 deletions python/plugins/fTools/tools/doRandPoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ def accept(self):
self.progressBar.setValue(1)
outPath = self.outShape.text()
self.progressBar.setValue(2.5)
if outPath.contains("\\"):
outName = outPath.right((outPath.length() - outPath.lastIndexOf("\\")) - 1)
else:
outName = outPath.right((outPath.length() - outPath.lastIndexOf("/")) - 1)
if outName.endsWith(".shp"):
outName = outName.left(outName.length() - 4)
outName = ftools_utils.getShapefileName( outPath )
self.progressBar.setValue(5)
mLayer = ftools_utils.getMapLayerByName(unicode(inName))
if mLayer.type() == mLayer.VectorLayer:
Expand Down
7 changes: 1 addition & 6 deletions python/plugins/fTools/tools/doRegPoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,7 @@ def accept(self):
inName = self.inShape.currentText()
outPath = self.outShape.text()
self.outShape.clear()
if outPath.contains("\\"):
outName = outPath.right((outPath.length() - outPath.lastIndexOf("\\")) - 1)
else:
outName = outPath.right((outPath.length() - outPath.lastIndexOf("/")) - 1)
if outName.endsWith(".shp"):
outName = outName.left(outName.length() - 4)
outName = ftools_utils.getShapefileName( outPath )
if self.rdoSpacing.isChecked(): value = self.spnSpacing.value()
else: value = self.spnNumber.value()
if self.chkRandom.isChecked(): offset = True
Expand Down
12 changes: 3 additions & 9 deletions python/plugins/fTools/tools/doSpatialJoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ def accept(self):
sumList = ["all"]
if self.rdoKeep.isChecked(): keep = True
else: keep = False
if outPath.contains("\\"):
outName = outPath.right((outPath.length() - outPath.lastIndexOf("\\")) - 1)
else:
outName = outPath.right((outPath.length() - outPath.lastIndexOf("/")) - 1)
if outName.endsWith(".shp"):
outName = outName.left(outName.length() - 4)
outName = ftools_utils.getShapefileName( outPath )
res = self.compute(inName, joinName, outPath, summary, sumList, keep, self.progressBar)
self.outShape.clear()
if res:
Expand Down Expand Up @@ -154,7 +149,7 @@ def compute(self, inName, joinName, outName, summary, sumList, keep, progressBar
# check for correct field names
print fieldList1
longNames = ftools_utils.checkFieldNameLength( fieldList1.values() )
if not longNames.isEmpty():
if len( longNames ) > 0:
QMessageBox.warning( self, self.tr( 'Incorrect field names' ),
self.tr( 'No output will be created.\nFollowing field names are longer than 10 characters:\n%s' ) % ( "\n".join(longNames) ) )
return False
Expand Down Expand Up @@ -207,8 +202,7 @@ def compute(self, inName, joinName, outName, summary, sumList, keep, progressBar
for i in joinList:
#tempGeom = i.geometry()
provider2.getFeatures( QgsFeatureRequest().setFilterFid( int(i) ) ).nextFeature( inFeatB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
if inGeom.intersects(tmpGeom):
if inGeom.intersects(inFeatB.geometry()):
count = count + 1
none = False
atMap2 = inFeatB.attributes()
Expand Down
7 changes: 1 addition & 6 deletions python/plugins/fTools/tools/doSumLines.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ def accept(self):
inLns = self.inPoint.currentText()
inField = self.lnField.text()
outPath = self.outShape.text()
if outPath.contains("\\"):
outName = outPath.right((outPath.length() - outPath.lastIndexOf("\\")) - 1)
else:
outName = outPath.right((outPath.length() - outPath.lastIndexOf("/")) - 1)
if outName.endsWith(".shp"):
outName = outName.left(outName.length() - 4)
outName = ftools_utils.getShapefileName( outPath )
self.compute(inPoly, inLns, inField, outPath, self.progressBar)
self.outShape.clear()
addToTOC = QMessageBox.question(self, self.tr("Sum line lengths"), self.tr("Created output shapefile:\n%s\n\nWould you like to add the new layer to the TOC?") % (unicode(outPath)), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
Expand Down
20 changes: 14 additions & 6 deletions python/plugins/fTools/tools/ftools_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ def createUniqueFieldName( field ):
def checkFieldNameLength( fieldList ):
longNames = []
for field in fieldList:
if field.name().size() > 10:
longNames.append(unicode( field.name() ))
if len ( field.name() ) > 10:
longNames.append( field.name() )
return longNames

# Return list of names of all layers in QgsMapLayerRegistry
Expand All @@ -195,15 +195,15 @@ def getLayerNames( vTypes ):
layerlist = []
if vTypes == "all":
for name, layer in layermap.iteritems():
layerlist.append( unicode( layer.name() ) )
layerlist.append( layer.name() )
else:
for name, layer in layermap.iteritems():
if layer.type() == QgsMapLayer.VectorLayer:
if layer.geometryType() in vTypes:
layerlist.append( unicode( layer.name() ) )
layerlist.append( layer.name() )
elif layer.type() == QgsMapLayer.RasterLayer:
if "Raster" in vTypes:
layerlist.append( unicode( layer.name() ) )
layerlist.append( layer.name() )
return sorted( layerlist, cmp=locale.strcoll )

# Return list of names of all fields from input QgsVectorLayer
Expand All @@ -212,7 +212,7 @@ def getFieldNames( vlayer ):
fieldlist = []
for field in fieldmap:
if not field.name() in fieldlist:
fieldlist.append( unicode( field.name() ) )
fieldlist.append( field.name() )
return sorted( fieldlist, cmp=locale.strcoll )

# Return QgsVectorLayer from a layer name ( as string )
Expand Down Expand Up @@ -382,3 +382,11 @@ def getShapesByGeometryType( baseDir, inShapes, geomType ):
return None

return outShapes

def getShapefileName( outPath, extension='.shp' ):
import os.path
outName=os.path.basename(outPath)
if outName.endswith(extension):
outName=outName[:-len(extension)]
return outName

8 changes: 8 additions & 0 deletions src/core/qgsfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ class CORE_EXPORT QgsFields
inline bool isEmpty() const { return mFields.isEmpty(); }
inline int count() const { return mFields.count(); }
inline int size() const { return mFields.count(); } // TODO[MD]: delete?
void extend( const QgsFields& other )
{
for ( int i = 0; i < other.count(); ++i )
{
if ( other.fieldOrigin( i ) != OriginJoin )
append( other.at( i ), other.fieldOrigin( i ), other.fieldOriginIndex( i ) );
}
}
inline const QgsField& operator[]( int i ) const { return mFields[i].field; }
inline QgsField& operator[]( int i ) { return mFields[i].field; }
const QgsField& at( int i ) const { return mFields[i].field; }
Expand Down
3 changes: 2 additions & 1 deletion src/providers/ogr/qgsogrfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ bool QgsOgrFeatureIterator::nextFeature( QgsFeature& feature )
return false;
}

readFeature( fet, feature );
if ( readFeature( fet, feature ) )
OGR_F_Destroy( fet );

feature.setValid( true );
close(); // the feature has been read: we have finished here
Expand Down