-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avro Schema Creation for ProjectedExtent and TemporalProjectedExtent #1971
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
980f91e
Added new types to ExtentCodecs
jbouffard ecde16e
Removed ProjectedExent and TemporalProjectedExtent from ExtentCodec
jbouffard 356f5a8
Created ProjectedExtentCodec
jbouffard 5a114dd
Created TemporalProjectedExtentCodec
jbouffard 2330f79
Added the new codecs to Implicits
jbouffard 3f26429
Added tests for the various ExtentCodecs
jbouffard 8d44a63
Edited namespace in ProjectedExtentCodec
jbouffard 4496e06
Reversed code change in ExtentCodec
jbouffard 804e340
Removed extra white space in ExtentCodec
jbouffard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
38 changes: 38 additions & 0 deletions
38
spark/src/main/scala/geotrellis/spark/io/avro/codecs/ProjectedExtentCodec.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,38 @@ | ||
package geotrellis.spark.io.avro.codecs | ||
|
||
import geotrellis.proj4.CRS | ||
import geotrellis.spark._ | ||
import geotrellis.spark.io.avro._ | ||
import geotrellis.spark.io.avro.codecs._ | ||
import geotrellis.spark.io.avro.codecs.Implicits._ | ||
import geotrellis.vector._ | ||
|
||
import org.apache.avro._ | ||
import org.apache.avro.generic._ | ||
|
||
// --- // | ||
|
||
trait ProjectedExtentCodec { | ||
implicit def projectedExtentCodec = new AvroRecordCodec[ProjectedExtent] { | ||
def schema: Schema = SchemaBuilder | ||
.record("ProjectedExtent").namespace("geotrellis.vector") | ||
.fields() | ||
.name("extent").`type`(extentCodec.schema).noDefault() | ||
.name("epsg").`type`().intType().noDefault() | ||
.endRecord() | ||
|
||
def encode(projectedExtent: ProjectedExtent, rec: GenericRecord): Unit = { | ||
rec.put("extent", extentCodec.encode(projectedExtent.extent)) | ||
rec.put("epsg", projectedExtent.crs.epsgCode.get) | ||
} | ||
|
||
def decode(rec: GenericRecord): ProjectedExtent = { | ||
val epsg = rec[Int]("epsg") | ||
val crs = CRS.fromEpsgCode(epsg) | ||
|
||
val extent = extentCodec.decode(rec[GenericRecord]("extent")) | ||
|
||
ProjectedExtent(extent, crs) | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
spark/src/main/scala/geotrellis/spark/io/avro/codecs/TemporalProjectedExtentCodec.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,41 @@ | ||
package geotrellis.spark.io.avro.codecs | ||
|
||
import geotrellis.proj4.CRS | ||
import geotrellis.spark._ | ||
import geotrellis.spark.io.avro._ | ||
import geotrellis.spark.io.avro.codecs._ | ||
import geotrellis.spark.io.avro.codecs.Implicits._ | ||
import geotrellis.vector._ | ||
|
||
import org.apache.avro._ | ||
import org.apache.avro.generic._ | ||
|
||
|
||
trait TemporalProjectedExtentCodec { | ||
implicit def temporalProjectedExtentCodec = new AvroRecordCodec[TemporalProjectedExtent] { | ||
def schema: Schema = SchemaBuilder | ||
.record("TemporalProjectedExtent").namespace("geotrellis.spark") | ||
.fields() | ||
.name("extent").`type`(extentCodec.schema).noDefault() | ||
.name("epsg").`type`().intType().noDefault() | ||
.name("instant").`type`().longType().noDefault() | ||
.endRecord() | ||
|
||
def encode(temporalProjectedExtent: TemporalProjectedExtent, rec: GenericRecord): Unit = { | ||
rec.put("extent", extentCodec.encode(temporalProjectedExtent.extent)) | ||
rec.put("epsg", temporalProjectedExtent.crs.epsgCode.get) | ||
rec.put("instant", temporalProjectedExtent.instant) | ||
} | ||
|
||
def decode(rec: GenericRecord): TemporalProjectedExtent = { | ||
val instant = rec[Long]("instant") | ||
val epsg = rec[Int]("epsg") | ||
val crs = CRS.fromEpsgCode(epsg) | ||
|
||
val extent = extentCodec.decode(rec[GenericRecord]("extent")) | ||
|
||
TemporalProjectedExtent(extent, crs, instant) | ||
} | ||
} | ||
} | ||
|
38 changes: 38 additions & 0 deletions
38
spark/src/test/scala/geotrellis/spark/io/avro/ExtentCodecsSpec.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,38 @@ | ||
/* | ||
* 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.spark.io.avro | ||
|
||
import geotrellis.spark.io.avro.codecs._ | ||
import org.scalatest._ | ||
import geotrellis.proj4._ | ||
import geotrellis.vector._ | ||
import geotrellis.spark._ | ||
import geotrellis.spark.io.avro.AvroTools._ | ||
|
||
class ExtentCodecsSpec extends FunSpec with Matchers with AvroTools { | ||
describe("ExtentCodecs") { | ||
it("encodes Extent"){ | ||
roundTrip(Extent(0, 1, 2, 3)) | ||
} | ||
it("encodes ProjectedExtent") { | ||
roundTrip(ProjectedExtent(Extent(0, 1, 2, 3), CRS.fromEpsgCode(4324))) | ||
} | ||
it("encodes TemporalProjectedExtent"){ | ||
roundTrip(TemporalProjectedExtent(Extent(0, 1, 2, 3), CRS.fromEpsgCode(4324), 1.toLong)) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update to use the proj4 string.
Or, if possible, check if it's an EPSG code, and then fall back to CRS?