-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
View collection item footprints as MVT layer (#203)
* Upgrade postgres to 12 with postgis 3 * Update collection item tiles endpoint name * wip * Add tiles links to collections * Rename TileRequest -> RasterTileRequest * Serve MVT byte array from collection footprint endpoint * print to help debug * Include missing path segment * Project tile envelope to source srid * Work out projection adventures * Remove unused * scalafix / scalafmt * Don't interpolate uninterpolated string * Add TileJSON endpoint for collection footprints * Actually use the footprint tile json route * Switch x and y order? * Revert "Switch x and y order?" This reverts commit 88d713d. * Switch scheme? * Remove println, scalafmt / fix
- Loading branch information
Showing
15 changed files
with
420 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 39 additions & 42 deletions
81
application/src/main/scala/com/azavea/franklin/api/endpoints/TileEndpoints.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,71 @@ | ||
package com.azavea.franklin.api.endpoints | ||
|
||
import com.azavea.franklin.datamodel.{ | ||
ItemRasterTileRequest, | ||
MapboxVectorTileFootprintRequest, | ||
Quantile | ||
} | ||
import com.azavea.franklin.error.NotFound | ||
import io.circe.Json | ||
import sttp.model.StatusCode.{NotFound => NF} | ||
import sttp.tapir._ | ||
import sttp.tapir.codec.refined._ | ||
import sttp.tapir.json.circe._ | ||
|
||
import java.net.URLDecoder | ||
import java.nio.charset.StandardCharsets | ||
|
||
case class TileRequest( | ||
collectionRaw: String, | ||
itemRaw: String, | ||
z: Int, | ||
x: Int, | ||
y: Int, | ||
asset: String, | ||
redBandOption: Option[Int], | ||
greenBandOption: Option[Int], | ||
blueBandOption: Option[Int], | ||
upperQuantileOption: Option[Quantile], | ||
lowerQuantileOption: Option[Quantile] | ||
) { | ||
|
||
val collection = URLDecoder.decode(collectionRaw, StandardCharsets.UTF_8.toString) | ||
val item = URLDecoder.decode(itemRaw, StandardCharsets.UTF_8.toString) | ||
|
||
val redBand = redBandOption.getOrElse(0) | ||
val greenBand = greenBandOption.getOrElse(1) | ||
val blueBand = blueBandOption.getOrElse(2) | ||
|
||
val bands = Seq(redBand, greenBand, blueBand) | ||
|
||
// Because lists are 0 indexed and humans are 1 indexed we need to adjust | ||
val upperQuantile = upperQuantileOption.map(_.value).getOrElse(100) - 1 | ||
val lowerQuantile = lowerQuantileOption.map(_.value).getOrElse(-1) + 1 | ||
|
||
val zxy = (z, x, y) | ||
|
||
} | ||
|
||
class TileEndpoints(enableTiles: Boolean) { | ||
|
||
val basePath = "tiles" / "collections" | ||
val zxyPath = path[Int] / path[Int] / path[Int] | ||
|
||
val tilePath: EndpointInput[(String, String, Int, Int, Int)] = | ||
val itemRasterTilePath: EndpointInput[(String, String, Int, Int, Int)] = | ||
(basePath / path[String] / "items" / path[String] / "WebMercatorQuad" / zxyPath) | ||
|
||
val tileParameters: EndpointInput[TileRequest] = | ||
tilePath | ||
val collectionFootprintTilePath: EndpointInput[(String, Int, Int, Int)] = | ||
(basePath / path[String] / "footprint" / "WebMercatorQuad" / zxyPath) | ||
|
||
val collectionFootprintTileJsonPath: EndpointInput[String] = | ||
(basePath / path[String] / "footprint" / "tile-json") | ||
|
||
val itemRasterTileParameters: EndpointInput[ItemRasterTileRequest] = | ||
itemRasterTilePath | ||
.and(query[String]("asset")) | ||
.and(query[Option[Int]]("redBand")) | ||
.and(query[Option[Int]]("greenBand")) | ||
.and(query[Option[Int]]("blueBand")) | ||
.and(query[Option[Quantile]]("upperQuantile")) | ||
.and(query[Option[Quantile]]("lowerQuantile")) | ||
.mapTo(TileRequest) | ||
.mapTo(ItemRasterTileRequest) | ||
|
||
val tileEndpoint: Endpoint[TileRequest, NotFound, Array[Byte], Nothing] = | ||
val itemRasterTileEndpoint: Endpoint[ItemRasterTileRequest, NotFound, Array[Byte], Nothing] = | ||
endpoint.get | ||
.in(tileParameters) | ||
.in(itemRasterTileParameters) | ||
.out(binaryBody[Array[Byte]]) | ||
.out(header("content-type", "image/png")) | ||
.errorOut(oneOf(statusMapping(NF, jsonBody[NotFound].description("not found")))) | ||
.description("Raster Tile endpoint for Collection Item") | ||
.name("collectionItemTiles") | ||
|
||
val collectionFootprintTileEndpoint | ||
: Endpoint[MapboxVectorTileFootprintRequest, NotFound, Array[Byte], Nothing] = | ||
endpoint.get | ||
.in(collectionFootprintTilePath.mapTo(MapboxVectorTileFootprintRequest)) | ||
.out(binaryBody[Array[Byte]]) | ||
.out(header("content-type", "application/vnd.mapbox-vector-tile")) | ||
.errorOut(oneOf(statusMapping(NF, jsonBody[NotFound].description("not found")))) | ||
.description("MVT endpoint for a collection's footprint") | ||
.name("collectionFootprintTiles") | ||
|
||
val collectionFootprintTileJson: Endpoint[String, NotFound, Json, Nothing] = | ||
endpoint.get | ||
.in(collectionFootprintTileJsonPath) | ||
.out(jsonBody[Json]) | ||
.errorOut(oneOf(statusMapping(NF, jsonBody[NotFound].description("not found")))) | ||
.description("TileJSON representation of this collection's footprint tiles") | ||
.name("collectionFootprintTileJSON") | ||
|
||
val endpoints = enableTiles match { | ||
case true => List(tileEndpoint) | ||
case _ => List.empty | ||
case true => | ||
List(itemRasterTileEndpoint, collectionFootprintTileEndpoint, collectionFootprintTileJson) | ||
case _ => List.empty | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
application/src/main/scala/com/azavea/franklin/api/endpoints/package.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.