-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3032 from CloudNiner/bugfix/awf/tilelayermetadata…
…-json-codecs#3029 Fix Circe decoders for TileLayerMetadata Schema and Metadata.layoutDefinition
- Loading branch information
Showing
4 changed files
with
118 additions
and
6 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
63 changes: 63 additions & 0 deletions
63
layer/src/test/scala/geotrellis/layer/TileLayerMetadataSpec.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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2019 Azavea | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package geotrellis.layer | ||
|
||
import geotrellis.raster._ | ||
import geotrellis.proj4._ | ||
import geotrellis.vector._ | ||
import _root_.io.circe.syntax._ | ||
import _root_.io.circe.parser.decode | ||
import geotrellis.raster | ||
import org.scalatest._ | ||
|
||
class TileLayerMetadataSpec extends FunSpec with Matchers { | ||
describe("TileLayerMetadata JSON codecs") { | ||
|
||
val cellType = DoubleCellType | ||
val layoutDefinition = LayoutDefinition(Extent(-126.0, 21.608163265306125, -62.0, 54.0), | ||
TileLayout(4, 2, 256, 256)) | ||
val extent = Extent(-126.0, 23.0, -66.0, 54.0) | ||
val bounds = KeyBounds(SpaceTimeKey(0,0,0), SpaceTimeKey(3,1,1000000)) | ||
val tileLayerMetadata: TileLayerMetadata[SpaceTimeKey] = TileLayerMetadata( | ||
cellType, | ||
layoutDefinition, | ||
extent, | ||
LatLng, | ||
bounds | ||
) | ||
|
||
it("should convert TileLayerMetadata to json and back with specific JSON keys") { | ||
val json = tileLayerMetadata.asJson | ||
json.hcursor.downField("cellType").as[CellType] should equal(Right(cellType)) | ||
json.hcursor.downField("layoutDefinition").as[LayoutDefinition] should equal(Right(layoutDefinition)) | ||
json.hcursor.downField("extent").as[Extent] should equal(Right(extent)) | ||
json.hcursor.downField("crs").as[CRS] should equal(Right(LatLng)) | ||
json.hcursor.downField("bounds").as[Bounds[SpaceTimeKey]] should equal(Right(bounds)) | ||
|
||
json.as[TileLayerMetadata[SpaceTimeKey]].right.map(_ should equal(tileLayerMetadata)) | ||
} | ||
|
||
it("should parse a GeoTrellis 1.2 TileLayerMetadata object") { | ||
// NOTE: If this test breaks because the keys in TileLayerMetadata have changed, then | ||
// we've broken backwards compatibility in reading TileLayerMetadata in our layers. | ||
val metadata: String = "{\"extent\":{\"xmin\":-126.0,\"ymin\":23.0,\"xmax\":-66.0,\"ymax\":54.0},\"layoutDefinition\":{\"extent\":{\"xmin\":-126.0,\"ymin\":21.608163265306125,\"xmax\":-62.0,\"ymax\":54.0},\"tileLayout\":{\"layoutCols\":4,\"layoutRows\":2,\"tileCols\":256,\"tileRows\":256}},\"bounds\":{\"minKey\":{\"col\":0,\"row\":0,\"instant\":1514764800000},\"maxKey\":{\"col\":3,\"row\":1,\"instant\":4133894400000}},\"cellType\":\"float32ud1.0000000150474662E30\",\"crs\":\"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs \"}" | ||
val result = decode[TileLayerMetadata[SpaceTimeKey]](metadata) | ||
result.isRight should equal(true) | ||
} | ||
} | ||
} | ||
|
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
36 changes: 36 additions & 0 deletions
36
store/src/test/scala/geotrellis/store/json/SchemaJsonSpec.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2016 Azavea | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package geotrellis.store.json | ||
|
||
|
||
import cats.syntax.either._ | ||
import geotrellis.store.json.Implicits._ | ||
import io.circe._ | ||
import io.circe.parser._ | ||
import org.apache.avro.Schema | ||
import org.scalatest._ | ||
|
||
class SchemaJsonSpec extends FunSpec with Matchers { | ||
describe("KeyIndexJsonFormatFactory") { | ||
val schemaString = "{\"type\":\"record\",\"name\":\"KeyValueRecord\",\"namespace\":\"geotrellis.spark.io\",\"fields\":[{\"name\":\"pairs\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"Tuple2\",\"namespace\":\"scala\",\"fields\":[{\"name\":\"_1\",\"type\":{\"type\":\"record\",\"name\":\"SpaceTimeKey\",\"namespace\":\"geotrellis.spark\",\"fields\":[{\"name\":\"col\",\"type\":\"int\"},{\"name\":\"row\",\"type\":\"int\"},{\"name\":\"instant\",\"type\":\"long\",\"aliases\":[\"millis\"]}]}},{\"name\":\"_2\",\"type\":{\"type\":\"record\",\"name\":\"ArrayMultibandTile\",\"namespace\":\"geotrellis.raster\",\"fields\":[{\"name\":\"bands\",\"type\":{\"type\":\"array\",\"items\":[{\"type\":\"record\",\"name\":\"ByteArrayTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cells\",\"type\":\"bytes\"},{\"name\":\"noDataValue\",\"type\":[\"int\",\"null\"],\"default\":-128}]},{\"type\":\"record\",\"name\":\"FloatArrayTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cells\",\"type\":{\"type\":\"array\",\"items\":\"float\"}},{\"name\":\"noDataValue\",\"type\":[\"boolean\",\"float\"],\"default\":true}]},{\"type\":\"record\",\"name\":\"DoubleArrayTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cells\",\"type\":{\"type\":\"array\",\"items\":\"double\"}},{\"name\":\"noDataValue\",\"type\":[\"boolean\",\"double\"],\"default\":true}]},{\"type\":\"record\",\"name\":\"ShortArrayTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cells\",\"type\":{\"type\":\"array\",\"items\":\"int\"}},{\"name\":\"noDataValue\",\"type\":[\"int\",\"null\"],\"default\":-32768}]},{\"type\":\"record\",\"name\":\"IntArrayTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cells\",\"type\":{\"type\":\"array\",\"items\":\"int\"}},{\"name\":\"noDataValue\",\"type\":[\"int\",\"null\"],\"default\":-2147483648}]},{\"type\":\"record\",\"name\":\"BitArrayTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cells\",\"type\":\"bytes\"}]},{\"type\":\"record\",\"name\":\"UByteArrayTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cells\",\"type\":\"bytes\"},{\"name\":\"noDataValue\",\"type\":[\"int\",\"null\"],\"default\":0}]},{\"type\":\"record\",\"name\":\"UShortArrayTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cells\",\"type\":{\"type\":\"array\",\"items\":\"int\"}},{\"name\":\"noDataValue\",\"type\":[\"int\",\"null\"],\"default\":0}]},{\"type\":\"record\",\"name\":\"ByteConstantTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cell\",\"type\":\"int\"},{\"name\":\"noDataValue\",\"type\":[\"int\",\"null\"],\"default\":-128}]},{\"type\":\"record\",\"name\":\"FloatConstantTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cell\",\"type\":\"float\"},{\"name\":\"noDataValue\",\"type\":[\"boolean\",\"float\"],\"default\":true}]},{\"type\":\"record\",\"name\":\"DoubleConstantTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cell\",\"type\":\"double\"},{\"name\":\"noDataValue\",\"type\":[\"boolean\",\"double\"],\"default\":true}]},{\"type\":\"record\",\"name\":\"ShortConstantTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cell\",\"type\":\"int\"},{\"name\":\"noDataValue\",\"type\":[\"int\",\"null\"],\"default\":0}]},{\"type\":\"record\",\"name\":\"IntConstantTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cell\",\"type\":\"int\"},{\"name\":\"noDataValue\",\"type\":[\"int\",\"null\"],\"default\":-2147483648}]},{\"type\":\"record\",\"name\":\"BitConstantTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cell\",\"type\":\"boolean\"}]},{\"type\":\"record\",\"name\":\"UByteConstantTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cell\",\"type\":\"int\"},{\"name\":\"noDataValue\",\"type\":[\"int\",\"null\"],\"default\":0}]},{\"type\":\"record\",\"name\":\"UShortConstantTile\",\"fields\":[{\"name\":\"cols\",\"type\":\"int\"},{\"name\":\"rows\",\"type\":\"int\"},{\"name\":\"cell\",\"type\":\"int\"},{\"name\":\"noDataValue\",\"type\":[\"int\",\"null\"],\"default\":0}]}]}}]}}]}}}]}" | ||
it("should be able to decode Schema from generic Json, NOT String") { | ||
val json: Json = parse(schemaString).valueOr(throw _) | ||
val schema = json.as[Schema].valueOr(throw _) | ||
} | ||
} | ||
} | ||
|