When I use the QgsSpatialIndex class, after leaving the method, my application crash. Looks like the object QgsSpatialIndex class works, it brings QgsFeatureId list, but from what I noticed something in the "destruction" of the object makes the application crash. I'm using Windows 7. I installed qgis with osgeo4w-setup-x86.

qgis-dev: 2.9.0-3

void MainWindow::addLayer(){
    QString myLayerPath         = "C:\\Users\\osgeos4w\\Documents\\desktop_gis_data";
    QString myLayerBaseName     = "world_borders";
    QString myProviderName      = "ogr";
    QgsVectorLayer * mypLayer = new QgsVectorLayer(myLayerPath, myLayerBaseName, myProviderName, true);
    QList<QgsMapCanvasLayer> myLayerSet;
    QList<QgsMapCanvasLayer> myLayerSet;
    if (mypLayer->isValid()) {
        qDebug("Layer is valid");
    } else {
        qDebug("Layer is NOT valid");
    QgsMapLayerRegistry::instance()->addMapLayer(mypLayer, TRUE);

    QgsSpatialIndex index(mypLayer->getFeatures());
    QgsPoint p = QgsPoint(-33.33,-5.97);
    QList<QgsFeatureId> featuiresIds = index.nearestNeighbor(p, 2);
    qDebug() << "fdis count = " << featuiresIds.count();

The output console is: "fdis count = 2"

it worked but crashes the application soon after the end of the method, and this only execute without crash if I comment the follow line:

QList<QgsFeatureId> featuiresIds = index.nearestNeighbor(p, 2);
qDebug() << "fdis count = " << featuiresIds.count();

If I execute the same code in the python conselo inside the QGIS Desktop 2.9.0, it works perfectly

Do anyone have any idea what might be happening?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.