I am working on the typology of urban blocks. Each block contains a number of buildings, each of which has an area and a height.
I would like to calculate the maximum, minimum, average and median area and height in each block on arcade. Can you help me please?
Solved! Go to Solution.
If you want to do this in the CalculateField tool, you can use this expression, modified for each statistic:
// load the whole feature class
var fs_buildings = FeatureSetByName($datastore, "BuildingFC", ["BlockID", "BuildingID", "BuildingHeight", "BuildingArea"], false)
// only select rows with the current feature's BlockID
var id = $feature.BlockID
var fs_buildings_block = Filter(fs_buildings, "BlockID = @ID")
// edit this line for each statistic and field
return Min(fs_buildings_block, "BuildingHeight")
For the functions, look here:
https://developers.arcgis.com/arcade/function-reference/data_functions/#featuresetbyid
https://developers.arcgis.com/arcade/function-reference/data_functions/#groupby
As an example, you can use the following code in the Playground | ArcGIS Arcade | ArcGIS Developer
var fs_buildings = {
"geometryType": "",
"fields": [
{"name": "BlockID", "type": "esriFieldTypeInteger"},
{"name": "BuildingID", "type": "esriFieldTypeInteger"},
{"name": "BuildingHeight", "type": "esriFieldTypeDouble"},
{"name": "BuildingArea", "type": "esriFieldTypeDouble"}
],
"features": [
{"attributes": {"BlockID": 1, "BuildingID": 1, "BuildingHeight": 10., "BuildingArea": 300.}},
{"attributes": {"BlockID": 1, "BuildingID": 2, "BuildingHeight": 30., "BuildingArea": 500.}},
{"attributes": {"BlockID": 1, "BuildingID": 3, "BuildingHeight": 15., "BuildingArea": 250.}},
{"attributes": {"BlockID": 2, "BuildingID": 4, "BuildingHeight": 16., "BuildingArea": 400.}},
{"attributes": {"BlockID": 2, "BuildingID": 5, "BuildingHeight": 10., "BuildingArea": 300.}},
{"attributes": {"BlockID": 3, "BuildingID": 6, "BuildingHeight": 10., "BuildingArea": 300.}}
]
}
fs_buildings = FeatureSet(Text(fs_buildings))
//return fs_buildings
// actually use one of the FeatureSetBy*() functions:
//var p = Portal(...)
//var fs_buildings = FeatureSetByPortalItem(p, item, layer, ["BlockID", "BuildingID", "BuildingHeight", "BuildingArea"], false)
var statistics = [
{"name": "Count", "expression": "BuildingID", "statistic": "COUNT"},
{"name": "HeightMax", "expression": "BuildingHeight", "statistic": "MAX"},
{"name": "HeightMin", "expression": "BuildingHeight", "statistic": "MIN"},
{"name": "HeightMean", "expression": "BuildingHeight", "statistic": "AVG"},
{"name": "AreaMax", "expression": "BuildingArea", "statistic": "MAX"},
{"name": "AreaMin", "expression": "BuildingArea", "statistic": "MIN"},
{"name": "AreaMean", "expression": "BuildingArea", "statistic": "AVG"},
]
var fs_grouped_buildings = GroupBy(fs_buildings, "BlockID", statistics)
return fs_grouped_buildings
Thank you very much for your quick response
in fact I already have a table with the BlockID, the ID of the buildings, the area and the height of each building. and I would like to calculate from this table.
could you, please, tell me how to calculate each statistic by adding a new field on my buildings table and calculating the field?
If you want to do this in the CalculateField tool, you can use this expression, modified for each statistic:
// load the whole feature class
var fs_buildings = FeatureSetByName($datastore, "BuildingFC", ["BlockID", "BuildingID", "BuildingHeight", "BuildingArea"], false)
// only select rows with the current feature's BlockID
var id = $feature.BlockID
var fs_buildings_block = Filter(fs_buildings, "BlockID = @ID")
// edit this line for each statistic and field
return Min(fs_buildings_block, "BuildingHeight")
IT work...Thank you very much !!!!