Select to view content in your preferred language

FeatureSet from QueryTask does not contain all information from db

2035
1
05-20-2013 12:26 PM
PatriziaPeller
Emerging Contributor
Hi everybody!

Does anybody know why the FeatureSet I get from my QueryTask only contains one of several Fields? If I perform the same Query via Browser, I get all the Fields for each feature, but the FeatureSet only contains the field specified as displayField, in my case NAME.

Fields contained according to Browser:
"fieldAliases":{"ID":"ID","NAME":"NAME","ADRESSE":"ADRESSE","OEFFNUNGSZEITEN":"??ffnungszeiten","PARKENTGELT":"Parkentgelt","TAGESHOECHSTSATZ":"Tageshöchstsatz","LANGZEITPARKEN":"Langzeitparken","PLS_NAME":"PLS Name","INFRASTRUKTUR":"Infrastruktur","BEMERKUNG":"Bemerkung","STELLPLAETZE":"Stellplätze","TYP":"TYP","TYP_EN":"TYP_EN","TYP_ID":"TYP_ID","BETREIBER":"BETREIBER","BETREIBER_LINK":"BETREIBER_LINK"}

(NAME is contained in FeatureSet, the rest of the fields not)

In class DownloadController, I trigger the download which is done in class DatabaseConnection. DownloadController is kind of a Util-class that is why the methods are public static.

>
 boolean downloadDidFinish = DownloadController.grabParkingAreaDataWithFeatureSet(context); //will trigger the download

package passau.android.app.db;

+import java.util.ArrayList; // I deleted the rest of the imports to make the code cleaner and easier readable

public class DownloadController {

 private static final String TAG = "DOWNLOADER";
 private static final String NO_DESCRIPTION_TEXT = "-";
 private static final int MINUTES_OF_DAY = 86400;

 private static Context context;
 private DataStore ds = DataStore.getInstance();

 private static AsyncTask<String, Void, FeatureSet> parkingConnection;

 private static FeatureSet parkingFeatureSet;

 private static ArrayList<ParkingArea> parkingArray;

 public static boolean[] failedDataConnection = new boolean[10];

 public static boolean isParkingDataAvailable = false;

 public static boolean grabParkingAreaData(Context context) {
  String parkingurl = "http://www.geoportal.passau.de/ArcGIS/rest/services/APPDATEN/MapServer/10";
  String parkingWhere = "ID <> 0";
  // String parkingWhere = "NAME='Zentralgarage'";
  String parkingDataName = "park";
  String[] parkingParams = { parkingurl, parkingWhere, parkingDataName,
    "id", "name", "adresse", "oeffnungszeiten", "parkentgelt",
    "tageshoechstsatz", "langzeitparken", "pls_name", "shape",
    "infrastruktur", "bemerkung", "stellplaetze", "typ", "typ_en",
    "typ_id", "betreiber", "betreiber_link" };
  parkingConnection = new DatabaseConnection().execute(parkingParams);
  return getDataWhenDownloadFinished(parkingConnection, "park");
 }

