Hello, I have a table with buildings distributed in blocks. I would like to know how to calculate the distance between the neighboring buildings. can you Help me please?
This calculates the distance to the closest building in the same block:
// load the whole feature class
var fs_buildings = FeatureSetByName($datastore, "BuildingFC", ["BlockID", "BuildingID"], false)
// only select rows with the current feature's BlockID and not this building
var block_id = $feature.BlockID
var building_id = $feature.BuildingID
var fs_buildings_block = Filter(fs_buildings, "BlockID = @block_id AND BuildingID <> @building_id")
function closest_feature(fs) {
var min_dist = 99999999
var closest_feature = null
for(var f in fs) {
var f_dist = Distance(f, $feature)
if(f_dist < min_dist) {
closest_building = f
min_dist = f_dist
}
}
return closest_feature
}
var closest_building = closest_feature(fs_buildings_block)
if(closest_building == null) { return null }
return Distance($feature, closest_building)