84 int addRingReturnCode = 5;
85 double xMin, yMin, xMax, yMax;
104 if ( addRingReturnCode == 0 )
113 return addRingReturnCode;
134 if ( errorCode == 0 )
159 int errorCode = geometry.
translate( dx, dy );
160 if ( errorCode == 0 )
174 double xMin, yMin, xMax, yMax;
177 int splitFunctionReturn;
178 int numberOfSplittedFeatures = 0;
183 if ( selectedIds.size() > 0 )
207 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
225 QgsFeatureList::iterator select_it = featureList.begin();
226 for ( ; select_it != featureList.end(); ++select_it )
228 if ( !select_it->geometry() )
232 QList<QgsGeometry*> newGeometries;
233 QList<QgsPoint> topologyTestPoints;
235 splitFunctionReturn = select_it->geometry()->
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
236 if ( splitFunctionReturn == 0 )
242 for (
int i = 0; i < newGeometries.size(); ++i )
244 newGeometry = newGeometries.at( i );
254 if ( !defaultValue.isNull() )
256 newAttributes[ pkIdx ] = defaultValue;
260 newAttributes[ pkIdx ] = QVariant();
266 newFeatures.append( newFeature );
269 if ( topologicalEditing )
271 QList<QgsPoint>::const_iterator topol_it = topologyTestPoints.constBegin();
272 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
277 ++numberOfSplittedFeatures;
279 else if ( splitFunctionReturn > 1 )
281 returnCode = splitFunctionReturn;
285 if ( numberOfSplittedFeatures == 0 && selectedIds.size() > 0 )
304 double xMin, yMin, xMax, yMax;
307 int splitFunctionReturn;
308 int numberOfSplittedParts = 0;
313 if ( selectedIds.size() > 0 )
337 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
356 foreach (
const QgsFeature& feat, featureList )
358 QList<QgsGeometry*> newGeometries;
359 QList<QgsPoint> topologyTestPoints;
360 splitFunctionReturn = feat.
geometry()->
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
361 if ( splitFunctionReturn == 0 )
364 for (
int i = 0; i < newGeometries.size(); ++i )
381 switch ( addPartRet )
398 if ( topologicalEditing )
400 QList<QgsPoint>::const_iterator topol_it = topologyTestPoints.constBegin();
401 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
406 ++numberOfSplittedParts;
408 else if ( splitFunctionReturn > 1 )
410 returnCode = splitFunctionReturn;
413 qDeleteAll( newGeometries );
416 if ( numberOfSplittedParts == 0 && selectedIds.size() > 0 && returnCode == 0 )
448 QgsPolyline::const_iterator line_it = theLine.constBegin();
449 for ( ; line_it != theLine.constEnd(); ++line_it )
466 for (
int i = 0; i < theMultiLine.size(); ++i )
468 QgsPolyline::const_iterator line_it = currentPolyline.constBegin();
469 for ( ; line_it != currentPolyline.constEnd(); ++line_it )
487 for (
int i = 0; i < thePolygon.size(); ++i )
489 currentRing = thePolygon.at( i );
490 QgsPolyline::const_iterator line_it = currentRing.constBegin();
491 for ( ; line_it != currentRing.constEnd(); ++line_it )
510 for (
int i = 0; i < theMultiPolygon.size(); ++i )
512 currentPolygon = theMultiPolygon.at( i );
513 for (
int j = 0; j < currentPolygon.size(); ++j )
515 currentRing = currentPolygon.at( j );
516 QgsPolyline::const_iterator line_it = currentRing.constBegin();
517 for ( ; line_it != currentRing.constEnd(); ++line_it )
540 QMultiMap<double, QgsSnappingResult> snapResults;
542 QMultiMap<double, QgsSnappingResult> vertexSnapResults;
544 QList<QgsSnappingResult> filteredSnapResults;
547 double threshold = 0.0000001;
563 QMultiMap<double, QgsSnappingResult>::const_iterator snap_it = snapResults.constBegin();
564 QMultiMap<double, QgsSnappingResult>::const_iterator vertex_snap_it;
565 for ( ; snap_it != snapResults.constEnd(); ++snap_it )
568 bool vertexAlreadyExists =
false;
574 vertex_snap_it = vertexSnapResults.constBegin();
575 for ( ; vertex_snap_it != vertexSnapResults.constEnd(); ++vertex_snap_it )
577 if ( snap_it.value().snappedAtGeometry == vertex_snap_it.value().snappedAtGeometry )
579 vertexAlreadyExists =
true;
583 if ( !vertexAlreadyExists )
585 filteredSnapResults.push_back( *snap_it );
601 QList<QgsSnappingResult>::const_iterator it = snapResults.constBegin();
602 for ( ; it != snapResults.constEnd(); ++it )
604 if ( it->snappedVertexNr == -1 )
606 layerPoint = it->snappedVertex;
607 if ( !
insertVertex( layerPoint.
x(), layerPoint.
y(), it->snappedAtGeometry, it->afterVertexNr ) )
621 if ( list.size() < 1 )
631 for ( QList<QgsPoint>::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
633 if ( it->x() < xmin )
637 if ( it->x() > xmax )
641 if ( it->y() < ymin )
645 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.
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