No returns from selectFeaturesByQuery

1158
3
Jump to solution
08-17-2016 07:27 PM
GarethPalmer1
New Contributor

I'm working on a search function that selects features from a local runtime geodatabase on the device and am currently trying to call an error message when the function fails to return any features.

There was a section in a tutorial for querying features that i found which has a response in the GeodatabaseFeatureTable component of the queried table but this section of code never got called (I loaded in console.log() statements which were never displayed when I tested the code). This used an if statement that's similar to the one below:

if(queryFeaturesResult.iterator.hasNext===0){
    message1.visible=true
}

The other method that I've tried to call the error message from is the FeatureLayer component by checking the number of selected features when selection query is called however this only loads the message on the clearSelection() function or doesn't load at all.

Is there any other way to check for the number of returns?

I've copied in the related code below.

MainApp{

    GeodatabaseFeatureTable {
        id:tableAddress
        geodatabase: geodatabase.valid ? geodatabase: null
        featureServiceLayerId: 0
    }

    Map {
        id: map

    ...

        FeatureLayer{
            id:address
            featureTable: tableAddress
            visible:false

            function selectID(){
                var buffer = selectedFeatures[0].geometry.buffer(50, "Meters")
                var featureLength = selectedFeatures.length
                if(featureLength === 0){
                    message1.visible = true
                } else if (featureLength === 1){
                    map.zoomTo(buffer)
                } else {
                    message2.visible = true
                }
            }

            onSelectedFeaturesChanged: {
                selectID()
            }
        }
    }
}

SearchFunction {
    id: searchFunction
    anchors {
        left: parent.left
        right: parent.right
        top: headerRect.bottom
    }

    ...

    TextField {
        id:searchQuery
        anchors {
            left: parent.left
            bottom: parent.bottom
            margins: 8
        }
        width: 2*(parent.width/3)
        height: 50
        placeholderText: "2 Fryatt Quay, Wellington"
    }

    Button {
        id: searchFind
        text: "Find"
        enabled: searchQuery.length != 0
        anchors {
            bottom: parent.bottom
            right: searchClose.left
            margins: 8
        }

        Query{
            id:searchQAddress
            where: "\"ADDRESS\" = \'"+ searchQuery.text.toUpperCase()+"\'"
        }

        Query{
            id: searchQRoads
            where: "\"FULL_RD_NM\" = \'" + searchQuery.text + "\'"
        }

        FeatureResult {
            id: queryResult
        }

        onClicked: {
            if (searchTable.currentText === "Addresses"){
                address.clearSelection()
                address.selectFeaturesByQuery(searchQAddress,Enums.SelectionMethodNew)
                console.log(searchQAddress.where)
            } else if (searchTable.currentText === "Roads"){
                road.selectFeaturesByQuery(searchQRoads,Enums.SelectionMethodNew)
            }
        }
    }


    Button {
        id: searchClose
        text: "Close"
        anchors {
            bottom: parent.bottom
            right: parent.right
            margins: 8
        }

        onClicked: {
            closeSearch.running = true
            searchFunction.enabled = false
        }
    }
}
0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

I see. Instead of selecting features, could you query Id's from the feature table (ArcGIS Runtime SDK for Qt QML API: FeatureTable Class Reference ), and if the query doesn't return anything, show your error, and if it does, then select the features by ID on the feature layer (ArcGIS Runtime SDK for Qt QML API: FeatureLayer Class Reference )?

View solution in original post

3 Replies
LucasDanzinger
Esri Frequent Contributor

Gareth-

hasNext returns a bool, so you can just do something like the following instead:

if(queryFeaturesResult.iterator.hasNext){
    message1.visible=true
}

As for the second part of your question, are you saying that the selectionChanged signal only emits when the selection is cleared? It should emit whenever the selection changes at all.

0 Kudos
GarethPalmer1
New Contributor

The selectionChanged does emit when the selection changes - lines 24 to 27 in the code segments are able to open message2 when it receives multiple returns. It doesn't respond when the query doesn't return any values though.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

I see. Instead of selecting features, could you query Id's from the feature table (ArcGIS Runtime SDK for Qt QML API: FeatureTable Class Reference ), and if the query doesn't return anything, show your error, and if it does, then select the features by ID on the feature layer (ArcGIS Runtime SDK for Qt QML API: FeatureLayer Class Reference )?