Quantum GIS API Documentation
1.8
|
The QGis class provides vector geometry analysis functions. More...
#include <qgsgeometryanalyzer.h>
Public Member Functions | |
bool | simplify (QgsVectorLayer *layer, const QString &shapefileName, double tolerance, bool onlySelectedFeatures=false, QProgressDialog *p=0) |
Simplify vector layer using (a modified) Douglas-Peucker algorithm and write it to a new shape file. | |
bool | centroids (QgsVectorLayer *layer, const QString &shapefileName, bool onlySelectedFeatures=false, QProgressDialog *p=0) |
Calculate the true centroids, or 'center of mass' for a vector layer and write it to a new shape file. | |
bool | extent (QgsVectorLayer *layer, const QString &shapefileName, bool onlySelectedFeatures=false, QProgressDialog *p=0) |
Create a polygon based on the extent of all (selected) features and write it to a new shape file. | |
bool | buffer (QgsVectorLayer *layer, const QString &shapefileName, double bufferDistance, bool onlySelectedFeatures=false, bool dissolve=false, int bufferDistanceField=-1, QProgressDialog *p=0) |
Create buffers for a vector layer and write it to a new shape file. | |
bool | convexHull (QgsVectorLayer *layer, const QString &shapefileName, bool onlySelectedFeatures=false, int uniqueIdField=-1, QProgressDialog *p=0) |
Create convex hull(s) of a vector layer and write it to a new shape file. | |
bool | dissolve (QgsVectorLayer *layer, const QString &shapefileName, bool onlySelectedFeatures=false, int uniqueIdField=-1, QProgressDialog *p=0) |
Dissolve a vector layer and write it to a new shape file. | |
bool | eventLayer (QgsVectorLayer *lineLayer, QgsVectorLayer *eventLayer, int lineField, int eventField, QList< int > &unlocatedFeatureIds, const QString &outputLayer, const QString &outputFormat, int locationField1, int locationField2=-1, int offsetField=-1, double offsetScale=1.0, bool forceSingleGeometry=false, QgsVectorDataProvider *memoryProvider=0, QProgressDialog *p=0) |
Creates an event layer (multipoint or multiline) by locating features from a (non-spatial) event table along the features of a line layer. | |
QgsGeometry * | locateBetweenMeasures (double fromMeasure, double toMeasure, QgsGeometry *lineGeom) |
Returns linear reference geometry as a multiline (or 0 if no match). | |
QgsGeometry * | locateAlongMeasure (double measure, QgsGeometry *lineGeom) |
Returns linear reference geometry. | |
Private Member Functions | |
QList< double > | simpleMeasure (QgsGeometry *geometry) |
double | perimeterMeasure (QgsGeometry *geometry, QgsDistanceArea &measure) |
void | simplifyFeature (QgsFeature &f, QgsVectorFileWriter *vfw, double tolerance) |
Helper function to simplify an individual feature. | |
void | centroidFeature (QgsFeature &f, QgsVectorFileWriter *vfw) |
Helper function to get the cetroid of an individual feature. | |
void | bufferFeature (QgsFeature &f, int nProcessedFeatures, QgsVectorFileWriter *vfw, bool dissolve, QgsGeometry **dissolveGeometry, double bufferDistance, int bufferDistanceField) |
Helper function to buffer an individual feature. | |
void | convexFeature (QgsFeature &f, int nProcessedFeatures, QgsGeometry **dissolveGeometry) |
Helper function to get the convex hull of feature(s) | |
void | dissolveFeature (QgsFeature &f, int nProcessedFeatures, QgsGeometry **dissolveGeometry) |
Helper function to dissolve feature(s) | |
void | addEventLayerFeature (QgsFeature &feature, QgsGeometry *geom, QgsGeometry *lineGeom, QgsVectorFileWriter *fileWriter, QgsFeatureList &memoryFeatures, int offsetField=-1, double offsetScale=1.0, bool forceSingleType=false) |
void | createOffsetGeometry (QgsGeometry *geom, QgsGeometry *lineGeom, double offset) |
Create geometry offset relative to line geometry. | |
QgsPoint | createPointOffset (double x, double y, double dist, QgsGeometry *lineGeom) const |
unsigned char * | locateBetweenWkbString (unsigned char *ptr, QgsMultiPolyline &result, double fromMeasure, double toMeasure) |
unsigned char * | locateAlongWkbString (unsigned char *ptr, QgsMultiPoint &result, double measure) |
Static Private Member Functions | |
static bool | clipSegmentByRange (double x1, double y1, double m1, double x2, double y2, double m2, double range1, double range2, QgsPoint &pt1, QgsPoint &pt2, bool &secondPointClipped) |
static void | locateAlongSegment (double x1, double y1, double m1, double x2, double y2, double m2, double measure, bool &pt1Ok, QgsPoint &pt1, bool &pt2Ok, QgsPoint &pt2) |
The QGis class provides vector geometry analysis functions.
Definition at line 36 of file qgsgeometryanalyzer.h.
void QgsGeometryAnalyzer::addEventLayerFeature | ( | QgsFeature & | feature, |
QgsGeometry * | geom, | ||
QgsGeometry * | lineGeom, | ||
QgsVectorFileWriter * | fileWriter, | ||
QgsFeatureList & | memoryFeatures, | ||
int | offsetField = -1 , |
||
double | offsetScale = 1.0 , |
||
bool | forceSingleType = false |
||
) | [private] |
Definition at line 1038 of file qgsgeometryanalyzer.cpp.
References QgsVectorFileWriter::addFeature(), QgsGeometry::asGeometryCollection(), QgsFeature::attributeMap(), createOffsetGeometry(), and QgsFeature::setGeometry().
Referenced by eventLayer().
bool QgsGeometryAnalyzer::buffer | ( | QgsVectorLayer * | layer, |
const QString & | shapefileName, | ||
double | bufferDistance, | ||
bool | onlySelectedFeatures = false , |
||
bool | dissolve = false , |
||
int | bufferDistanceField = -1 , |
||
QProgressDialog * | p = 0 |
||
) |
Create buffers for a vector layer and write it to a new shape file.
layer | input vector layer |
shapefileName | path to the output shp |
bufferDistance | distance for buffering (if no buffer field is specified) |
onlySelectedFeatures | if true, only selected features are considered, else all the features |
dissolve | if true, merge all the buffers to a big multipolygon |
bufferDistanceField | index of the attribute field that contains the buffer distance (or -1 if all features have the same buffer distance) |
p | progress dialog (or 0 if no progress dialog is to be shown) |
Definition at line 753 of file qgsgeometryanalyzer.cpp.
References bufferFeature(), QgsMapLayer::crs(), QgsVectorLayer::dataProvider(), dissolveFeature(), QgsVectorDataProvider::encoding(), QgsVectorLayer::featureAtId(), QgsVectorLayer::featureCount(), QgsVectorDataProvider::fields(), QgsVectorLayer::nextFeature(), QgsVectorLayer::pendingAllAttributesList(), QgsDebugMsg, QgsVectorLayer::select(), QgsVectorLayer::selectedFeaturesIds(), QgsFeature::setGeometry(), QGis::WKBMultiPolygon, and QGis::WKBPolygon.
void QgsGeometryAnalyzer::bufferFeature | ( | QgsFeature & | f, |
int | nProcessedFeatures, | ||
QgsVectorFileWriter * | vfw, | ||
bool | dissolve, | ||
QgsGeometry ** | dissolveGeometry, | ||
double | bufferDistance, | ||
int | bufferDistanceField | ||
) | [private] |
Helper function to buffer an individual feature.
Definition at line 860 of file qgsgeometryanalyzer.cpp.
References QgsVectorFileWriter::addFeature(), QgsFeature::attributeMap(), QgsGeometry::buffer(), QgsGeometry::combine(), QgsFeature::geometry(), QgsFeature::setAttributeMap(), and QgsFeature::setGeometry().
Referenced by buffer().
void QgsGeometryAnalyzer::centroidFeature | ( | QgsFeature & | f, |
QgsVectorFileWriter * | vfw | ||
) | [private] |
Helper function to get the cetroid of an individual feature.
Definition at line 240 of file qgsgeometryanalyzer.cpp.
References QgsVectorFileWriter::addFeature(), QgsFeature::attributeMap(), QgsGeometry::centroid(), QgsFeature::geometry(), QgsFeature::setAttributeMap(), and QgsFeature::setGeometry().
Referenced by centroids().
bool QgsGeometryAnalyzer::centroids | ( | QgsVectorLayer * | layer, |
const QString & | shapefileName, | ||
bool | onlySelectedFeatures = false , |
||
QProgressDialog * | p = 0 |
||
) |
Calculate the true centroids, or 'center of mass' for a vector layer and write it to a new shape file.
layer | input vector layer |
shapefileName | path to the output shp |
onlySelectedFeatures | if true, only selected features are considered, else all the features |
p | progress dialog (or 0 if no progress dialog is to be shown) |
Definition at line 147 of file qgsgeometryanalyzer.cpp.
References centroidFeature(), QgsMapLayer::crs(), QgsVectorLayer::dataProvider(), QgsVectorDataProvider::encoding(), QgsVectorLayer::featureAtId(), QgsVectorLayer::featureCount(), QgsVectorDataProvider::fields(), QgsVectorLayer::nextFeature(), QgsVectorLayer::pendingAllAttributesList(), QgsDebugMsg, QgsVectorLayer::select(), QgsVectorLayer::selectedFeaturesIds(), and QGis::WKBPoint.
bool QgsGeometryAnalyzer::clipSegmentByRange | ( | double | x1, |
double | y1, | ||
double | m1, | ||
double | x2, | ||
double | y2, | ||
double | m2, | ||
double | range1, | ||
double | range2, | ||
QgsPoint & | pt1, | ||
QgsPoint & | pt2, | ||
bool & | secondPointClipped | ||
) | [static, private] |
Definition at line 1358 of file qgsgeometryanalyzer.cpp.
References QgsPoint::setX(), and QgsPoint::setY().
Referenced by locateBetweenWkbString().
void QgsGeometryAnalyzer::convexFeature | ( | QgsFeature & | f, |
int | nProcessedFeatures, | ||
QgsGeometry ** | dissolveGeometry | ||
) | [private] |
Helper function to get the convex hull of feature(s)
Definition at line 570 of file qgsgeometryanalyzer.cpp.
References QgsGeometry::combine(), QgsGeometry::convexHull(), and QgsFeature::geometry().
Referenced by convexHull().
bool QgsGeometryAnalyzer::convexHull | ( | QgsVectorLayer * | layer, |
const QString & | shapefileName, | ||
bool | onlySelectedFeatures = false , |
||
int | uniqueIdField = -1 , |
||
QProgressDialog * | p = 0 |
||
) |
Create convex hull(s) of a vector layer and write it to a new shape file.
layer | input vector layer |
shapefileName | path to the output shp |
onlySelectedFeatures | if true, only selected features are considered, else all the features |
uniqueIdField | index of the attribute field that contains the unique convex hull id (or -1 if all features have the same buffer distance) |
p | progress dialog (or 0 if no progress dialog is to be shown) |
Definition at line 386 of file qgsgeometryanalyzer.cpp.
References convexFeature(), QgsGeometry::convexHull(), QgsMapLayer::crs(), QgsVectorLayer::dataProvider(), dissolveFeature(), QgsVectorDataProvider::encoding(), QgsVectorLayer::featureAtId(), QgsVectorLayer::featureCount(), QgsVectorLayer::nextFeature(), QgsVectorLayer::pendingAllAttributesList(), QgsDebugMsg, QgsVectorLayer::select(), QgsVectorLayer::selectedFeaturesIds(), QgsFeature::setAttributeMap(), QgsFeature::setGeometry(), simpleMeasure(), and QGis::WKBPolygon.
void QgsGeometryAnalyzer::createOffsetGeometry | ( | QgsGeometry * | geom, |
QgsGeometry * | lineGeom, | ||
double | offset | ||
) | [private] |
Create geometry offset relative to line geometry.
geom | the geometry to modify |
lineGeom | the line geometry to which the feature is referenced |
offset | the offset value in layer unit. Negative values mean offset towards left, positive values offset to the right side |
Definition at line 1084 of file qgsgeometryanalyzer.cpp.
References QgsGeometry::asGeometryCollection(), createPointOffset(), QgsGeometry::fromGeos(), QgsGeometry::isMultipart(), QGis::Line, QGis::Point, QgsGeometry::type(), QgsPoint::x(), and QgsPoint::y().
Referenced by addEventLayerFeature().
QgsPoint QgsGeometryAnalyzer::createPointOffset | ( | double | x, |
double | y, | ||
double | dist, | ||
QgsGeometry * | lineGeom | ||
) | const [private] |
Definition at line 1157 of file qgsgeometryanalyzer.cpp.
References QgsGeometry::closestSegmentWithContext(), QgsGeometry::vertexAt(), QgsPoint::x(), and QgsPoint::y().
Referenced by createOffsetGeometry().
bool QgsGeometryAnalyzer::dissolve | ( | QgsVectorLayer * | layer, |
const QString & | shapefileName, | ||
bool | onlySelectedFeatures = false , |
||
int | uniqueIdField = -1 , |
||
QProgressDialog * | p = 0 |
||
) |
Dissolve a vector layer and write it to a new shape file.
layer | input vector layer |
shapefileName | path to the output shp |
onlySelectedFeatures | if true, only selected features are considered, else all the features |
uniqueIdField | index of the attribute field that contains the unique id to dissolve on (or -1 if all features should be dissolved together) |
p | progress dialog (or 0 if no progress dialog is to be shown) |
Definition at line 596 of file qgsgeometryanalyzer.cpp.
References QgsMapLayer::crs(), QgsVectorLayer::dataProvider(), dissolveFeature(), QgsVectorDataProvider::encoding(), QgsVectorLayer::featureAtId(), QgsVectorLayer::featureCount(), QgsVectorDataProvider::fields(), QgsVectorDataProvider::geometryType(), QgsVectorLayer::nextFeature(), QgsVectorLayer::pendingAllAttributesList(), QgsVectorLayer::select(), QgsVectorLayer::selectedFeaturesIds(), QgsFeature::setAttributeMap(), and QgsFeature::setGeometry().
void QgsGeometryAnalyzer::dissolveFeature | ( | QgsFeature & | f, |
int | nProcessedFeatures, | ||
QgsGeometry ** | dissolveGeometry | ||
) | [private] |
Helper function to dissolve feature(s)
Definition at line 730 of file qgsgeometryanalyzer.cpp.
References QgsGeometry::asWkb(), QgsGeometry::combine(), QgsFeature::geometry(), and QgsGeometry::wkbSize().
Referenced by buffer(), convexHull(), and dissolve().
bool QgsGeometryAnalyzer::eventLayer | ( | QgsVectorLayer * | lineLayer, |
QgsVectorLayer * | eventLayer, | ||
int | lineField, | ||
int | eventField, | ||
QList< int > & | unlocatedFeatureIds, | ||
const QString & | outputLayer, | ||
const QString & | outputFormat, | ||
int | locationField1, | ||
int | locationField2 = -1 , |
||
int | offsetField = -1 , |
||
double | offsetScale = 1.0 , |
||
bool | forceSingleGeometry = false , |
||
QgsVectorDataProvider * | memoryProvider = 0 , |
||
QProgressDialog * | p = 0 |
||
) |
Creates an event layer (multipoint or multiline) by locating features from a (non-spatial) event table along the features of a line layer.
Note that currently (until QgsGeometry supports m-values) the z-coordinate of the line layer is used for linear referencing
lineLayer | layer with the line geometry |
eventLayer | layer with features and location field |
lineField | join index in line layer |
eventField | join index in event layer |
outputLayer | name of output file (can be empty if a memory layer is used) |
outputFormat | name of output format (can be empty if a memory provider is used to store the results) |
unlocatedFeatureIds | out: ids of event features where linear referencing was not successful |
locationField1 | attribute index of location field in event layer |
locationField2 | attribute index of location end field (or -1 for point layer) |
offsetField | attribute index for offset field. Negative offset value = offset to left side, positive value = offset to right side |
offsetScale | factor to scale offset |
forceSingleGeometry | force layer to single point/line type. Feature attributes are copied in case of multiple matches |
memoryProvider | memory provider to write output to (can be 0 if output is written to a file) |
p | progress dialog or 0 if no progress dialog should be shown |
Definition at line 912 of file qgsgeometryanalyzer.cpp.
References QgsVectorDataProvider::addAttributes(), addEventLayerFeature(), QgsVectorDataProvider::addFeatures(), QgsFeature::attributeMap(), QgsMapLayer::crs(), QgsVectorLayer::dataProvider(), QgsVectorDataProvider::encoding(), QgsVectorLayer::featureAtId(), QgsFeature::geometry(), QgsFeature::id(), QgsMapLayer::isValid(), locateAlongMeasure(), locateBetweenMeasures(), QgsVectorLayer::nextFeature(), QgsVectorLayer::pendingAllAttributesList(), QgsVectorLayer::pendingFeatureCount(), QgsVectorLayer::pendingFields(), QgsVectorLayer::select(), QGis::WKBLineString, QGis::WKBMultiLineString, QGis::WKBMultiPoint, and QGis::WKBPoint.
bool QgsGeometryAnalyzer::extent | ( | QgsVectorLayer * | layer, |
const QString & | shapefileName, | ||
bool | onlySelectedFeatures = false , |
||
QProgressDialog * | p = 0 |
||
) |
Create a polygon based on the extent of all (selected) features and write it to a new shape file.
layer | input vector layer |
shapefileName | path to the output shp |
onlySelectedFeatures | if true, only selected features are considered, else all the features |
p | progress dialog (or 0 if no progress dialog is to be shown) |
Definition at line 263 of file qgsgeometryanalyzer.cpp.
References QgsVectorLayer::boundingBoxOfSelected(), QgsMapLayer::crs(), QgsVectorLayer::dataProvider(), QgsVectorDataProvider::encoding(), QgsMapLayer::extent(), QgsGeometry::fromRect(), QgsFeature::setAttributeMap(), QgsFeature::setGeometry(), QGis::WKBPolygon, and QgsRectangle::xMinimum().
QgsGeometry * QgsGeometryAnalyzer::locateAlongMeasure | ( | double | measure, |
QgsGeometry * | lineGeom | ||
) |
Returns linear reference geometry.
Unlike the PostGIS function, this method always returns multipoint or 0 if no match (not geometry collection). Currently, the z-coordinates are considered to be the measures (no support for m-values in QGIS)
Definition at line 1226 of file qgsgeometryanalyzer.cpp.
References QgsGeometry::asWkb(), QgsGeometry::fromMultiPoint(), locateAlongWkbString(), QGis::WKBLineString25D, and QGis::WKBMultiLineString25D.
Referenced by eventLayer().
void QgsGeometryAnalyzer::locateAlongSegment | ( | double | x1, |
double | y1, | ||
double | m1, | ||
double | x2, | ||
double | y2, | ||
double | m2, | ||
double | measure, | ||
bool & | pt1Ok, | ||
QgsPoint & | pt1, | ||
bool & | pt2Ok, | ||
QgsPoint & | pt2 | ||
) | [static, private] |
Definition at line 1453 of file qgsgeometryanalyzer.cpp.
References doubleNear(), QgsPoint::setX(), and QgsPoint::setY().
Referenced by locateAlongWkbString().
unsigned char * QgsGeometryAnalyzer::locateAlongWkbString | ( | unsigned char * | ptr, |
QgsMultiPoint & | result, | ||
double | measure | ||
) | [private] |
Definition at line 1322 of file qgsgeometryanalyzer.cpp.
References locateAlongSegment().
Referenced by locateAlongMeasure().
QgsGeometry * QgsGeometryAnalyzer::locateBetweenMeasures | ( | double | fromMeasure, |
double | toMeasure, | ||
QgsGeometry * | lineGeom | ||
) |
Returns linear reference geometry as a multiline (or 0 if no match).
Currently, the z-coordinates are considered to be the measures (no support for m-values in QGIS)
Definition at line 1182 of file qgsgeometryanalyzer.cpp.
References QgsGeometry::asWkb(), QgsGeometry::fromMultiPolyline(), locateBetweenWkbString(), QGis::WKBLineString25D, and QGis::WKBMultiLineString25D.
Referenced by eventLayer().
unsigned char * QgsGeometryAnalyzer::locateBetweenWkbString | ( | unsigned char * | ptr, |
QgsMultiPolyline & | result, | ||
double | fromMeasure, | ||
double | toMeasure | ||
) | [private] |
Definition at line 1270 of file qgsgeometryanalyzer.cpp.
References clipSegmentByRange().
Referenced by locateBetweenMeasures().
double QgsGeometryAnalyzer::perimeterMeasure | ( | QgsGeometry * | geometry, |
QgsDistanceArea & | measure | ||
) | [private] |
Definition at line 358 of file qgsgeometryanalyzer.cpp.
References QgsGeometry::asMultiPolygon(), QgsGeometry::asPolygon(), QgsGeometry::fromPolyline(), QgsGeometry::isMultipart(), and QgsDistanceArea::measure().
Referenced by simpleMeasure().
QList< double > QgsGeometryAnalyzer::simpleMeasure | ( | QgsGeometry * | geometry | ) | [private] |
Definition at line 335 of file qgsgeometryanalyzer.cpp.
References QgsGeometry::asPoint(), QgsDistanceArea::measure(), perimeterMeasure(), QGis::Polygon, QgsGeometry::type(), QGis::WKBPoint, QgsGeometry::wkbType(), QgsPoint::x(), and QgsPoint::y().
Referenced by convexHull().
bool QgsGeometryAnalyzer::simplify | ( | QgsVectorLayer * | layer, |
const QString & | shapefileName, | ||
double | tolerance, | ||
bool | onlySelectedFeatures = false , |
||
QProgressDialog * | p = 0 |
||
) |
Simplify vector layer using (a modified) Douglas-Peucker algorithm and write it to a new shape file.
layer | input vector layer |
shapefileName | path to the output shp |
tolerance | (level of simplification) |
onlySelectedFeatures | if true, only selected features are considered, else all the features |
p | progress dialog (or 0 if no progress dialog is to be shown) |
Definition at line 30 of file qgsgeometryanalyzer.cpp.
References QgsMapLayer::crs(), QgsVectorLayer::dataProvider(), QgsVectorDataProvider::encoding(), QgsVectorLayer::featureAtId(), QgsVectorLayer::featureCount(), QgsVectorDataProvider::fields(), QgsVectorDataProvider::geometryType(), QgsVectorLayer::nextFeature(), QgsVectorLayer::pendingAllAttributesList(), QgsVectorLayer::select(), QgsVectorLayer::selectedFeaturesIds(), and simplifyFeature().
void QgsGeometryAnalyzer::simplifyFeature | ( | QgsFeature & | f, |
QgsVectorFileWriter * | vfw, | ||
double | tolerance | ||
) | [private] |
Helper function to simplify an individual feature.
Definition at line 124 of file qgsgeometryanalyzer.cpp.
References QgsVectorFileWriter::addFeature(), QgsFeature::attributeMap(), QgsFeature::geometry(), QgsFeature::setAttributeMap(), QgsFeature::setGeometry(), and QgsGeometry::simplify().
Referenced by simplify().