From 844c86cc56b538cbe368dd7fe7fadcab70398626 Mon Sep 17 00:00:00 2001 From: CollinBeczak Date: Fri, 1 Mar 2024 13:18:15 -0600 Subject: [PATCH] add support for relations in overpass queries --- .../provider/ChallengeProvider.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/org/maproulette/provider/ChallengeProvider.scala b/app/org/maproulette/provider/ChallengeProvider.scala index 5ee518f0..5d54ffd8 100644 --- a/app/org/maproulette/provider/ChallengeProvider.scala +++ b/app/org/maproulette/provider/ChallengeProvider.scala @@ -485,6 +485,13 @@ class ChallengeProvider @Inject() ( "Element type 'way' does not match target type of '" + targetType + "'" ) } + case Some("relation") => + if (targetType != "relation") { + targetTypeFailed = true + throw new InvalidException( + "Element type 'relation' does not match target type of '" + targetType + "'" + ) + } case Some("node") => if (targetType != "node") { targetTypeFailed = true @@ -522,6 +529,18 @@ class ChallengeProvider @Inject() ( List((geom \ "lon").as[Double], (geom \ "lat").as[Double]) } Some(Json.obj("type" -> "LineString", "coordinates" -> points)) + case Some("relation") => + // Relations can contain multiple geometries. Here, we're handling them similarly to ways. + val geometries = (element \ "members").as[List[JsValue]].flatMap { + member => + (member \ "geometry").asOpt[List[JsValue]] + } + val points = geometries.flatMap { geom => + geom.map { point => + ((point \ "lon").as[Double], (point \ "lat").as[Double]) + } + } + Some(Json.obj("type" -> "LineString", "coordinates" -> points)) case Some("node") => Some( Json.obj(