Skip to content

Commit

Permalink
Fixup after rebase
Browse files Browse the repository at this point in the history
Signed-off-by: jpolchlo <jpolchlopek@azavea.com>
  • Loading branch information
jpolchlo committed Jun 27, 2019
1 parent 72097e6 commit 2577afb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
Expand Up @@ -36,7 +36,7 @@ trait FeatureFormats {
Json.obj(
"type" -> "Feature".asJson,
"geometry" -> GeometryFormats.geometryEncoder(obj.geom),
"bbox" -> Extent.listEncoder(obj.extent),
"bbox" -> Extent.listEncoder(obj.geom.extent),
"properties" -> obj.data.asJson
)
}
Expand Down
Expand Up @@ -82,14 +82,14 @@ trait GeometryFormats {
}

implicit lazy val lineEncoder: Encoder[LineString] =
Encoder.encodeJson.contramap[Line] { obj =>
Encoder.encodeJson.contramap[LineString] { obj =>
Json.obj(
"type" -> "LineString".asJson,
"coordinates" -> writeLineCoords(obj)
)
}

implicit lazy val lineDecoder: Decoder[Line] =
implicit lazy val lineDecoder: Decoder[LineString] =
Decoder.decodeJson.emap { json: Json =>
val c = json.hcursor
c.downField("type").as[String].flatMap {
Expand Down Expand Up @@ -135,8 +135,8 @@ trait GeometryFormats {
}.leftMap(_ => "MultiPoint geometry expected")
}

implicit lazy val multiLineEncoder: Encoder[MultiLine] =
Encoder.encodeJson.contramap[MultiLine] { obj =>
implicit lazy val multiLineStringEncoder: Encoder[MultiLineString] =
Encoder.encodeJson.contramap[MultiLineString] { obj =>
Json.obj(
"type" -> "MultiLineString".asJson,
"coordinates" -> obj.lines.map(writeLineCoords).toVector.asJson
Expand All @@ -147,7 +147,7 @@ trait GeometryFormats {
Decoder.decodeJson.emap { json: Json =>
val c = json.hcursor
c.downField("type").as[String].flatMap {
case "MultiLineString" => c.downField("coordinates").focus.map(json => MultiLineString(json.asArray.toVector.flatten.map(readLineCoords))).toRight("MultiLine geometry expected")
case "MultiLineString" => c.downField("coordinates").focus.map(json => MultiLineString(json.asArray.toVector.flatten.map(readLineCoords))).toRight("MultiLineString geometry expected")
case "Feature" => multiLineStringDecoder(unwrapFeature(json).hcursor)
case _ => Left("MultiLineString geometry expected")
}.leftMap(_ => "MultiLineString geometry expected")
Expand Down Expand Up @@ -203,14 +203,16 @@ trait GeometryFormats {
case geom: Point => geom.asJson
case geom: LineString => geom.asJson
case geom: Polygon => geom.asJson
case geom: Extent => geom.toPolygon.asJson
case geom: MultiPolygon => geom.asJson
case geom: MultiPoint => geom.asJson
case geom: MultiLineString => geom.asJson
case geom: GeometryCollection => geom.asJson
case geom => throw new Exception(s"Unknown Geometry type ${geom.getClass.getName}: $geom")
}

implicit lazy val extentEncoder: Encoder[Extent] =
Encoder.encodeJson.contramap[Extent] {_.toPolygon.asJson}

implicit lazy val geometryDecoder: Decoder[Geometry] =
Decoder.decodeJson.emap { json: Json =>
val c = json.hcursor
Expand Down
Expand Up @@ -22,6 +22,7 @@ import cats.syntax.either._
import io.circe.parser.{parse => circeParse}

import geotrellis.vector._
import scala.reflect.ClassTag
import scala.reflect.runtime.universe.TypeTag
import scala.util.{Try, Success, Failure}

Expand Down Expand Up @@ -73,7 +74,7 @@ trait Implicits extends GeoJsonSupport {
* @tparam G type of geometry desired to extract
* @return Seq[G] containing geometries
*/
def extractGeometries[G <: Geometry: Decoder: TypeTag](): Seq[G] =
def extractGeometries[G <: Geometry: Decoder: TypeTag: ClassTag](): Seq[G] =
circeParse(s).flatMap(_.as[G]) match {
case Right(g) => Seq(g)
case Left(_) =>
Expand Down
Expand Up @@ -129,7 +129,7 @@ class JsonFeatureCollectionMap(features: List[Json] = Nil) {
def getAllLineStrings() = getAll[LineString]
def getAllPolygons() = getAll[Polygon]
def getAllMultiPoints() = getAll[MultiPoint]
def getAllMultiLineStrings() = getAll[MultiLine]
def getAllMultiLineStrings() = getAll[MultiLineString]
def getAllMultiPolygons() = getAll[MultiPolygon]

def getAllGeometries(): Map[String, Geometry] =
Expand Down

0 comments on commit 2577afb

Please sign in to comment.