 private static boolean getDataWhenDownloadFinished(
   AsyncTask<String, Void, FeatureSet> download, String dataName) {
  FeatureSet fs = new FeatureSet();
  try {
   fs = download.get();
   Log.d(dataName.toUpperCase(), FeatureSet.toJson(fs));
  } catch (InterruptedException e) {
   e.printStackTrace();
  } catch (ExecutionException e) {
   e.printStackTrace();
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

  boolean finished = false;
  if (fs.getGraphics().length > 0) {
                        if (dataName.equals("park")) {
    Log.d(TAG, "PARK_DB successfully downloaded");
    parkingFeatureSet = fs;
    finished = setParkingAreasWithFeatureSet(parkingFeatureSet);
   } // never mind the other cases, they follow the same principle
  } else {
   handleDatabaseDownloadError(dataName);
  }

  return finished;
 }

        public static boolean setParkingAreasWithFeatureSet(FeatureSet fs) {
  DataStore ds = DataStore.getInstance();
  ds.removeAllValuesForKey("pa_");
  ArrayList<ParkingArea> parkingList = new ArrayList<ParkingArea>();
  
  for (Graphic g : fs.getGraphics()) {
   String graphicName = (String) g.getAttributeValue("PLS_NAME");
   if (graphicName != null && graphicName.isEmpty()) {
    String name = "";
    int total = 0;
    int current = 0;
    int trend = 0;
    String status = "";
    boolean full = false;
    String distance = "";
    if (g.getAttributeValue("NAME") != null) {
     name = (String) g.getAttributeValue("NAME");
    }
    if (g.getAttributeValue("AKTUELL") != null) {
     current = (Integer) g.getAttributeValue("AKTUELL");
    }
    if (g.getAttributeValue("GESAMT") != null) {
     total = (Integer) g.getAttributeValue("GESAMT");
    }
    if (g.getAttributeValue("STATUS") != null) {
     status = (String) g.getAttributeValue("STATUS");
    }
    if (g.getAttributeValue("TREND") != null) {
     trend = (Integer) g.getAttributeValue("TREND");
    }
    ParkingArea pa = new ParkingArea(name, total, current, trend,
      status, full, distance);

    if (g.getAttributeValue("WEBSITE") != null) {
     pa.setSlotId((Integer) g.getAttributeValue("ID"));
    }
    
                                // here I am processing the rest of the attributes likewise

    ds.setValue("pa_" + name, pa);
    parkingList.add(pa);
   }
  }
  parkingArray = parkingList;
  return true;
 }


package passau.android.app.db;

+import android.graphics.Color;

public class DatabaseConnection extends AsyncTask<String, Void, FeatureSet> {

 private static final String TAG = "DATABASE_DOWNLOAD";
 private FeatureSet fs;
 private QueryTask task;
 private Query query;

 private String dataName = "";

 @Override
 protected FeatureSet doInBackground(String... params) {
  String url = params[0];
  String where = params[1];
  this.dataName = params[2];
  String[] outFields = new String[params.length - 3];
  for (int i = 3; i < params.length; i++) {
   outFields[i - 3] = params;
  }

  // Define a new query and set parameters
  query = new Query();
  query.setWhere(where);
  query.setReturnGeometry(true);

  // Define the new instance of QueryTask
  task = new QueryTask(url);
  fs = new FeatureSet();

  try {
   // run the querytask
   fs = task.execute(query);
  } catch (Exception e) {
   Log.d(TAG, "Error: Couln't load FeatureSet for data: " + dataName);
   e.printStackTrace();
  }

  return fs;
 }

 @Override
 protected void onPostExecute(FeatureSet fs) {
  // Define a new marker symbol for the result graphics
  SimpleMarkerSymbol sms = new SimpleMarkerSymbol(Color.BLUE, 6,
    SimpleMarkerSymbol.STYLE.CIRCLE);

  for (Graphic gr : fs.getGraphics()) {
   Graphic g = new Graphic(gr.getGeometry(), sms);

   Point p = (Point) gr.getGeometry();
  }
 }

}


Hope anybody has a clue for me, why all my fields will not show up in FeatureSet but in Browser-Json. How can I get that Json-representation in Code as well? Performing a FeatureSet.toJson(featureSet) will not do the trick.

Greetings
0 Kudos
1 Reply
MilesWacker
Emerging Contributor
Maybe in your query object you need to specify the outFields?:

Query query = new Query();


// set the geometry to the envelope of Montana created above.  
query.setGeometry(mtStExtent);

// query features that are completely contained by selection
query.setSpatialRelationship(SpatialRelationship.CONTAINS);

// set query in/out spatial ref defined above  
query.setInSpatialReference(mtSt);
  
// get the output in Montana State Plane to match map
query.setOutSpatialReference(mtSt);

// return all features
query.setOutFields(new String[] { "*" });

// include geometry in result set
query.setReturnGeometry(true);
  
// run query on FeatureLayer off UI thread
fl.queryFeatures(query, new CallbackListener<FeatureSet>() {....
0 Kudos