Select to view content in your preferred language

File Geodatabase Query

1447
1
05-10-2013 12:10 PM
JasonBewley1
Emerging Contributor
I'm creating a web map application using the JavaScript API and I've been sticking with the supplied dojo widgets, so I don't have anything crazy going on.

What I have is a local file geodatabase (not large, approx 10mb) that basically contains parcel information. I'm trying to figure out how I can query that file geodatabase and then display the information from a positive match. I'm not worried about having to write to the database, it's only being used for READ only.

For example, in my application, the user will be able to search by Owner from a dijit input text field. I understand all the logic and what needs to happen as far as that's concerned. My issue is I'm not sure how to:

  1. Connect to the local copy of the file geodatabase

  2. How the query statement needs to be written (standard SQL?)

  3. Return the information from a positive match that I can then display in a <div></div>

  4. all using JavaScript


Any suggestions or points in the right direction will be very appreciative.

Thanks!
0 Kudos
1 Reply
SteveClarke
Emerging Contributor
Not sure if you got your questions answered yet, but here are some suggestions:

Connecting to a file geodatabase for querying is similar to connecting to an SDE geodatabase. In your map document that you publish to ArcGIS Server bring in your feature class from the file geodatabase.  This will be your connection info to the file geodatabase.  Then use the queryTask function in Javascript to point to the url for your mapservice and the layerid number in the map service of the feature class you want to query.

The sql query is similar to querying a relational database in SDE.  Here is an example of code I use to query for a park name of a feature class stored in a file geodatabase and return the results on the map and zoom to the feature. I'm passing in the park name value from the text that gets entered by the user in the tool.

function findPark(value) {
var parkQuery;
parkName = value;
        queryTask = new esri.tasks.QueryTask("http://maps.sgcity.org/arcgisweb/rest/services/Features_REP/MapServer/7");
        parkQuery = new esri.tasks.Query();
        parkQuery.returnGeometry = true;
        parkQuery.outFields = ["Park_Name"];
        var dirty = (new Date()).getTime();
        parkQuery.where = "Park_Name='" + parkName + "' AND " + dirty + "=" + dirty;
        queryTask.execute(parkQuery, zoomRecreationPointFeatureResults);
      }
  
   function zoomRecreationPointFeatureResults(results){
     for (var i = 0, il = results.features.length; i < il; i++) {
      var graphic = results.features;
      map.centerAndZoom(graphic.geometry, 5);
     }
   }

Note that in the where clause I'm using a variable called 'dirty'.  This is because of a current bug with queries against a file geodatabase using ArcGIS Server 10.1 (I believe this will be fixed for 10.2).  This 'dirty' variable simply adds a timestamp to the end of each query that gets passed to the file geodatabase to make each query unique, which avoids the bug so you get accurate results each time you execute the query.

Hope this helps.
0 Kudos