105 int addRingReturnCode = 5;
106 double xMin, yMin, xMax, yMax;
125 if ( addRingReturnCode == 0 )
134 return addRingReturnCode;
155 if ( errorCode == 0 )
180 int errorCode = geometry.
translate( dx, dy );
181 if ( errorCode == 0 )
195 double xMin, yMin, xMax, yMax;
198 int splitFunctionReturn;
199 int numberOfSplittedFeatures = 0;
204 if ( selectedIds.size() > 0 )
228 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
236 double bufferDistance = 0.000001;
238 bufferDistance = 0.00000001;
253 QgsFeatureList::iterator select_it = featureList.begin();
254 for ( ; select_it != featureList.end(); ++select_it )
256 if ( !select_it->geometry() )
260 QList<QgsGeometry*> newGeometries;
261 QList<QgsPoint> topologyTestPoints;
263 splitFunctionReturn = select_it->geometry()->
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
264 if ( splitFunctionReturn == 0 )
270 for (
int i = 0; i < newGeometries.size(); ++i )
272 newGeometry = newGeometries.at( i );
282 if ( !defaultValue.isNull() )
284 newAttributes[ pkIdx ] = defaultValue;
288 newAttributes[ pkIdx ] = QVariant();
294 newFeatures.append( newFeature );
297 if ( topologicalEditing )
299 QList<QgsPoint>::const_iterator topol_it = topologyTestPoints.constBegin();
300 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
305 ++numberOfSplittedFeatures;
307 else if ( splitFunctionReturn > 1 )
309 returnCode = splitFunctionReturn;
313 if ( numberOfSplittedFeatures == 0 && selectedIds.size() > 0 )
332 double xMin, yMin, xMax, yMax;
335 int splitFunctionReturn;
336 int numberOfSplittedParts = 0;
341 if ( selectedIds.size() > 0 )
365 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
373 double bufferDistance = 0.000001;
375 bufferDistance = 0.00000001;
391 foreach (
const QgsFeature& feat, featureList )
393 QList<QgsGeometry*> newGeometries;
394 QList<QgsPoint> topologyTestPoints;
395 splitFunctionReturn = feat.
geometry()->
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
396 if ( splitFunctionReturn == 0 )
399 for (
int i = 0; i < newGeometries.size(); ++i )
416 switch ( addPartRet )
433 if ( topologicalEditing )
435 QList<QgsPoint>::const_iterator topol_it = topologyTestPoints.constBegin();
436 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
441 ++numberOfSplittedParts;
443 else if ( splitFunctionReturn > 1 )
445 returnCode = splitFunctionReturn;
448 qDeleteAll( newGeometries );
451 if ( numberOfSplittedParts == 0 && selectedIds.size() > 0 && returnCode == 0 )
483 QgsPolyline::const_iterator line_it = theLine.constBegin();
484 for ( ; line_it != theLine.constEnd(); ++line_it )
501 for (
int i = 0; i < theMultiLine.size(); ++i )
503 QgsPolyline::const_iterator line_it = currentPolyline.constBegin();
504 for ( ; line_it != currentPolyline.constEnd(); ++line_it )
522 for (
int i = 0; i < thePolygon.size(); ++i )
524 currentRing = thePolygon.at( i );
525 QgsPolyline::const_iterator line_it = currentRing.constBegin();
526 for ( ; line_it != currentRing.constEnd(); ++line_it )
545 for (
int i = 0; i < theMultiPolygon.size(); ++i )
547 currentPolygon = theMultiPolygon.at( i );
548 for (
int j = 0; j < currentPolygon.size(); ++j )
550 currentRing = currentPolygon.at( j );
551 QgsPolyline::const_iterator line_it = currentRing.constBegin();
552 for ( ; line_it != currentRing.constEnd(); ++line_it )
575 QMultiMap<double, QgsSnappingResult> snapResults;
577 QMultiMap<double, QgsSnappingResult> vertexSnapResults;
579 QList<QgsSnappingResult> filteredSnapResults;
582 double threshold = 0.0000001;
598 QMultiMap<double, QgsSnappingResult>::const_iterator snap_it = snapResults.constBegin();
599 QMultiMap<double, QgsSnappingResult>::const_iterator vertex_snap_it;
600 for ( ; snap_it != snapResults.constEnd(); ++snap_it )
603 bool vertexAlreadyExists =
false;
609 vertex_snap_it = vertexSnapResults.constBegin();
610 for ( ; vertex_snap_it != vertexSnapResults.constEnd(); ++vertex_snap_it )
612 if ( snap_it.value().snappedAtGeometry == vertex_snap_it.value().snappedAtGeometry )
614 vertexAlreadyExists =
true;
618 if ( !vertexAlreadyExists )
620 filteredSnapResults.push_back( *snap_it );
636 QList<QgsSnappingResult>::const_iterator it = snapResults.constBegin();
637 for ( ; it != snapResults.constEnd(); ++it )
639 if ( it->snappedVertexNr == -1 )
641 layerPoint = it->snappedVertex;
642 if ( !
insertVertex( layerPoint.
x(), layerPoint.
y(), it->snappedAtGeometry, it->afterVertexNr ) )
656 if ( list.size() < 1 )
666 for ( QList<QgsPoint>::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
668 if ( it->x() < xmin )
672 if ( it->x() > xmax )
676 if ( it->y() < ymin )
680 if ( it->y() > ymax )
QgsFeatureId id() const
Get the feature id for this feature.
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
bool isEmpty() const
test if rectangle is empty.
int insertSegmentVerticesForSnap(const QList< QgsSnappingResult > &snapResults)
Inserts vertices to the snapped segments.
QgsFeatureList selectedFeatures()
Get a copy of the user-selected features.
void setXMaximum(double x)
Set the maximum x value.
bool addFeatures(QgsFeatureList &features)
Insert a copy of the given features into the layer (but does not commit it)
Use exact geometry intersection (slower) instead of bounding boxes.
double yMaximum() const
Get the y maximum value (top side of rectangle)
QSet< QgsFeatureId > QgsFeatureIds
QList< QgsFeature > QgsFeatureList
QgsMultiPolyline asMultiPolyline() const
return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
QVector< QgsPoint > QgsPolyline
polyline is represented as a vector of points
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
QgsPolygon asPolygon() const
return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list ...
bool moveVertex(double x, double y, int atVertex)
Moves the vertex at the given position number and item (first number is index 0) to the given coordin...
int addPart(const QList< QgsPoint > &points, QGis::GeometryType geomType=QGis::UnknownGeometry)
Adds a new island polygon to a multipolygon feature.
void setAttributes(const QgsAttributes &attrs)
WkbType
Used for symbology operations.
int addPart(const QList< QgsPoint > &ring, QgsFeatureId featureId)
Adds a new part polygon to a multipart feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
virtual QgsAttributeList pkAttributeIndexes()
Return list of indexes of fields that make up the primary key.
bool insertVertex(double x, double y, int beforeVertex)
Insert a new vertex before the given vertex index, ring and item (first number is index 0) If the req...
bool deleteVertex(QgsFeatureId atFeatureId, int atVertex)
Deletes a vertex from a feature.
int boundingBoxFromPointList(const QList< QgsPoint > &list, double &xmin, double &ymin, double &xmax, double &ymax) const
Little helper function that gives bounding box from a list of points.
QgsMultiPolygon asMultiPolygon() const
return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty ...
double ANALYSIS_EXPORT max(double x, double y)
returns the maximum of two doubles or the first argument if both are equal
int splitGeometry(const QList< QgsPoint > &splitLine, QList< QgsGeometry * > &newGeometries, bool topological, QList< QgsPoint > &topologyTestPoints)
Splits this geometry according to a given line.
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object (deep copy)
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
const QgsFeatureIds & selectedFeaturesIds() const
Return reference to identifiers of selected features.
int snapWithContext(const QgsPoint &startPoint, double snappingTolerance, QMultiMap< double, QgsSnappingResult > &snappingResults, QgsSnapper::SnappingType snap_to)
Snaps to segment or vertex within given tolerance.
bool geometry(QgsFeatureId fid, QgsGeometry &geometry)
fetch geometry from cache, return true if successful
int addTopologicalPoints(QgsGeometry *geom)
Adds topological points for every vertex of the geometry.
void setYMinimum(double y)
Set the minimum y value.
bool deleteVertex(int atVertex)
Deletes the vertex at the given position number and item (first number is index 0) Returns false if a...
int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
bool moveVertex(double x, double y, QgsFeatureId atFeatureId, int atVertex)
Moves the vertex at the given position number, ring and item (first number is index 0)...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QVector< QgsPolygon > QgsMultiPolygon
a collection of QgsPolygons that share a common collection of attributes
QList< int > QgsAttributeList
QGis::WkbType wkbType() const
Returns type of wkb (point / linestring / polygon etc.)
QGis::GeometryType geometryType() const
Returns point, line or polygon.
QVector< QgsPolyline > QgsPolygon
polygon: first item of the list is outer ring, inner rings (if any) start from second item ...
A class to represent a point geometry.
int translate(double dx, double dy)
Translate this geometry by dx, dy.
QgsGeometryCache * cache()
QVector< QgsPolyline > QgsMultiPolyline
a collection of QgsPolylines that share a common collection of attributes
QgsPolyline asPolyline() const
return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list ...
bool insertVertex(double x, double y, QgsFeatureId atFeatureId, int beforeVertex)
Insert a new vertex before the given vertex number, in the given ring, item (first number is index 0)...
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
int addRing(const QList< QgsPoint > &ring)
Adds a ring to polygon/multipolygon features.
virtual QVariant defaultValue(int fieldId)
Returns the default value for field specified by fieldId.
QVector< QVariant > QgsAttributes
void setYMaximum(double y)
Set the maximum y value.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
int addRing(const QList< QgsPoint > &ring)
Adds a new ring to this geometry.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
bool nextFeature(QgsFeature &f)
double width() const
Width of the rectangle.
Represents a vector layer which manages a vector based data sets.
bool geographicFlag() const
int splitParts(const QList< QgsPoint > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
double xMinimum() const
Get the x minimum value (left side of rectangle)
bool changeGeometry(QgsFeatureId fid, QgsGeometry *geom)
change feature's geometry
int splitFeatures(const QList< QgsPoint > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
void setXMinimum(double x)
Set the minimum x value.
double height() const
Height of the rectangle.
QgsVectorLayerEditUtils(QgsVectorLayer *layer)
QGis::UnitType mapUnits() const