Generate Geodatabase

1119
12
01-06-2020 06:18 AM
jaykapalczynski
Frequent Contributor

I am using the template example in appstudio to test downloading a geodatabase.  Its working as it seems it should but I have a question that maybe someone can help answer

In the example it is setting up some Geodatabase Parameters.  One of these is the Bounding box that the user specifies and as such all features within this box are downloaded to the Geodatabase.

My question.  Can I add w where clause anywhere in there?

// create the generate geodatabase parameters
GenerateGeodatabaseParameters {
    id: generateParameters
    extent: generateExtent
    outSpatialReference: SpatialReference.createWebMercator()
    returnAttachments: false
}

I tried this but getting errors...

QueryParameters {
    id: params
    whereClause: "created_user = 'Law'"
}

// create the generate geodatabase parameters
GenerateGeodatabaseParameters {
    id: generateParameters
    extent: generateExtent
    outSpatialReference: SpatialReference.createWebMercator()
    returnAttachments: false
     
    QueryParameters: params
}
0 Kudos
12 Replies
ErwinSoekianto
Esri Regular Contributor

Based on this documentation, GenerateGeodatabaseParameters QML Type | ArcGIS for Developers , GenerateGeodatabaseParameters does not have QueryParameters as listed property. 

I am including ArcGIS Runtime SDK for Qt‌, to see if there is another way to achieve what you are asking. 

0 Kudos
jaykapalczynski
Frequent Contributor

Thanks for your thoughts...

I can set up a definition expression after the fact but would like to include the limitation of records before the download occurs.  That make sense?  As the dataset gets larger I want to be able to limit the records downloaded by date range and user.  Then do the download.....

0 Kudos
LucasDanzinger
Esri Frequent Contributor

You can specify GenerateLayerOptions in the GenerateGeodatabaseParameters. This allows you to specify a where clause for each layer - GenerateGeodatabaseParameters QML Type | ArcGIS for Developers 

jaykapalczynski
Frequent Contributor

OK I see in the example here that they are referencing the layerOptions....was was leaning towards this potentially being a solution....

Although not sure how to proceed....would this be the area that I implement that....and what would be the syntax

if I work it in below is this done before the download occurs?

how would I add a date range and created_user = 'user1'  

would it be something like this?  layerOption2   ????

Again I am using the base template in appstudio for GenerateGeodatabase

                onLoadStatusChanged: {
                    if (loadStatus === Enums.LoadStatusLoaded) {
                        var idInfos = featureServiceInfo.layerInfos;
                        for (var i = 0; i < idInfos.length; i++) {
                            // add the layer to the map
                            var featureLayerUrl = featureServiceInfo.url + "/" + idInfos[i].infoId;
                            var serviceFeatureTable = ArcGISRuntimeEnvironment.createObject("ServiceFeatureTable", {url: featureLayerUrl});
                            var featureLayer = ArcGISRuntimeEnvironment.createObject("FeatureLayer", {featureTable: serviceFeatureTable});
                            map.operationalLayers.append(featureLayer);

                            // add a new GenerateLayerOption to array for use in the GenerateGeodatabaseParameters
                            var layerOption = ArcGISRuntimeEnvironment.createObject("GenerateLayerOption", {layerId: idInfos[i].infoId});
                            
                            var layerOption2 = ArcGISRuntimeEnvironment.createObject("GenerateLayerOption", {whereClause: "created_user = 'law' "});
                            
                            generateLayerOptions.push(layerOption);
                            
                            generateLayerOptions.push(layerOption2);
                            
                            generateParameters.layerOptions = generateLayerOptions;
                        }
                    }
                }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
jaykapalczynski
Frequent Contributor

I think i got it with this

testing now...

var layerOption  = ArcGISRuntimeEnvironment.createObject("GenerateLayerOption", 
          {layerId: idInfos[i].infoId, whereClause: "created_user = 'law' "});

                onLoadStatusChanged: {
                    if (loadStatus === Enums.LoadStatusLoaded) {
                        var idInfos = featureServiceInfo.layerInfos;
                        for (var i = 0; i < idInfos.length; i++) {
                            // add the layer to the map
                            var featureLayerUrl = featureServiceInfo.url + "/" + idInfos[i].infoId;
                            var serviceFeatureTable = ArcGISRuntimeEnvironment.createObject("ServiceFeatureTable", {url: featureLayerUrl});
                            var featureLayer = ArcGISRuntimeEnvironment.createObject("FeatureLayer", {featureTable: serviceFeatureTable});
                            map.operationalLayers.append(featureLayer);

                            // add a new GenerateLayerOption to array for use in the GenerateGeodatabaseParameters
                            var layerOption  = ArcGISRuntimeEnvironment.createObject("GenerateLayerOption", {layerId: idInfos[i].infoId, whereClause: "created_user = 'law' "});

                            generateLayerOptions.push(layerOption);

                            generateParameters.layerOptions = generateLayerOptions;
                        }
                    }
                }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
