Select to view content in your preferred language

FeatureLayer Queries not returning anything

2692
4
Jump to solution
07-27-2014 04:51 PM
ChrisWhite
Deactivated User

I'm having trouble getting (offline) Feature Layer queries to return expected results. If I do a simple query with a Where 1=1 clause I get all features as expected. If I do a query with the a Where 'AreaName' = 'example' I get no results but no error message either. I have tested the same query in ArcMap and against the Feature Server on ArcGIS server and both work as expected. When I do the first query I can see that there is data that should satisfy the query in the Feature Layer but it is not being returned.

I am using the following code:

QueryParameters params = new QueryParameters();

params.setWhere("'AreaName' = '" + areaName + "'");

               

featureLayer.getFeatureTable().queryFeatures(params, new CallbackListener<FeatureResult>() {

   

    @Override

    public void onError(Throwable e) {

        //Handle error

    }

   

    @Override

    public void onCallback(FeatureResult objs) {

        ArrayList<String> items = new ArrayList<String>();

       

        for(Object o : objs){

            if(o instanceof Feature){

                Feature f = (Feature) o;

                String item = (String) f.getAttributeValue("Line");

               

                if(item != null && !items.contains(item)){

                    items.add(transect);

                }

            }

        }

}

Is there anything wrong with the way I am doing the query?

0 Kudos
1 Solution

Accepted Solutions
OwenEarley
Frequent Contributor

Hi Chris,

I haven't tried this using the Android SDK QueryParameters.

The example in the developer help shows a query with no quotes at all around the field name - have you tried without quotes around the field name?

The developer help example was: 'POP2000 > 500000'

View solution in original post

0 Kudos
4 Replies
OwenEarley
Frequent Contributor

This may also be the issue with your query - try using double quotes around the field name.

In ArcMap the field name is normally enclosed in double quotes and the query value for strings is in single quotes. For example in a test data set I can run the following Select By Attributes query:

"HydroName" = 'Richmond River'  --> returns 44 records

However, if I change the query:

'HydroName' = 'Richmond River' --> returns 0 records

Interestingly, the second query can be verified and runs but returns no records.

I also tried this in ArcMap against one of the ESRI sample feature services

DamageAssessment (FeatureServer)

"inspector" = 'Fred' --> returns 37 records

'inspector' = 'Fred' --> returns 0 records

UPDATE:

Just out of interest, I also tried using no quotation marks around the field name and the query worked:

inspector = 'Fred' --> returns 37 records

0 Kudos
ChrisWhite
Deactivated User

Hi Owen

I tried adding double quotes but this causes a runtime error: Error: Failed to execute query. Check whether query is valid.

I'm guessing they switched it around to avoid having to escape the double quote characters?

0 Kudos
OwenEarley
Frequent Contributor

Hi Chris,

I haven't tried this using the Android SDK QueryParameters.

The example in the developer help shows a query with no quotes at all around the field name - have you tried without quotes around the field name?

The developer help example was: 'POP2000 > 500000'

0 Kudos
ChrisWhite
Deactivated User

That's done the trick! That makes sense now that I think about it. The way I had it was most likely comparing two strings so was never going to return anything.

Thanks for your help

0 Kudos