Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support postgis ST_EndPoint, ST_PointN and ST_StartPoint.
Browse files Browse the repository at this point in the history
Elvis Lee committed Jul 17, 2020
1 parent ee48190 commit b4acee4
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -249,6 +249,8 @@ class PgPostGISSupportSuite extends FunSuite {

test("PostGIS Lifted support - accessor") {
val point = wktReader.read("POINT(4 5 7)")
val point1 = wktReader.read("POINT(0 0)").asInstanceOf[Point]
val point2 = wktReader.read("POINT(3 3)").asInstanceOf[Point]
val geogPoint = wktGeogReader.read("POINT(4 5 7)").asInstanceOf[Geography]
val line = wktReader.read("LINESTRING(0 0, 3 3)")
val geogLine = wktGeogReader.read("LINESTRING(0 0, 3 3)").asInstanceOf[Geography]
@@ -316,6 +318,10 @@ class PgPostGISSupportSuite extends FunSuite {
GeomTests.filter(_.id === collectionbean.id.bind).map(_.geom.dimension).result.head.map(
r => assert(1 === r)
),
// endPoint
GeomTests.filter(_.id === linebean.id.bind).map(_.geom.endPoint).result.head.map(
r => assert(point2 === r)
),
// coord_dim
GeomTests.filter(_.id === collectionbean.id.bind).map(_.geom.coordDim).result.head.map(
r => assert(2 === r)
@@ -332,6 +338,14 @@ class PgPostGISSupportSuite extends FunSuite {
GeomTests.filter(_.id === polygonbean.id.bind).map(_.geom.nRings).result.head.map(
r => assert(1 === r)
),
// pointN
GeomTests.filter(_.id === linebean.id.bind).map(_.geom.pointN(2)).result.head.map(
r => assert(point2 === r)
),
// startPoint
GeomTests.filter(_.id === linebean.id.bind).map(_.geom.startPoint).result.head.map(
r => assert(point1 === r)
),
// x
GeomTests.filter(_.id === pointbean.id.bind).map(_.geom.x).result.head.map(
r => assert(Math.abs(4f - r) < 0.001f)
Original file line number Diff line number Diff line change
@@ -2,11 +2,11 @@ package com.github.tminglei.slickpg
package geom

import com.github.tminglei.slickpg.window.WindowFunc
import slick.lifted._
import slick.ast.{LiteralNode, TypedType}
import slick.ast.Library.{SqlFunction, SqlOperator}
import slick.lifted.FunctionSymbolExtensionMethods._
import slick.ast.{LiteralNode, TypedType}
import slick.jdbc.{JdbcType, JdbcTypesComponent, PostgresProfile}
import slick.lifted.FunctionSymbolExtensionMethods._
import slick.lifted._

trait PgPostGISExtensions extends JdbcTypesComponent { driver: PostgresProfile =>
import driver.api._
@@ -147,9 +147,12 @@ trait PgPostGISExtensions extends JdbcTypesComponent { driver: PostgresProfile =
val Boundary = new SqlFunction("ST_Boundary")
val Dimension = new SqlFunction("ST_Dimension")
val CoordDim = new SqlFunction("ST_CoordDim")
val EndPoint = new SqlFunction("ST_EndPoint")
val NDims = new SqlFunction("ST_NDims")
val NPoints = new SqlFunction("ST_NPoints")
val NRings = new SqlFunction("ST_NRings")
val PointN = new SqlFunction("ST_PointN")
val StartPoint = new SqlFunction("ST_StartPoint")
val X = new SqlFunction("ST_X")
val Y = new SqlFunction("ST_Y")
val Z = new SqlFunction("ST_Z")
@@ -335,6 +338,9 @@ trait PgPostGISExtensions extends JdbcTypesComponent { driver: PostgresProfile =
def dimension[R](implicit om: o#to[Int, R]) = {
om.column(GeomLibrary.Dimension, n)
}
def endPoint[R](implicit om: o#to[POINT, R]) = {
om.column(GeomLibrary.EndPoint, n)
}
def coordDim[R](implicit om: o#to[Int, R]) = {
om.column(GeomLibrary.CoordDim, n)
}
@@ -347,6 +353,12 @@ trait PgPostGISExtensions extends JdbcTypesComponent { driver: PostgresProfile =
def nRings[R](implicit om: o#to[Int, R]) = {
om.column(GeomLibrary.NRings, n)
}
def pointN[R](position: Rep[Int])(implicit om: o#to[POINT, R]) = {
om.column(GeomLibrary.PointN, n, position.toNode)
}
def startPoint[R](implicit om: o#to[POINT, R]) = {
om.column(GeomLibrary.StartPoint, n)
}
def x[R](implicit om: o#to[Float, R]) = {
om.column(GeomLibrary.X, n)
}

0 comments on commit b4acee4

Please sign in to comment.