jaykapalczynski
Frequent Contributor

Maybe someone can help with the where clause...

This seems to work

var userWhereClause = "created_user = 'Esri_Anonymous' ";



BUT I cannot get the date ranges queries to work....thoughts on syntax?
//DATE VARIABLES
var startdate = "2020-1-03";
var enddate = "2020-1-20";

// WHERE CLAUSE

//var userWhereClause = "created_date BETWEEN DATE '" + startdate + "' AND DATE '" + enddate + "'  ";

// var userWhereClause = "created_date >= DATE ' " + startdate + " ' ";

0 Kudos
ErwinSoekianto
Esri Regular Contributor

Refer to this blog for Date-Time query, Querying Feature Services: Date-Time Queries 

0 Kudos
jaykapalczynski
Frequent Contributor

Yea I have been referencing that blog from another post...still something weird going on...

I am successful in creating a definitionExpression on a Feature layer as such:

ALL THREE examples below including the DATE greater than and between work just fine...

//DATE VARIABLES
var exactdate = "2020-01-04";
var startdate = "2019-12-01";
var enddate = "2019-12-30";

// USER NAME
//featurelayer.definitionExpression = "created_user = 'Esri_Anonymous'";
// AFTER DATE
//featurelayer.definitionExpression = "created_date >= DATE'" + startdate + "'";
// BETWEEN DATES
//featurelayer.definitionExpression = "created_date BETWEEN DATE'" + startdate + "' AND DATE '" + enddate + "' ";

I try and use this same logic and syntax to create a GenerateLayerOption and I get varied results

This example works just fine....it grabs only the rescords with the created_user = Esri_Anonymous

var userWhereClause = "created_user = 'Esri_Anonymous' ";

BUT when I try and use the DATEs it blows up and dosent work properly...

IT works in the DefinitionExpression but the same syntax on the same dataset does not work?????

var userWhereClause = "created_date BETWEEN DATE'" + startdate + "' AND DATE '" + enddate + "' ";

onLoadStatusChanged: {
  if (loadStatus === Enums.LoadStatusLoaded) {
    var idInfos = featureServiceInfo.layerInfos;
    for (var i = 0; i < idInfos.length; i++) {
       // add the layer to the map
       var featureLayerUrl = featureServiceInfo.url + "/" + idInfos[i].infoId;
       var serviceFeatureTable = ArcGISRuntimeEnvironment.createObject("ServiceFeatureTable", {url: featureLayerUrl});
       var featureLayer = ArcGISRuntimeEnvironment.createObject("FeatureLayer", {featureTable: serviceFeatureTable});
       map.operationalLayers.append(featureLayer);


       // QUERY DATES
       //DATE VARIABLES
       var exactdate = "2020-01-04";
       var startdate = "2019-12-01";
       var enddate = "2019-12-30";

       // WHERE CLAUSE
       //var userWhereClause = "created_user = 'Esri_Anonymous' ";
       //var userWhereClause = "created_date BETWEEN DATE'" + startdate + "' AND DATE '" + enddate + "' ";

       // add a new GenerateLayerOption to array for use in the GenerateGeodatabaseParameters
       var layerOption  = ArcGISRuntimeEnvironment.createObject("GenerateLayerOption", {layerId: idInfos[i].infoId, whereClause: userWhereClause});

       generateLayerOptions.push(layerOption);

       generateParameters.layerOptions = generateLayerOptions;
      }
   }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
by Anonymous User
Not applicable

Hi Jay

Try adding in brackets around the actual date. e.g.

var myDate = new Date();
//make these some other dates obviously...
var startDate = new Date();
var finishDate = new Date();


var dateQueryString = "(date(%1) BETWEEN date('%2') AND date('%3'))".arg(myDate.toISOString()).arg(startDate.toISOString()).arg(finishDate.toISOString());