Documentation
¶
Overview ¶
Package postgis PostgreSQL PostGIS의 좁은 Point 값과 database/sql용 SQL helper를 제공한다.
이 패키지는 ORM, migration manager, 다른 데이터베이스 dialect를 소유하지 않는다. 공간 연산의 단위와 연결 수명은 호출자가 관리한다.
Index ¶
- Variables
- func CreateExtensionSQL() string
- func CreateSpatialIndexSQL(table, column string) (string, error)
- func CreateSpatialTableSQL(table, column string, srid int) (string, error)
- func InsertPoint(table, column string, point Point) (sqlkit.Statement, error)
- func SelectPointSQL(table, column string) (string, error)
- func WithinBounds(table, column string, minX, minY, maxX, maxY float64, srid int) (sqlkit.Statement, error)
- func WithinDistance(table, column string, center Point, distance float64) (sqlkit.Statement, error)
- type Point
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPoint 좌표, EWKB 또는 WKT Point 값이 유효하지 않을 때 반환된다. ErrInvalidPoint = errors.New("postgis: invalid point") // ErrInvalidSRID SRID가 음수이거나 지원 범위를 벗어날 때 반환된다. ErrInvalidSRID = errors.New("postgis: invalid SRID") // ErrInvalidArgument SQL helper 인자가 비어 있거나 안전하지 않을 때 반환된다. ErrInvalidArgument = errors.New("postgis: invalid argument") // ErrInvalidDistance 거리 값이 유한하지 않거나 음수일 때 반환된다. ErrInvalidDistance = errors.New("postgis: invalid distance") )
Functions ¶
func CreateExtensionSQL ¶
func CreateExtensionSQL() string
CreateExtensionSQL 는 PostGIS extension을 명시적으로 활성화하는 SQL을 반환한다.
func CreateSpatialIndexSQL ¶
CreateSpatialIndexSQL 는 PostGIS geometry column에 대한 GIST index DDL을 만든다.
func CreateSpatialTableSQL ¶
CreateSpatialTableSQL 는 SRID 제약이 있는 PostGIS Point 테이블 DDL을 만든다.
func InsertPoint ¶
InsertPoint 는 EWKB를 bind argument로 사용하는 point insert statement를 만든다.
func SelectPointSQL ¶
SelectPointSQL 는 geometry column의 WKB와 SRID를 함께 읽는 SQL statement를 만든다.
func WithinBounds ¶
func WithinBounds(table, column string, minX, minY, maxX, maxY float64, srid int) (sqlkit.Statement, error)
WithinBounds 는 inclusive bounding box predicate statement를 만든다.
func WithinDistance ¶
WithinDistance 는 SRID가 같은 geometry에서 거리 단위의 indexed predicate를 만든다.
Example ¶
package main
import (
"context"
"database/sql"
"github.com/bluetape4k/bluetape-go/sqlkit/postgis"
)
func main() {
ctx := context.Background()
var db *sql.DB
point, _ := postgis.NewPoint(127.0276, 37.4979, 4326)
stmt, _ := postgis.WithinDistance("places", "location", point, 500)
if db != nil {
_, _ = db.ExecContext(ctx, stmt.SQL, stmt.Args...)
}
}
Output:
Types ¶
type Point ¶
Point 는 WGS84 경도(X)·위도(Y)와 SRID를 보관하는 유효한 공간 값이다.
X는 -180..180, Y는 -90..90의 degree 값이다. zero value는 SQL NULL을 나타내며, Valid가 true일 때만 Value가 non-NULL EWKB를 반환한다.
Example ¶
package main
import (
"github.com/bluetape4k/bluetape-go/sqlkit/postgis"
)
func main() {
point, err := postgis.NewPoint(127.0276, 37.4979, 4326)
if err != nil {
panic(err)
}
value, err := point.Value()
if err != nil {
panic(err)
}
_ = value
}
Output:
func NewWGS84Point ¶
NewWGS84Point 는 위도와 경도를 받아 SRID 4326 Point를 생성한다.
func (Point) MarshalEWKB ¶
MarshalEWKB 는 Point를 호출자가 소유하는 새 EWKB byte slice로 인코딩한다.