input(relation: 'nz-trig-points', name: 'survey_mark') as survey_marks
 -> join(on:true) as join_marks_and_districts
 -> select({survey_mark, sample_centroid(geometry: survey_mark, coverage: districts) as district}) as marks_and_districts
 -> select({survey_mark, district.name as district}) as marks_and_district_name

# we save the same marks_and_districts to multiple outputs then we can count the
# results in each to check they are the same size
marks_and_district_name -> save('marks1')
marks_and_district_name -> save('marks2')
marks_and_district_name -> save('marks3')

marks_and_districts
  -> group(by: district, select: {district, count(survey_mark) as mark_count})
  -> save('marks_by_district')

input(relation: 'nz-land-districts', name: 'district') as districts
 -> group({to_coverage(district) as districts})
 -> join_marks_and_districts.rhs
