Select to view content in your preferred language

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

153
0
Saturday
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
0 Replies