Generate a local geodatabase with tables

3536
7
Jump to solution
04-02-2014 12:08 PM
JustinBurns1
New Contributor II
Hi,

I am using the 10.2.2 version of the SDK and 10.2.1 version of Server for ArcGIS.  The help documentation seems to be a little fuzzy on this.  Does the SDK support generating a local geodatabase (AGSSyncTask generateGeodatabaseWithParameters method) that includes tables from the feature service?  I have been unable to get it to include a table I have in my service.  The table meets the requirements needed for sync.

Thank you,
Justin
0 Kudos
1 Solution

Accepted Solutions
JustinBurns1
New Contributor II
Thanks for the reply.  Yes, I have seen that page. 

I found and fixed my issue yesterday.  The Server for ArcGIS log file showed an error stating that there was an invalid column data type in the table.  As it turns out, the process that creates the SQLite geodatabase does not like fields of type nvarchar(max) (SQL Server). 

Also, of note for anyone else, if you initialize the AGSGDBGenerateParameters object with the feature service info it does not automatically include tables.  I had to override the layerIDs property for the parameters to add both the layer IDs and table IDs.

View solution in original post

0 Kudos
7 Replies
YueWu1
by Esri Regular Contributor
Esri Regular Contributor
Hi Justin,

Do you mean the attribute table?
Have you checked this page?
https://developers.arcgis.com/ios/guide/sync-offline-edits.htm
0 Kudos
JustinBurns1
New Contributor II
Thanks for the reply.  Yes, I have seen that page. 

I found and fixed my issue yesterday.  The Server for ArcGIS log file showed an error stating that there was an invalid column data type in the table.  As it turns out, the process that creates the SQLite geodatabase does not like fields of type nvarchar(max) (SQL Server). 

Also, of note for anyone else, if you initialize the AGSGDBGenerateParameters object with the feature service info it does not automatically include tables.  I had to override the layerIDs property for the parameters to add both the layer IDs and table IDs.
0 Kudos
ShiminCai
Occasional Contributor III
Thanks for the reply.  Yes, I have seen that page. 

I found and fixed my issue yesterday.  The Server for ArcGIS log file showed an error stating that there was an invalid column data type in the table.  As it turns out, the process that creates the SQLite geodatabase does not like fields of type nvarchar(max) (SQL Server). 

Also, of note for anyone else, if you initialize the AGSGDBGenerateParameters object with the feature service info it does not automatically include tables.  I had to override the layerIDs property for the parameters to add both the layer IDs and table IDs.


Hi,

I have a few standalone lookup tables in my feature service. When generating a local geodatabase, I'm able to download these tables into the local geodatabase based on the advice above that adds both the layerIDs and tableIDs in the feature service. However, the tables downloaded in the local geodatabase are empty... I need to download the data in the tables as well. Is it possible to do this?

Thanks,

Shimin
0 Kudos
MattCooper
Occasional Contributor

Hi Shimin,

We're having the same issue with empty tables in the local geodatabase, unless the tables participate in a relationship with a featureclass.  Did you find a solution to this, by chance?

Thanks,
Matt

0 Kudos
ShiminCai
Occasional Contributor III

Hi Matt & Michael,

I did not get any response in this forum but I had to work around it... My workaround is to write the records into a *.sqlite database when the app is going online and then use the data in the sqlite regardless of online or offline. Here is the code:

@property (nonatomic, strong) AGSFeatureSet *quickCodeFeatureSet;

When the app is going online, add and query the table feature layers:

//Add standalone table layers

        for (AGSMapServiceTableInfo* info in weakSelf.gdbTask.featureServiceInfo.tableInfos)

        {

            NSURL* url = [weakSelf.gdbTask.URL URLByAppendingPathComponent:[NSString stringWithFormat:@"%d",info.tableId]];

           

            AGSFeatureLayer* fl = [AGSFeatureLayer featureServiceLayerWithURL:url mode:AGSFeatureLayerModeOnDemand];

           

            fl.outFields = @[@"*"];

            fl.delegate = weakSelf;

            fl.queryDelegate = weakSelf;

            fl.editingDelegate = weakSelf;

           

            AGSQuery *qry = [AGSQuery query];

            qry.outFields = @[@"*"];

            //qry.outFields = @[@"Type", @"QuickCode", @"Description", @"ObjectID"];

            //qry.outFields = @[@"Type", @"QuickCode", @"Description"];

            //qry.where = [NSString stringWithFormat:@"QuickCode in (%@)", @"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"];

            qry.where = @"QuickCode < 10000";

            [fl queryFeatures:qry];

           

            [weakSelf.mapView addMapLayer:fl withName:info.name];

            [weakSelf logStatus:[NSString stringWithFormat:@"loading: %@", [fl.URL absoluteString]]];

        }

