
doobie.postgis.instances.geometry.scala Maven / Gradle / Ivy
// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT
package doobie.postgis.instances
import doobie.util.invariant.*
import doobie.util.meta.Meta
import net.postgis.jdbc.*
import net.postgis.jdbc.geometry.*
import org.tpolecat.typename.*
import scala.reflect.ClassTag
object geometry {
implicit val PGgeometryType: Meta[PGgeometry] = Meta.Advanced.other[PGgeometry]("geometry")
implicit val PGbox3dType: Meta[PGbox3d] = Meta.Advanced.other[PGbox3d]("box3d")
implicit val PGbox2dType: Meta[PGbox2d] = Meta.Advanced.other[PGbox2d]("box2d")
@SuppressWarnings(Array("org.wartremover.warts.AsInstanceOf", "org.wartremover.warts.Throw"))
private def geometryType[A >: Null <: Geometry: TypeName](implicit A: ClassTag[A]): Meta[A] =
PGgeometryType.timap[A](g =>
try A.runtimeClass.cast(g.getGeometry).asInstanceOf[A]
catch {
case _: ClassCastException => throw InvalidObjectMapping(A.runtimeClass, g.getGeometry.getClass)
},
)(new PGgeometry(_))
implicit val GeometryType: Meta[Geometry] = geometryType[Geometry]
implicit val ComposedGeomType: Meta[ComposedGeom] = geometryType[ComposedGeom]
implicit val GeometryCollectionType: Meta[GeometryCollection] = geometryType[GeometryCollection]
implicit val LineStringType: Meta[LineString] = geometryType[LineString]
implicit val MultiLineStringType: Meta[MultiLineString] = geometryType[MultiLineString]
implicit val MultiPointType: Meta[MultiPoint] = geometryType[MultiPoint]
implicit val MultiPolygonType: Meta[MultiPolygon] = geometryType[MultiPolygon]
implicit val PointType: Meta[Point] = geometryType[Point]
implicit val PointComposedGeomType: Meta[PointComposedGeom] = geometryType[PointComposedGeom]
implicit val PolygonType: Meta[Polygon] = geometryType[Polygon]
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy