Skip to content

Commit

Permalink
add support for relations in overpass queries
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Mar 1, 2024
1 parent 49bffd1 commit 844c86c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/org/maproulette/provider/ChallengeProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 844c86c

Please sign in to comment.