QGIS API Documentation  2.11.0-Master
qgsvectorlayereditutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayereditutils.cpp
3  ---------------------
4  begin : Dezember 2012
5  copyright : (C) 2012 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
16 
17 #include "qgsvectordataprovider.h"
18 #include "qgsgeometrycache.h"
20 #include "qgslogger.h"
21 #include "qgspointv2.h"
22 
23 #include <limits>
24 
25 
27  : L( layer )
28 {
29 }
30 
31 bool QgsVectorLayerEditUtils::insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex )
32 {
33  if ( !L->hasGeometryType() )
34  return false;
35 
36  QgsGeometry geometry;
37  if ( !cache()->geometry( atFeatureId, geometry ) )
38  {
39  // it's not in cache: let's fetch it from layer
40  QgsFeature f;
41  if ( !L->getFeatures( QgsFeatureRequest().setFilterFid( atFeatureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.constGeometry() )
42  return false; // geometry not found
43 
44  geometry = *f.constGeometry();
45  }
46 
47  geometry.insertVertex( x, y, beforeVertex );
48 
49  L->editBuffer()->changeGeometry( atFeatureId, &geometry );
50  return true;
51 }
52 
53 
54 bool QgsVectorLayerEditUtils::moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex )
55 {
56  QgsPointV2 p( x, y );
57  return moveVertex( p, atFeatureId, atVertex );
58 }
59 
60 bool QgsVectorLayerEditUtils::moveVertex( const QgsPointV2& p, QgsFeatureId atFeatureId, int atVertex )
61 {
62  if ( !L->hasGeometryType() )
63  return false;
64 
65  QgsGeometry geometry;
66  if ( !cache()->geometry( atFeatureId, geometry ) )
67  {
68  // it's not in cache: let's fetch it from layer
69  QgsFeature f;
70  if ( !L->getFeatures( QgsFeatureRequest().setFilterFid( atFeatureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.constGeometry() )
71  return false; // geometry not found
72 
73  geometry = *f.constGeometry();
74  }
75 
76  geometry.moveVertex( p, atVertex );
77 
78  L->editBuffer()->changeGeometry( atFeatureId, &geometry );
79  return true;
80 }
81 
82 
83 bool QgsVectorLayerEditUtils::deleteVertex( QgsFeatureId atFeatureId, int atVertex )
84 {
85  if ( !L->hasGeometryType() )
86  return false;
87 
88  QgsGeometry geometry;
89  if ( !cache()->geometry( atFeatureId, geometry ) )
90  {
91  // it's not in cache: let's fetch it from layer
92  QgsFeature f;
93  if ( !L->getFeatures( QgsFeatureRequest().setFilterFid( atFeatureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.constGeometry() )
94  return false; // geometry not found
95 
96  geometry = *f.constGeometry();
97  }
98 
99  if ( !geometry.deleteVertex( atVertex ) )
100  return false;
101 
102  L->editBuffer()->changeGeometry( atFeatureId, &geometry );
103  return true;
104 }
105 
106 
108 {
109  if ( !L->hasGeometryType() )
110  return 5;
111 
112  int addRingReturnCode = 5; //default: return code for 'ring not inserted'
113  double xMin, yMin, xMax, yMax;
114  QgsRectangle bBox;
115 
116  if ( boundingBoxFromPointList( ring, xMin, yMin, xMax, yMax ) == 0 )
117  {
118  bBox.setXMinimum( xMin ); bBox.setYMinimum( yMin );
119  bBox.setXMaximum( xMax ); bBox.setYMaximum( yMax );
120  }
121  else
122  {
123  return 3; //ring not valid
124  }
125 
126  QgsFeatureIterator fit = L->getFeatures( QgsFeatureRequest().setFilterRect( bBox ).setFlags( QgsFeatureRequest::ExactIntersect ) );
127 
128  QgsFeature f;
129  while ( fit.nextFeature( f ) )
130  {
131  addRingReturnCode = f.geometry()->addRing( ring );
132  if ( addRingReturnCode == 0 )
133  {
134  L->editBuffer()->changeGeometry( f.id(), f.geometry() );
135 
136  //setModified( true, true );
137  break;
138  }
139  }
140 
141  return addRingReturnCode;
142 }
143 
144 
146 {
147  if ( !L->hasGeometryType() )
148  return 6;
149 
150  QgsGeometry geometry;
151  if ( !cache()->geometry( featureId, geometry ) ) // maybe it's in cache
152  {
153  // it's not in cache: let's fetch it from layer
154  QgsFeature f;
155  if ( !L->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.constGeometry() )
156  return 6; //geometry not found
157 
158  geometry = *f.constGeometry();
159  }
160 
161  int errorCode = geometry.addPart( points, L->geometryType() );
162  if ( errorCode == 0 )
163  {
164  L->editBuffer()->changeGeometry( featureId, &geometry );
165  }
166  return errorCode;
167 }
168 
169 
170 
171 int QgsVectorLayerEditUtils::translateFeature( QgsFeatureId featureId, double dx, double dy )
172 {
173  if ( !L->hasGeometryType() )
174  return 1;
175 
176  QgsGeometry geometry;
177  if ( !cache()->geometry( featureId, geometry ) ) // maybe it's in cache
178  {
179  // it's not in cache: let's fetch it from layer
180  QgsFeature f;
181  if ( !L->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.constGeometry() )
182  return 1; //geometry not found
183 
184  geometry = *f.constGeometry();
185  }
186 
187  int errorCode = geometry.translate( dx, dy );
188  if ( errorCode == 0 )
189  {
190  L->editBuffer()->changeGeometry( featureId, &geometry );
191  }
192  return errorCode;
193 }
194 
195 
196 int QgsVectorLayerEditUtils::splitFeatures( const QList<QgsPoint>& splitLine, bool topologicalEditing )
197 {
198  if ( !L->hasGeometryType() )
199  return 4;
200 
201  QgsFeatureList newFeatures; //store all the newly created features
202  double xMin, yMin, xMax, yMax;
203  QgsRectangle bBox; //bounding box of the split line
204  int returnCode = 0;
205  int splitFunctionReturn; //return code of QgsGeometry::splitGeometry
206  int numberOfSplittedFeatures = 0;
207 
208  QgsFeatureIterator features;
209  const QgsFeatureIds selectedIds = L->selectedFeaturesIds();
210 
211  if ( selectedIds.size() > 0 ) //consider only the selected features if there is a selection
212  {
213  features = L->selectedFeaturesIterator();
214  }
215  else //else consider all the feature that intersect the bounding box of the split line
216  {
217  if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) == 0 )
218  {
219  bBox.setXMinimum( xMin ); bBox.setYMinimum( yMin );
220  bBox.setXMaximum( xMax ); bBox.setYMaximum( yMax );
221  }
222  else
223  {
224  return 1;
225  }
226 
227  if ( bBox.isEmpty() )
228  {
229  //if the bbox is a line, try to make a square out of it
230  if ( bBox.width() == 0.0 && bBox.height() > 0 )
231  {
232  bBox.setXMinimum( bBox.xMinimum() - bBox.height() / 2 );
233  bBox.setXMaximum( bBox.xMaximum() + bBox.height() / 2 );
234  }
235  else if ( bBox.height() == 0.0 && bBox.width() > 0 )
236  {
237  bBox.setYMinimum( bBox.yMinimum() - bBox.width() / 2 );
238  bBox.setYMaximum( bBox.yMaximum() + bBox.width() / 2 );
239  }
240  else
241  {
242  //If we have a single point, we still create a non-null box
243  double bufferDistance = 0.000001;
244  if ( L->crs().geographicFlag() )
245  bufferDistance = 0.00000001;
246  bBox.setXMinimum( bBox.xMinimum() - bufferDistance );
247  bBox.setXMaximum( bBox.xMaximum() + bufferDistance );
248  bBox.setYMinimum( bBox.yMinimum() - bufferDistance );
249  bBox.setYMaximum( bBox.yMaximum() + bufferDistance );
250  }
251  }
252 
253  features = L->getFeatures( QgsFeatureRequest().setFilterRect( bBox ).setFlags( QgsFeatureRequest::ExactIntersect ) );
254  }
255 
256  QgsFeature feat;
257  while ( features.nextFeature( feat ) )
258  {
259  if ( !feat.constGeometry() )
260  {
261  continue;
262  }
263  QList<QgsGeometry*> newGeometries;
264  QList<QgsPoint> topologyTestPoints;
265  QgsGeometry* newGeometry = 0;
266  splitFunctionReturn = feat.geometry()->splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
267  if ( splitFunctionReturn == 0 )
268  {
269  //change this geometry
270  L->editBuffer()->changeGeometry( feat.id(), feat.geometry() );
271 
272  //insert new features
273  for ( int i = 0; i < newGeometries.size(); ++i )
274  {
275  newGeometry = newGeometries.at( i );
276  QgsFeature newFeature;
277  newFeature.setGeometry( newGeometry );
278 
279  //use default value where possible for primary key (e.g. autoincrement),
280  //and use the value from the original (split) feature if not primary key
281  QgsAttributes newAttributes = feat.attributes();
282  foreach ( int pkIdx, L->dataProvider()->pkAttributeIndexes() )
283  {
284  const QVariant defaultValue = L->dataProvider()->defaultValue( pkIdx );
285  if ( !defaultValue.isNull() )
286  {
287  newAttributes[ pkIdx ] = defaultValue;
288  }
289  else //try with NULL
290  {
291  newAttributes[ pkIdx ] = QVariant();
292  }
293  }
294 
295  newFeature.setAttributes( newAttributes );
296 
297  newFeatures.append( newFeature );
298  }
299 
300  if ( topologicalEditing )
301  {
302  QList<QgsPoint>::const_iterator topol_it = topologyTestPoints.constBegin();
303  for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
304  {
305  addTopologicalPoints( *topol_it );
306  }
307  }
308  ++numberOfSplittedFeatures;
309  }
310  else if ( splitFunctionReturn > 1 ) //1 means no split but also no error
311  {
312  returnCode = splitFunctionReturn;
313  }
314  }
315 
316  if ( numberOfSplittedFeatures == 0 && selectedIds.size() > 0 )
317  {
318  //There is a selection but no feature has been split.
319  //Maybe user forgot that only the selected features are split
320  returnCode = 4;
321  }
322 
323 
324  //now add the new features to this vectorlayer
325  L->editBuffer()->addFeatures( newFeatures );
326 
327  return returnCode;
328 }
329 
330 int QgsVectorLayerEditUtils::splitParts( const QList<QgsPoint>& splitLine, bool topologicalEditing )
331 {
332  if ( !L->hasGeometryType() )
333  return 4;
334 
335  double xMin, yMin, xMax, yMax;
336  QgsRectangle bBox; //bounding box of the split line
337  int returnCode = 0;
338  int splitFunctionReturn; //return code of QgsGeometry::splitGeometry
339  int numberOfSplittedParts = 0;
340 
341  QgsFeatureIterator fit;
342 
343  if ( L->selectedFeatureCount() > 0 ) //consider only the selected features if there is a selection
344  {
345  fit = L->selectedFeaturesIterator();
346  }
347  else //else consider all the feature that intersect the bounding box of the split line
348  {
349  if ( boundingBoxFromPointList( splitLine, xMin, yMin, xMax, yMax ) == 0 )
350  {
351  bBox.setXMinimum( xMin ); bBox.setYMinimum( yMin );
352  bBox.setXMaximum( xMax ); bBox.setYMaximum( yMax );
353  }
354  else
355  {
356  return 1;
357  }
358 
359  if ( bBox.isEmpty() )
360  {
361  //if the bbox is a line, try to make a square out of it
362  if ( bBox.width() == 0.0 && bBox.height() > 0 )
363  {
364  bBox.setXMinimum( bBox.xMinimum() - bBox.height() / 2 );
365  bBox.setXMaximum( bBox.xMaximum() + bBox.height() / 2 );
366  }
367  else if ( bBox.height() == 0.0 && bBox.width() > 0 )
368  {
369  bBox.setYMinimum( bBox.yMinimum() - bBox.width() / 2 );
370  bBox.setYMaximum( bBox.yMaximum() + bBox.width() / 2 );
371  }
372  else
373  {
374  //If we have a single point, we still create a non-null box
375  double bufferDistance = 0.000001;
376  if ( L->crs().geographicFlag() )
377  bufferDistance = 0.00000001;
378  bBox.setXMinimum( bBox.xMinimum() - bufferDistance );
379  bBox.setXMaximum( bBox.xMaximum() + bufferDistance );
380  bBox.setYMinimum( bBox.yMinimum() - bufferDistance );
381  bBox.setYMaximum( bBox.yMaximum() + bufferDistance );
382  }
383  }
384 
385  fit = L->getFeatures( QgsFeatureRequest().setFilterRect( bBox ).setFlags( QgsFeatureRequest::ExactIntersect ) );
386  }
387 
388  int addPartRet = 0;
389 
390  QgsFeature feat;
391  while ( fit.nextFeature( feat ) )
392  {
393  QList<QgsGeometry*> newGeometries;
394  QList<QgsPoint> topologyTestPoints;
395  splitFunctionReturn = feat.geometry()->splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
396  if ( splitFunctionReturn == 0 )
397  {
398  //add new parts
399  for ( int i = 0; i < newGeometries.size(); ++i )
400  {
401  addPartRet = feat.geometry()->addPart( newGeometries.at( i ) );
402  if ( addPartRet )
403  break;
404  }
405 
406  // For test only: Exception already thrown here...
407  // feat.geometry()->asWkb();
408 
409  if ( !addPartRet )
410  {
411  L->editBuffer()->changeGeometry( feat.id(), feat.geometry() );
412  }
413  else
414  {
415  // Test addPartRet
416  switch ( addPartRet )
417  {
418  case 1:
419  QgsDebugMsg( "Not a multipolygon" );
420  break;
421 
422  case 2:
423  QgsDebugMsg( "Not a valid geometry" );
424  break;
425 
426  case 3:
427  QgsDebugMsg( "New polygon ring" );
428  break;
429  }
430  }
431  L->editBuffer()->changeGeometry( feat.id(), feat.geometry() );
432 
433  if ( topologicalEditing )
434  {
435  QList<QgsPoint>::const_iterator topol_it = topologyTestPoints.constBegin();
436  for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
437  {
438  addTopologicalPoints( *topol_it );
439  }
440  }
441  ++numberOfSplittedParts;
442  }
443  else if ( splitFunctionReturn > 1 ) //1 means no split but also no error
444  {
445  returnCode = splitFunctionReturn;
446  }
447 
448  qDeleteAll( newGeometries );
449  }
450 
451  if ( numberOfSplittedParts == 0 && L->selectedFeatureCount() > 0 && returnCode == 0 )
452  {
453  //There is a selection but no feature has been split.
454  //Maybe user forgot that only the selected features are split
455  returnCode = 4;
456  }
457 
458  return returnCode;
459 }
460 
461 
463 {
464  if ( !L->hasGeometryType() )
465  return 1;
466 
467  if ( !geom )
468  {
469  return 1;
470  }
471 
472  int returnVal = 0;
473 
474  QGis::WkbType wkbType = geom->wkbType();
475 
476  switch ( wkbType )
477  {
478  //line
480  case QGis::WKBLineString:
481  {
482  QgsPolyline theLine = geom->asPolyline();
483  QgsPolyline::const_iterator line_it = theLine.constBegin();
484  for ( ; line_it != theLine.constEnd(); ++line_it )
485  {
486  if ( addTopologicalPoints( *line_it ) != 0 )
487  {
488  returnVal = 2;
489  }
490  }
491  break;
492  }
493 
494  //multiline
497  {
498  QgsMultiPolyline theMultiLine = geom->asMultiPolyline();
499  QgsPolyline currentPolyline;
500 
501  for ( int i = 0; i < theMultiLine.size(); ++i )
502  {
503  QgsPolyline::const_iterator line_it = currentPolyline.constBegin();
504  for ( ; line_it != currentPolyline.constEnd(); ++line_it )
505  {
506  if ( addTopologicalPoints( *line_it ) != 0 )
507  {
508  returnVal = 2;
509  }
510  }
511  }
512  break;
513  }
514 
515  //polygon
516  case QGis::WKBPolygon25D:
517  case QGis::WKBPolygon:
518  {
519  QgsPolygon thePolygon = geom->asPolygon();
520  QgsPolyline currentRing;
521 
522  for ( int i = 0; i < thePolygon.size(); ++i )
523  {
524  currentRing = thePolygon.at( i );
525  QgsPolyline::const_iterator line_it = currentRing.constBegin();
526  for ( ; line_it != currentRing.constEnd(); ++line_it )
527  {
528  if ( addTopologicalPoints( *line_it ) != 0 )
529  {
530  returnVal = 2;
531  }
532  }
533  }
534  break;
535  }
536 
537  //multipolygon
540  {
541  QgsMultiPolygon theMultiPolygon = geom->asMultiPolygon();
542  QgsPolygon currentPolygon;
543  QgsPolyline currentRing;
544 
545  for ( int i = 0; i < theMultiPolygon.size(); ++i )
546  {
547  currentPolygon = theMultiPolygon.at( i );
548  for ( int j = 0; j < currentPolygon.size(); ++j )
549  {
550  currentRing = currentPolygon.at( j );
551  QgsPolyline::const_iterator line_it = currentRing.constBegin();
552  for ( ; line_it != currentRing.constEnd(); ++line_it )
553  {
554  if ( addTopologicalPoints( *line_it ) != 0 )
555  {
556  returnVal = 2;
557  }
558  }
559  }
560  }
561  break;
562  }
563  default:
564  break;
565  }
566  return returnVal;
567 }
568 
569 
571 {
572  if ( !L->hasGeometryType() )
573  return 1;
574 
575  QMultiMap<double, QgsSnappingResult> snapResults; //results from the snapper object
576  //we also need to snap to vertex to make sure the vertex does not already exist in this geometry
577  QMultiMap<double, QgsSnappingResult> vertexSnapResults;
578 
579  QList<QgsSnappingResult> filteredSnapResults; //we filter out the results that are on existing vertices
580 
581  //work with a tolerance because coordinate projection may introduce some rounding
582  double threshold = 0.0000001;
583  if ( L->crs().mapUnits() == QGis::Meters )
584  {
585  threshold = 0.001;
586  }
587  else if ( L->crs().mapUnits() == QGis::Feet )
588  {
589  threshold = 0.0001;
590  }
591 
592 
593  if ( L->snapWithContext( p, threshold, snapResults, QgsSnapper::SnapToSegment ) != 0 )
594  {
595  return 2;
596  }
597 
600  for ( ; snap_it != snapResults.constEnd(); ++snap_it )
601  {
602  //test if p is already a vertex of this geometry. If yes, don't insert it
603  bool vertexAlreadyExists = false;
604  if ( L->snapWithContext( p, threshold, vertexSnapResults, QgsSnapper::SnapToVertex ) != 0 )
605  {
606  continue;
607  }
608 
609  vertex_snap_it = vertexSnapResults.constBegin();
610  for ( ; vertex_snap_it != vertexSnapResults.constEnd(); ++vertex_snap_it )
611  {
612  if ( snap_it.value().snappedAtGeometry == vertex_snap_it.value().snappedAtGeometry )
613  {
614  vertexAlreadyExists = true;
615  }
616  }
617 
618  if ( !vertexAlreadyExists )
619  {
620  filteredSnapResults.push_back( *snap_it );
621  }
622  }
623  insertSegmentVerticesForSnap( filteredSnapResults );
624  return 0;
625 }
626 
627 
629 {
630  if ( !L->hasGeometryType() )
631  return 1;
632 
633  int returnval = 0;
634  QgsPoint layerPoint;
635 
637  for ( ; it != snapResults.constEnd(); ++it )
638  {
639  if ( it->snappedVertexNr == -1 ) // segment snap
640  {
641  layerPoint = it->snappedVertex;
642  if ( !insertVertex( layerPoint.x(), layerPoint.y(), it->snappedAtGeometry, it->afterVertexNr ) )
643  {
644  returnval = 3;
645  }
646  }
647  }
648  return returnval;
649 }
650 
651 
652 
653 
654 int QgsVectorLayerEditUtils::boundingBoxFromPointList( const QList<QgsPoint>& list, double& xmin, double& ymin, double& xmax, double& ymax ) const
655 {
656  if ( list.size() < 1 )
657  {
658  return 1;
659  }
660 
665 
666  for ( QList<QgsPoint>::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
667  {
668  if ( it->x() < xmin )
669  {
670  xmin = it->x();
671  }
672  if ( it->x() > xmax )
673  {
674  xmax = it->x();
675  }
676  if ( it->y() < ymin )
677  {
678  ymin = it->y();
679  }
680  if ( it->y() > ymax )
681  {
682  ymax = it->y();
683  }
684  }
685 
686  return 0;
687 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:51
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
bool isEmpty() const
test if rectangle is empty.
int insertSegmentVerticesForSnap(const QList< QgsSnappingResult > &snapResults)
Inserts vertices to the snapped segments.
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:167
virtual 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.
void push_back(const T &value)
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:192
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
int size() const
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.
QgsPolygon asPolygon() const
Return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list...
const_iterator constEnd() const
const_iterator constBegin() const
const T & at(int i) const
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.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:75
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
Definition: qgsfeature.cpp:95
WkbType
Used for symbology operations.
Definition: qgis.h:53
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...
Definition: qgsfeature.h:162
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.
double x() const
Definition: qgspoint.h:126
int size() const
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.
Definition: qgsfeature.cpp:104
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
void append(const T &value)
bool isNull() const
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:197
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:182
const QgsFeatureIds & selectedFeaturesIds() const
Return reference to identifiers of selected features.
QgsAttributes attributes() const
Returns the feature's attributes.
Definition: qgsfeature.cpp:90
int addTopologicalPoints(const QgsGeometry *geom)
Adds topological points for every vertex of the geometry.
int snapWithContext(const QgsPoint &startPoint, double snappingTolerance, QMultiMap< double, QgsSnappingResult > &snappingResults, QgsSnapper::SnappingType snap_to)
Snaps to segment or vertex within given tolerance.
Point geometry type.
Definition: qgspointv2.h:29
bool geometry(QgsFeatureId fid, QgsGeometry &geometry)
fetch geometry from cache, return true if successful
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:172
bool deleteVertex(int atVertex)
Deletes the vertex at the given position number and item (first number is index 0) Returns false if a...
const_iterator constEnd() const
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)...
QList< int > QgsAttributeList
const T & value() const
QGis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
QGis::GeometryType geometryType() const
Returns point, line or polygon.
A class to represent a point.
Definition: qgspoint.h:63
int translate(double dx, double dy)
Translate this geometry by dx, dy.
QgsGeometry * geometry()
Get the geometry object associated with this feature.
Definition: qgsfeature.cpp:62
QgsFeatureIterator selectedFeaturesIterator(QgsFeatureRequest request=QgsFeatureRequest())
Get an iterator of the selected features.
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)...
const T & at(int i) const
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
const_iterator constBegin() const
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.
void setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:177
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
Definition: qgsfeature.cpp:68
qint64 QgsFeatureId
Definition: qgsfeature.h:31
double y() const
Definition: qgspoint.h:134
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
typedef const_iterator
int addRing(const QList< QgsPoint > &ring)
Adds a new ring to this geometry.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
const_iterator constEnd() const
bool nextFeature(QgsFeature &f)
const_iterator constBegin() const
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:202
A vector of attributes.
Definition: qgsfeature.h:109
int size() const
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.
int selectedFeatureCount()
The number of features that are selected in this layer.
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:187
virtual 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.
Definition: qgsrectangle.h:162
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:207
QgsVectorLayerEditUtils(QgsVectorLayer *layer)