Unable to Get Attributes using feature.getAttributes()

168
2
Jump to solution
11-23-2021 10:17 PM
GauravMam
New Contributor

Hi, I'm very new to ArcGIS and have been using the ArcGIS JAVA SDK for a couple of days now. I created the ArcGIS developers account (Essentials Plan) for just exploring things. I'm just interested in reading and writing of data from an online layer. I don't want to display anything on Java FX Maps.

Till now I have been able to read geometrical data for point, polyline and polygon. However I'm facing issues while fetching the non-geometrical attributes. I created a data layer of point geometry and then added a couple of non-geometrical fields in it. Then using the sdk I was also able to insert some values into the layer along with the non-geometrical attribute data. Also the data (including attributes) gets displayed fine on Map2D viewer online

While reading the same data from SDK, I'm able to read geometrical data, however the attributes don't come in the attribute map (

feature.getAttributes() - This gives the default attributes only and not the one I added manually to the layer


Although when I do  - featureTable.getFields() - it shows me the defination of fields that I added manually to the layer. They just don't come when I query their values from the feature.

  

Just need to know is there something I'm missing or may be not available in the essentials plan. Any help will be appreciated.

 

Thanks.

0 Kudos
1 Solution

Accepted Solutions
MarkBaird
Esri Regular Contributor

The default mode for a query operation is to limit the attributes returned so things render quicker and you are transferring less data across the network.  It is explained here.

In the code when you perform a query to get the features you can set it so you return everything.  Here is some very crude code to show it:

 

      // define the feature table
      ServiceFeatureTable featureTable = new ServiceFeatureTable("https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0");
      featureTable.loadAsync();

      // load it and wait...
      featureTable.addDoneLoadingListener(() -> {
        System.out.println("load status " + featureTable.getLoadStatus());

        // query parameters for everything
        QueryParameters queryParameters = new QueryParameters();
        queryParameters.setWhereClause("1=1");

        // query the table
        //ListenableFuture<FeatureQueryResult> future = featureTable.queryFeaturesAsync(queryParameters); // returns default fields only
        ListenableFuture<FeatureQueryResult> future = featureTable.queryFeaturesAsync(queryParameters, ServiceFeatureTable.QueryFeatureFields.LOAD_ALL);

        try {
          // thread blocks here until results come back
          FeatureQueryResult queryResult = future.get();

          // take a look at the features we've got
          for (Feature feature : queryResult) {
            System.out.println(" attr " + feature.getAttributes().keySet());
          }

        } catch (InterruptedException e) {
          e.printStackTrace();
        } catch (ExecutionException e) {
          e.printStackTrace();
        }
      });

 

You mention that you are writing an app which does not use JavaFX controls.  Can you tell me how you are using the SDK?  

View solution in original post

2 Replies
MarkBaird
Esri Regular Contributor

The default mode for a query operation is to limit the attributes returned so things render quicker and you are transferring less data across the network.  It is explained here.

In the code when you perform a query to get the features you can set it so you return everything.  Here is some very crude code to show it:

 

      // define the feature table
      ServiceFeatureTable featureTable = new ServiceFeatureTable("https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0");
      featureTable.loadAsync();

      // load it and wait...
      featureTable.addDoneLoadingListener(() -> {
        System.out.println("load status " + featureTable.getLoadStatus());

        // query parameters for everything
        QueryParameters queryParameters = new QueryParameters();
        queryParameters.setWhereClause("1=1");

        // query the table
        //ListenableFuture<FeatureQueryResult> future = featureTable.queryFeaturesAsync(queryParameters); // returns default fields only
        ListenableFuture<FeatureQueryResult> future = featureTable.queryFeaturesAsync(queryParameters, ServiceFeatureTable.QueryFeatureFields.LOAD_ALL);

        try {
          // thread blocks here until results come back
          FeatureQueryResult queryResult = future.get();

          // take a look at the features we've got
          for (Feature feature : queryResult) {
            System.out.println(" attr " + feature.getAttributes().keySet());
          }

        } catch (InterruptedException e) {
          e.printStackTrace();
        } catch (ExecutionException e) {
          e.printStackTrace();
        }
      });

 

You mention that you are writing an app which does not use JavaFX controls.  Can you tell me how you are using the SDK?  

View solution in original post

GauravMam
New Contributor

Hi Mark,

Thanks for the reply. It worked. The problem was not using the overloaded method which loads all the attributes.

 

//ListenableFuture<FeatureQueryResult> future = featureTable.queryFeaturesAsync(queryParameters); // returns default fields only
        ListenableFuture<FeatureQueryResult> future = featureTable.queryFeaturesAsync(queryParameters, ServiceFeatureTable.QueryFeatureFields.LOAD_ALL);

 I was using the commented one. As far as the SDK is concerned,  I have not included any JAVA FX maven dependencies, I just need the SDK to read data from ArcGIS and other ESRI formats and convert them into formats like DWG, DXF, GML etc. and vice versa. Hopefully this should suffice my requirement. Thanks again.

0 Kudos