Skip to content

Commit

Permalink
[ftools] Fix "Join attributes by location"
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 15, 2013
1 parent 54956db commit b6770be
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
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
5 changes: 2 additions & 3 deletions python/plugins/fTools/tools/doSpatialJoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,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 @@ -202,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
12 changes: 6 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
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

0 comments on commit b6770be

Please sign in to comment.