Note that, to be able to query this standalone table layer, it must be added to the map view otherwise zero features are returned.

In the feature layer query delegate write the records to the sqlite

#pragma mark - AGSFeatureLayer query delegate methods

-(void)featureLayer:(AGSFeatureLayer *)featureLayer operation:(NSOperation *)op didQueryFeaturesWithFeatureSet:(AGSFeatureSet *)featureSet

{

    NSLog(@"%d", featureSet.features.count);

    self.quickCodeFeatureSet = featureSet;

    NSLog(@"%d", self.quickCodeFeatureSet.features.count);

   

    [self populateQuickCodeTable];

}

-(void)populateQuickCodeTable

{

    DBManager *db = [[DBManager alloc]init];

   

    [db clearQuickCode:@"SPDQuickCode"];

   

    for (AGSGraphic *feature in self.quickCodeFeatureSet.features)

    {

        NSString *type = [feature safeAttributeForKey:@"Type"];

        int code = [((NSNumber *)[feature safeAttributeForKey:@"QuickCode"])intValue];

        NSString *description = [feature safeAttributeForKey:@"Description"];

       

        [db insertQuickCode:@"SPDQuickCode" QuickCodeType:type QuickCode:code Description:description];

    }

   

    [db closeDatabase];

}

The above workaround is working fine for my purposes.

For your information: I also tried to write the features to the local geodatabase right after the database is created, but I can't use this solution. The reason is below...

//Add local feature/table layers

                 for (AGSFeatureTable* fTable in geodatabase.featureTables)

                 {

                     if ([fTable hasGeometry])

                     {

                         AGSFeatureTableLayer *ftl = [[AGSFeatureTableLayer alloc]initWithFeatureTable:fTable];

                         ftl.delegate = self;

                        

                         [self.mapView addMapLayer:ftl];

                     }

                     /*

                     else

                     {

                         if([fTable.tableName isEqualToString:@"SPDQuickCode"])

                         {

                             AGSGDBFeatureServiceTable *fsTable = (AGSGDBFeatureServiceTable *)fTable;

                            

                             for (AGSGraphic *feature in self.quickCodeFeatureSet.features)

                             {

                                 AGSGDBFeature *gdbFeature = [fsTable featureWithTemplate:nil];

                                 [gdbFeature setAttribute:[feature safeAttributeForKey:@"Type"] forKey:@"Type"];

                                 [gdbFeature setAttribute:[feature safeAttributeForKey:@"QuickCode"] forKey:@"QuickCode"];

                                 [gdbFeature setAttribute:[feature safeAttributeForKey:@"Description"] forKey:@"Description"];

                                

                                 NSError *error;

                                

                                 [fsTable saveFeature:gdbFeature error:&error];

                                 if(error)

                                 {

                                     NSLog(@"%@", error.localizedDescription);

                                 }

                             }

                         }

                     }

                    

                     //the commented code is working and saves the quickcode records to the local table

                     //but the problem is that the database records the edits and the edits flags can't

                     //be removed and as a result when sync the data is synced back to the corporate database and generates duplicates.

                     */

                 }

Hope it helps.

Cheers,

Shimin

0 Kudos
MattCooper
Occasional Contributor

Thanks for the response. We ended up just converting our tables to point feature class and just assigned each record a lat/lon.  It works, but isn't ideal.  Would be nice to hear from Esri whether this is a bug or if we're overlooking something in the configuration or SDK.

0 Kudos
MichaelDavis3
Occasional Contributor III

We are also having issues with this - did you ever figure out a work-around or fix?

We are also having issues with related records in a table not being included if the feature is related to it (vs the record being related to the feature).

0 Kudos