AW: [Qgis-developer] Trouble with QgsGeometry contains(QgsPoint *p)function

Hugentobler Marco marco.hugentobler at karto.baug.ethz.ch
Fri Jul 31 01:20:16 EDT 2009


Hi Matt

currentGeometry2 is a pointer, so you need to use '->' instead of '.' to call a function.

if(currentGeometry2->contains(currentPoint))

should solve the problem.
Btw, what kind of program do you write? 'delaunay_intersect' sounds interesting...

Regards,
Marco


-----Ursprüngliche Nachricht-----
Von: qgis-developer-bounces at lists.osgeo.org im Auftrag von Matthew Denno
Gesendet: Fr 31.07.2009 07:02
An: qgis-developer
Betreff: [Qgis-developer] Trouble with QgsGeometry contains(QgsPoint *p)function
 
Hello Developers,


I am working on a little application using QGIS and am having trouble using
the QgsGeometry contains(QgsPoint *p) function. I have included the section
of code that is not working for me as well as the error message I am
getting. It appears that currentGeometry2 is not of type QgsGeometry*, but I
can't figure out why. This is the first application I have tried to write
using C++ so the solution may be more of a C++ question than a QGIS
problem...not sure.


Any help or pointers would be greatly appreciated.


Thanks,


Matt

CODE:

// Instantiate Provider Register

QgsProviderRegistry::instance(myPluginsDir);

//Open the shapefile vector layer from file

QgsVectorLayer * mypVectorLayer = new QgsVectorLayer(myLayerPath,
myLayerBaseName, myProviderName);

QgsVectorLayer * mypVectorLayer2 = new QgsVectorLayer(myLayerPath3,
myLayerBaseName, myProviderName);

 //create a holder for retrieving point features from the provider

QgsFeature currentFeature;

QgsVectorDataProvider * dataProvider = mypVectorLayer->dataProvider();

mypVectorLayer->select(dataProvider->attributeIndexes());


 //create a holder for retrieving mask features from the provider

QgsFeature currentFeature2;

 QgsVectorDataProvider * dataProvider2 = mypVectorLayer2->dataProvider();

 mypVectorLayer2->select(dataProvider2->attributeIndexes());


 //now iterate through each point feature

while (mypVectorLayer->nextFeature(currentFeature))

{

//get point geometry for current feature

QgsGeometry * currentGeometry = currentFeature.geometry();

QgsPoint currentPoint = currentGeometry->asPoint();


 //now interate through each polygon feature

while (mypVectorLayer2->nextFeature(currentFeature2))

{

//get polygon geometry for current feature

QgsGeometry * currentGeometry2 = currentFeature2.geometry();

QgsPolygon currentPolygon = currentGeometry2->asPolygon();


//check if point is contained in polygon

 if(currentGeometry2.contains(currentPoint))

{

 //do something with points that are within the current polygon

}

}

}


ERROR:


/home/matt/Programming/TestingCreator/delaunay_intersect.h:87:
error: request for member 'contains' in 'currentGeometry2', which is of
non-class type 'QgsGeometry*'



More information about the Qgis-developer mailing list