View on GitHub Sample viewer app

Create a Feature Collection Layer from a Feature Collection Table, and add it to a map.

Image of add feature collection layer from table

Use case

A Feature Collection allows easily importing external data (such as CSV files), as well as creating custom schema for data that is in non-standardized format. This data can then be used to populate a Feature Collection Table, and displayed in a Feature Collection Layer using the attributes and geometries provided in the external data source. For example, an electricity supplier could use this functionality to visualize existing location data of coverage areas (polygons), power stations (points), transmission lines (polylines), and others.

How to use the sample

When launched, this sample displays a FeatureCollectionLayer with a Point, Polyline and Polygon geometry. Pan and zoom to explore the scene.

How it works

  1. Create a FeatureCollectionLayer using a new feature collection, FeatureCollectionLayer(featureCollection)
  2. Add the feature collection layer to the map, ArcGISMap.operationalLayers.add(featureCollectionLayer).
  3. Create a FeatureCollectionTable for the GeometryTypes Point, Polyline, and Polygon, FeatureCollectionTable(fields, geometryType, spatialReference)
  4. Additionally, pass in a list of Field objects to represent the table’s schema. In this case a field of type String named name is added.
  5. Assign a SimpleRenderer to each table to render any Features from that table using the Symbol that was set.
  6. Add all the feature collection tables to the feature collection, FeatureCollection(featureCollectionTables = listOf(points, lines, polygons)).
  7. Use the createFeature method to create a feature from the feature collection table, passing an attribute and geometry for that feature, FeatureCollectionTable.createFeature(attributes, geometry).
  8. Add new features to the table, FeatureCollectionTable.addFeature(feature).

Relevant API

  • Feature
  • FeatureCollection
  • FeatureCollectionLayer
  • FeatureCollectionTable
  • Field
  • SimpleRenderer

Tags

collection, feature, layers, table

Sample Code

MainActivity.kt MainActivity.kt AddFeatureCollectionLayerFromTableViewModel.kt AddFeatureCollectionLayerFromTableScreen.kt
/* Copyright 2025 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.addfeaturecollectionlayerfromtable
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
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.addfeaturecollectionlayerfromtable.screens.AddFeatureCollectionLayerFromTableScreen
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)
setContent {
SampleAppTheme {
AddFeatureCollectionLayerFromTableApp()
}
}
}
@Composable
private fun AddFeatureCollectionLayerFromTableApp() {
Surface(color = MaterialTheme.colorScheme.background) {
AddFeatureCollectionLayerFromTableScreen(
sampleName = getString(R.string.add_feature_collection_layer_from_table_app_name)
)
}
}
}