QML Querying a Geodatabase Offline

574
7
10-01-2017 11:59 AM
RayfieldNeel
New Contributor II

I'm figuring out the workflows for an AppStudio app that involves a query of the current GPS location against a feature service of polygons. I've got it working for a feature service in ArcGIS Online, but need to work out how to make this an Offline operation, since connectivity could be an issue. 

I've explored the examples for generating Runtime Content in ArcMap (a .geodatabase file), sample code below. With a featuretable declared, I assumed that I could query against that, but I get no data in my result. One clue is that get an error: "Unable to assign [undefined] to QmlFeatureTable", even on the stock Esri example code, for the "featureTable:" line. Their data appears on the map, but I nothing I've tried, as far as querying features, seems to work. 

I'm not concerned about map display, I need to execute a query against a layer of polygons, as I would using the REST API, to see if my GPS "point" gets a return. Is there an established way to get there? I'm still a rookie with using QML/Javascript with AppStudio, so I could be missing something basic.

Also worth mentioning, I've looked at the MobileMapPackage process, as well; I like that since I can easily generate it in ArcGIS Pro, but have had no luck querying against that, either. 

Thanks for any info! 

--Ray

Sample code:

QueryParameters {
   id: params
}

FeatureLayer {
   // obtain the feature table from the geodatabase by name
   featureTable: gdb.geodatabaseFeatureTablesByTableName["Trailheads"]

   // create the geodatabase
   Geodatabase {
      id: gdb
      path: AppFramework.resolvedPathUrl(copyLocalData(inputGDB, outputGDB))
   }

   onLoadStatusChanged: {
      console.log( "Load Status: ", loadStatus );
      params.whereClause = "1=1";

      featureTable.queryFeatures( params );

      onQueryFeaturesStatusChanged: {
         console.log( JSON.stringify( FeatureQueryResult ));
      }
   }
}

0 Kudos
7 Replies
KaushikMysorekar
New Contributor III

Hi Ray,

Did you try verifying the path for the geodabase by doing console.log on the path?

Make sure the path is correct.

0 Kudos
RayfieldNeel
New Contributor II

Hi, thanks Kaushik,

Sorry for the delay, I got bounced around to another project for a bit!

Yes, when I log the path, it does appear that it's correctly pointing to my existing .geodatabase file in the correct folder. I was hoping you might be on to something, there, that would have been something that I could have fixed!

Any other thoughts?

Thanks, --Ray

0 Kudos
KaushikMysorekar
New Contributor III

Hi Ray,

What are the loadStatus and featureTable.queryFeaturesStatus (write out using the console) values?

That should tell us the state of the layer object and if the query is in progress, completed or failed.

Kaushik

  
0 Kudos
RayfieldNeel
New Contributor II

Hmmm, so perhaps you're on to something here. When I attempt to run their provided example geodatabase, I get 1 for both loadStatus and featureTable.queryFeatureStatus.

If I change things to try to use my gdb, the loadStatus is 0, and the featureTable comes up as undefined. I'm not getting the geodatabase loaded properly, somehow. 

0 Kudos
AneeqaAbrar1
New Contributor III

did you find an answer to your query? I'm facing the same problem.

0 Kudos
RayfieldNeel
New Contributor II

Hi Aneeqa, sorry, I've been out of the office for a holiday over the last week.

I'm sorry to say that I've had no luck getting this to work, so far. Most of the feedback that I've gotten simply keeps pointing me back to the same AppStudio samples, with the counsel that "it works just the same with offline content". Alas, that has not been my experience. 

0 Kudos
AneeqaAbrar1
New Contributor III

Well I can now help you with this I think - but this is for local geodatabase. 

                Geodatabase {
                    property var gdbLayers: []
                    id: gdb_geofence
                    path: AppFramework.resolvedPathUrl(copyLocalData(inputGeofencing, outputGeofencing))
                    onLoadStatusChanged: {
                        positionSource.update()
                        if(Enums.LoadStatusLoaded === gdb_geofence.loadStatus){
                            var tables = gdb_geofence.geodatabaseFeatureTables
                            for(var i = tables.length-1; i>= 0; i--){
                                var layer = ArcGISRuntimeEnvironment.createObject("FeatureLayer")
                                layer.featureTable = tables[i];
                                gdbLayers.push(layer);
                                layer.loadStatusChanged.connect(function(){
                                    for(var j = 0; j < gdbLayers.length; j++){
                                        if (Enums.LoadStatusLoaded !== gdbLayers[j].loadStatus){
                                            return;
                                        }
                                    }
                                    var bbox = gdbLayers[0].fullExtent
                                    var position = positionSource.position.coordinate
                                    lastpoint = CoordinateFormatter.fromLatitudeLongitude(positionSource.position.coordinate.latitude+","+positionSource.position.coordinate.longitude,SpatialReference.createWebMercator())
                                    var geometry_gdb = GeometryEngine.project(bbox, SpatialReference.createWebMercator())
                                    var geometry_location= GeometryEngine.project(lastpoint, SpatialReference.createWebMercator())
                                    var within = GeometryEngine.within(geometry_location, geometry_gdb)
                                    console.log("Geofence ", within)
                                    if(within === true){
                                        console.log("YUHOOOOOO")
                                    }
                                    else
                                        console.log("NOOOOOO")
                                });
                                map.operationalLayers.append(layer);
                            }
                        }
                    }
                }


Feature layer (geodatabase)—ArcGIS Runtime SDK for Qt | ArcGIS for Developers 
This should help you understand!

I am now looking to edit the local geodatabase but so far haven't found a solution.
0 Kudos