View on GitHub Sample viewer app

Generate a local geodatabase replica from an online feature service.

Image of generate geodatabase

Use case

Generating geodatabase replica is the first step toward taking a feature service offline. It allows you to save features locally for offline display.

How to use the sample

Zoom to any extent. Then click the generate button to generate a geodatabase of features from a feature service filtered to the current extent. A red outline will show the extent used. The job’s progress is shown while the geodatabase is generated. When complete, the map will reload with only the layers in the geodatabase, clipped to the extent.

How it works

  1. Create a GeodatabaseSyncTask with the URL of the feature service and load it.
  2. Create GenerateGeodatabaseParameters specifying the extent and whether to include attachments.
  3. Create a GenerateGeodatabaseJob with geodatabaseSyncTask.createGenerateGeodatabaseJob(parameters, downloadPath). Start the job with job.start().
  4. When the job is done, job.result() will return the geodatabase. Inside the geodatabase are feature tables which can be used to add feature layers to the map.
  5. Call geodatabaseSyncTask.unregisterGeodatabase(geodatabase) after generation when you’re not planning on syncing changes to the service.

Relevant API

  • GenerateGeodatabaseJob
  • GenerateGeodatabaseParameters
  • Geodatabase
  • GeodatabaseSyncTask

Additional information

This sample uses the GeoView-Compose Toolkit module to be able to implement a composable SceneView.

Tags

disconnected, geoview-compose, local geodatabase, offline, replica, sync, toolkit

Sample Code

MainActivity.kt MainActivity.kt GenerateGeodatabaseReplicaFromFeatureServiceViewModel.kt GenerateGeodatabaseReplicaFromFeatureServiceScreen.kt
/*
* Copyright 2023 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.esri.arcgismaps.sample.generategeodatabasereplicafromfeatureservice
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
import com.esri.arcgismaps.sample.generategeodatabasereplicafromfeatureservice.screens.GenerateGeodatabaseReplicaFromFeatureServiceScreen
import com.esri.arcgismaps.sample.sampleslib.BuildConfig
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
enableEdgeToEdge()
setContent {
SampleAppTheme {
GenerateGeodatabaseReplicaFromFeatureServiceApp()
}
}
}
@Composable
private fun GenerateGeodatabaseReplicaFromFeatureServiceApp() {
Surface(color = MaterialTheme.colorScheme.background) {
GenerateGeodatabaseReplicaFromFeatureServiceScreen(
sampleName = getString(R.string.generate_geodatabase_replica_from_feature_service_app_name)
)
}
}
}