Ejemplo n.º 1
0
bool QgsVectorLayerEditUtils::deleteVertex( QgsFeatureId atFeatureId, int atVertex )
{
  if ( !L->hasGeometryType() )
    return false;

  QgsGeometry geometry;
  if ( !cache()->geometry( atFeatureId, geometry ) )
  {
    // it's not in cache: let's fetch it from layer
    QgsFeature f;
    if ( !L->getFeatures( QgsFeatureRequest().setFilterFid( atFeatureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.constGeometry() )
      return false; // geometry not found

    geometry = *f.constGeometry();
  }

  if ( !geometry.deleteVertex( atVertex ) )
    return false;

  if ( geometry.geometry() && geometry.geometry()->nCoordinates() == 0 )
  {
    //last vertex deleted, set geometry to null
    geometry.setGeometry( 0 );
  }


  L->editBuffer()->changeGeometry( atFeatureId, &geometry );
  return true;
}
Ejemplo n.º 2
0
QgsVectorLayer::EditResult QgsVectorLayerEditUtils::deleteVertexV2( QgsFeatureId featureId, int vertex )
{
    if ( !L->hasGeometryType() )
        return QgsVectorLayer::InvalidLayer;

    QgsGeometry geometry;
    if ( !cache()->geometry( featureId, geometry ) )
    {
        // it's not in cache: let's fetch it from layer
        QgsFeature f;
        if ( !L->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.hasGeometry() )
            return QgsVectorLayer::FetchFeatureFailed; // geometry not found

        geometry = f.geometry();
    }

    if ( !geometry.deleteVertex( vertex ) )
        return QgsVectorLayer::EditFailed;

    if ( geometry.geometry() && geometry.geometry()->nCoordinates() == 0 )
    {
        //last vertex deleted, set geometry to null
        geometry.setGeometry( nullptr );
    }

    L->editBuffer()->changeGeometry( featureId, geometry );
    return !geometry.isEmpty() ? QgsVectorLayer::Success : QgsVectorLayer::EmptyGeometry;
}
bool QgsVectorLayerEditUtils::deleteVertex( QgsFeatureId atFeatureId, int atVertex )
{
  if ( !L->hasGeometryType() )
    return false;

  QgsGeometry geometry;
  if ( !cache()->geometry( atFeatureId, geometry ) )
    return false;   // TODO: support also uncached geometries

  if ( !geometry.deleteVertex( atVertex ) )
    return false;

  L->editBuffer()->changeGeometry( atFeatureId, &geometry );
  return true;
}
Ejemplo n.º 4
0
QgsVectorLayer::EditResult QgsVectorLayerEditUtils::deleteVertex( QgsFeatureId featureId, int vertex )
{
  if ( !mLayer->isSpatial() )
    return QgsVectorLayer::InvalidLayer;

  QgsFeature f;
  if ( !mLayer->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.hasGeometry() )
    return QgsVectorLayer::FetchFeatureFailed; // geometry not found

  QgsGeometry geometry = f.geometry();

  if ( !geometry.deleteVertex( vertex ) )
    return QgsVectorLayer::EditFailed;

  if ( geometry.constGet() && geometry.constGet()->nCoordinates() == 0 )
  {
    //last vertex deleted, set geometry to null
    geometry.set( nullptr );
  }

  mLayer->editBuffer()->changeGeometry( featureId, geometry );
  return !geometry.isNull() ? QgsVectorLayer::Success : QgsVectorLayer::EmptyGeometry;
}