void Layer::joinConnectedFeatures() { // go through all label texts QString labelText; while ( !connectedTexts->isEmpty() ) { labelText = connectedTexts->takeFirst(); //std::cerr << "JOIN: " << labelText << std::endl; QHash< QString, QLinkedList<FeaturePart*>* >::const_iterator partsPtr = connectedHashtable->find( labelText ); if ( partsPtr == connectedHashtable->constEnd() ) continue; // shouldn't happen QLinkedList<FeaturePart*>* parts = *partsPtr; // go one-by-one part, try to merge while ( !parts->isEmpty() ) { // part we'll be checking against other in this round FeaturePart* partCheck = parts->takeFirst(); FeaturePart* otherPart = _findConnectedPart( partCheck, parts ); if ( otherPart ) { //std::cerr << "- connected " << partCheck << " with " << otherPart << std::endl; // remove partCheck from r-tree double bmin[2], bmax[2]; partCheck->getBoundingBox( bmin, bmax ); rtree->Remove( bmin, bmax, partCheck ); featureParts->removeOne( partCheck ); otherPart->getBoundingBox( bmin, bmax ); // merge points from partCheck to p->item if ( otherPart->mergeWithFeaturePart( partCheck ) ) { // reinsert p->item to r-tree (probably not needed) rtree->Remove( bmin, bmax, otherPart ); otherPart->getBoundingBox( bmin, bmax ); rtree->Insert( bmin, bmax, otherPart ); } } } // we're done processing feature parts with this particular label text delete parts; } // we're done processing connected fetures delete connectedHashtable; connectedHashtable = NULL; delete connectedTexts; connectedTexts = NULL; }
void Layer::joinConnectedFeatures() { // go through all label texts int connectedFeaturesId = 0; Q_FOREACH ( const QString& labelText, mConnectedTexts ) { if ( !mConnectedHashtable.contains( labelText ) ) continue; // shouldn't happen connectedFeaturesId++; QLinkedList<FeaturePart*>* parts = mConnectedHashtable.value( labelText ); // go one-by-one part, try to merge while ( !parts->isEmpty() && parts->count() > 1 ) { // part we'll be checking against other in this round FeaturePart* partCheck = parts->takeFirst(); FeaturePart* otherPart = _findConnectedPart( partCheck, parts ); if ( otherPart ) { // remove partCheck from r-tree double checkpartBMin[2], checkpartBMax[2]; partCheck->getBoundingBox( checkpartBMin, checkpartBMax ); double otherPartBMin[2], otherPartBMax[2]; otherPart->getBoundingBox( otherPartBMin, otherPartBMax ); // merge points from partCheck to p->item if ( otherPart->mergeWithFeaturePart( partCheck ) ) { // remove the parts we are joining from the index mFeatureIndex->Remove( checkpartBMin, checkpartBMax, partCheck ); mFeatureIndex->Remove( otherPartBMin, otherPartBMax, otherPart ); // reinsert merged line to r-tree (probably not needed) otherPart->getBoundingBox( otherPartBMin, otherPartBMax ); mFeatureIndex->Insert( otherPartBMin, otherPartBMax, otherPart ); mConnectedFeaturesIds.insert( partCheck->featureId(), connectedFeaturesId ); mConnectedFeaturesIds.insert( otherPart->featureId(), connectedFeaturesId ); mFeatureParts.removeOne( partCheck ); delete partCheck; } } } // we're done processing feature parts with this particular label text delete parts; mConnectedHashtable.remove( labelText ); } // we're done processing connected features //should be empty, but clear to be safe qDeleteAll( mConnectedHashtable ); mConnectedHashtable.clear(); mConnectedTexts.clear(); }