int QgsInterpolator::cacheBaseData() { if ( mLayerData.size() < 1 ) { return 0; } //reserve initial memory for 100000 vertices mCachedBaseData.clear(); mCachedBaseData.reserve( 100000 ); QList<LayerData>::iterator v_it = mLayerData.begin(); for ( ; v_it != mLayerData.end(); ++v_it ) { if ( v_it->vectorLayer == 0 ) { continue; } QgsVectorDataProvider* provider = v_it->vectorLayer->dataProvider(); if ( !provider ) { return 2; } QgsAttributeList attList; if ( !v_it->zCoordInterpolation ) { attList.push_back( v_it->interpolationAttribute ); } provider->select( attList ); QgsFeature theFeature; double attributeValue = 0.0; bool attributeConversionOk = false; while ( provider->nextFeature( theFeature ) ) { if ( !v_it->zCoordInterpolation ) { QgsAttributeMap attMap = theFeature.attributeMap(); QgsAttributeMap::const_iterator att_it = attMap.find( v_it->interpolationAttribute ); if ( att_it == attMap.end() ) //attribute not found, something must be wrong (e.g. NULL value) { continue; } attributeValue = att_it.value().toDouble( &attributeConversionOk ); if ( !attributeConversionOk || qIsNaN( attributeValue ) ) //don't consider vertices with attributes like 'nan' for the interpolation { continue; } } if ( addVerticesToCache( theFeature.geometry(), v_it->zCoordInterpolation, attributeValue ) != 0 ) { return 3; } } } return 0; }
int QgsInterpolator::cacheBaseData() { if ( mLayerData.size() < 1 ) { return 0; } //reserve initial memory for 100000 vertices mCachedBaseData.clear(); mCachedBaseData.reserve( 100000 ); Q_FOREACH ( const LayerData& layer, mLayerData ) { if ( !layer.vectorLayer ) { continue; } QgsVectorLayer* vlayer = layer.vectorLayer; if ( !vlayer ) { return 2; } QgsAttributeList attList; if ( !layer.zCoordInterpolation ) { attList.push_back( layer.interpolationAttribute ); } double attributeValue = 0.0; bool attributeConversionOk = false; QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( attList ) ); QgsFeature theFeature; while ( fit.nextFeature( theFeature ) ) { if ( !layer.zCoordInterpolation ) { QVariant attributeVariant = theFeature.attribute( layer.interpolationAttribute ); if ( !attributeVariant.isValid() ) //attribute not found, something must be wrong (e.g. NULL value) { continue; } attributeValue = attributeVariant.toDouble( &attributeConversionOk ); if ( !attributeConversionOk || qIsNaN( attributeValue ) ) //don't consider vertices with attributes like 'nan' for the interpolation { continue; } } if ( addVerticesToCache( theFeature.geometry(), layer.zCoordInterpolation, attributeValue ) != 0 ) { return 3; } } } return 0; }