Spatial join - ObjectVision/GeoDMS GitHub Wiki

This example joins two point sets on a distance condition through the Cartesian product of their domain units, which is the general form of a spatial join and the one to use only for small sets: the intermediate domain has #Orgs × #Dests rows. For the functions that evaluate such a condition with a spatial index instead, and how their results relate to a JOIN in SQL, see Spatial joins and allocation.

To sum population per origin over all destinations within 120 km Euclidean:

unit<uint64> Combine_OrgDest := combine_unit_uint64(Orgs, Dests)
{
	attribute<Orgs>    Orgs_rel         := convert(id(.) / uint64(#Dests), Orgs);
	attribute<uint32>  Dests_rel        := convert(id(.) % uint64(#Dests), Dests);
	
	attribute<float64> Distance2        := sqrdist(Orgs/geometry[Orgs_rel], Dests/geometry[Dests_rel]);
	attribute<uint32>  NearbyPopulation := Dests/Population[Dests_rel] * uint32(Distance2 < sqr(120000d));
}

attribute<uint32> Population_within_120km (Orgs) := sum(Combine_OrgDest/NearbyPopulation, Combine_OrgDest/Orgs_rel);
⚠️ **GitHub.com Fallback** ⚠️