void QgsGeometryDuplicateNodesCheck::fixError( QgsGeometryCheckError* error, int method, int /*mergeAttributeIndex*/, Changes &changes ) const
{
  QgsFeature feature;
  if ( !mFeaturePool->get( error->featureId(), feature ) )
  {
    error->setObsolete();
    return;
  }
  QgsAbstractGeometryV2* geom = feature.geometry()->geometry();
  QgsVertexId vidx = error->vidx();

  // Check if point still exists
  if ( !vidx.isValid( geom ) )
  {
    error->setObsolete();
    return;
  }

  // Check if error still applies
  int nVerts = QgsGeomUtils::polyLineSize( geom, vidx.part, vidx.ring );
  QgsPointV2 pi = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + nVerts - 1 ) % nVerts ) );
  QgsPointV2 pj = geom->vertexAt( error->vidx() );
  if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) >= QgsGeometryCheckPrecision::tolerance() * QgsGeometryCheckPrecision::tolerance() )
  {
    error->setObsolete();
    return;
  }

  // Fix error
  if ( method == NoChange )
  {
    error->setFixed( method );
  }
  else if ( method == RemoveDuplicates )
  {
    geom->deleteVertex( error->vidx() );
    if ( QgsGeomUtils::polyLineSize( geom, vidx.part, vidx.ring ) < 3 )
    {
      error->setFixFailed( tr( "Resulting geometry is degenerate" ) );
    }
    else
    {
      mFeaturePool->updateFeature( feature );
      error->setFixed( method );
      changes[error->featureId()].append( Change( ChangeNode, ChangeRemoved, error->vidx() ) );
    }
  }
  else
  {
    error->setFixFailed( tr( "Unknown method" ) );
  }
}
示例#2
0
void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError* error, int method, int /*mergeAttributeIndex*/, Changes &changes ) const
{
    QgsFeature feature;
    if ( !mFeaturePool->get( error->featureId(), feature ) )
    {
        error->setObsolete();
        return;
    }
    QgsAbstractGeometryV2* geometry = feature.geometry()->geometry();
    const QgsVertexId& vidx = error->vidx();

    // Check if point still exists
    if ( !vidx.isValid( geometry ) )
    {
        error->setObsolete();
        return;
    }

    // Check if error still applies
    int n = QgsGeomUtils::polyLineSize( geometry, vidx.part, vidx.ring );
    const QgsPointV2& p1 = geometry->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex - 1 + n ) % n ) );
    const QgsPointV2& p2 = geometry->vertexAt( vidx );
    const QgsPointV2& p3 = geometry->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + 1 ) % n ) );
    QgsVector v21, v23;
    try
    {
        v21 = QgsVector( p1.x() - p2.x(), p1.y() - p2.y() ).normal();
        v23 = QgsVector( p3.x() - p2.x(), p3.y() - p2.y() ).normal();
    }
    catch ( const QgsException& )
    {
        error->setObsolete();
        return;
    }
    double angle = std::acos( v21 * v23 ) / M_PI * 180.0;
    if ( angle >= mMinAngle )
    {
        error->setObsolete();
        return;
    }

    // Fix error
    if ( method == NoChange )
    {
        error->setFixed( method );
    }
    else if ( method == DeleteNode )
    {

        if ( n <= 3 )
        {
            error->setFixFailed( tr( "Resulting geometry is degenerate" ) );
        }
        else
        {
            geometry->deleteVertex( vidx );
            mFeaturePool->updateFeature( feature );
            error->setFixed( method );
            changes[error->featureId()].append( Change( ChangeNode, ChangeRemoved, vidx ) );
        }
    }
    else
    {
        error->setFixFailed( tr( "Unknown method" ) );
    }
}