Select to view content in your preferred language

How to statistic vector area from a local featureLayer in Kotlin SDK

244
1
09-27-2025 05:49 PM
LiqiangZhu
Emerging Contributor

I am developing an Android application using the ArcGIS Maps SDK for Kotlin (version 200.6).I'm currently using StatisticsQueryParameters to perform statistics on other attribute fields in the FeatureTable, and it works well. Now I need to statistic vector area.

        val statisticDefinition = StatisticDefinition(
            areaFieldName, metricFieldStatisticType, areaFieldAlias
        )

        statisticDefinitions.add(statisticDefinition)
        
        val queryParameters = StatisticsQueryParameters(statisticDefinitions).apply {

            groupByFieldNames.add(firstLevelGroupByFieldName)
            
            secondLevelGroupByFieldName?.let {
                groupByFieldNames.add(it)
            }
            
            boundary?.let {
                geometry = it
            }

        }

        featureTable.queryStatistics(queryParameters).onSuccess { statisticsQueryResult ->
            statisticsQueryResult.forEach { statisticRecord ->

                val groupMap = statisticRecord.group
                val statisticsMap = statisticRecord.statistics

                val tableQueryByLevelRow = TableQueryRow.TableQueryByLevelRow(
                    firstLevelValue = groupMap[firstLevelGroupByFieldName].toString(),
                    secondLevelValue = groupMap[secondLevelGroupByFieldName]?.toString(),
                    metricFieldValue = formatStatisticValue(statisticsMap[areaFieldAlias])?:"",
                )

                result.add(tableQueryByLevelRow)

            }
        }.onFailure { e ->
            throw e
        }

 I know how to statistic the total area by iterating through each feature, getting its geometry, and summing areas.

Is there a better or more efficient method to statistic vector area?

0 Kudos
1 Reply
RamaChintapalli
Esri Contributor

Hi, 
If you have enabled Shape_Area field on your feature layer, then you can use it as the attribute to perform the statistics query on it to compute the SUM/Average etc. 

Thanks
Rama

0 Kudos