https://github.com/saulortega/pgeo.latlng
Geometric Types for Postgres
https://github.com/saulortega/pgeo.latlng
geographic geometric geometry go golang postgres postgresql psql
Last synced: 2 months ago
JSON representation
Geometric Types for Postgres
- Host: GitHub
- URL: https://github.com/saulortega/pgeo.latlng
- Owner: saulortega
- Created: 2018-06-27T22:01:19.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-18T02:36:38.000Z (over 2 years ago)
- Last Synced: 2025-01-28T01:36:47.958Z (4 months ago)
- Topics: geographic, geometric, geometry, go, golang, postgres, postgresql, psql
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pgeo.latlng
This package is identical to [pgeo](https://github.com/saulortega/pgeo) except that Point is defined as Point{ Lat, Lng } instead of Point{ X, Y }Package pgeo implements [geometric types for Postgres](https://www.postgresql.org/docs/current/static/datatype-geometric.html)
It uses Scanner and Valuer interfaces from `database/sql`
# Types
```go
//Points are the fundamental two-dimensional building block for geometric types.
//Lat and Lng are the respective coordinates, as floating-point numbers
type Point struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
}//Circles are represented by a center point and radius.
type Circle struct {
Point
Radius float64 `json:"radius"`
}//Line represents a infinite line with the linear equation Ax + By + C = 0, where A and B are not both zero.
type Line struct {
A float64 `json:"a"`
B float64 `json:"b"`
C float64 `json:"c"`
}//Paths are represented by lists of connected points.
//Paths can be open, where the first and last points in the list are considered not connected,
//or closed, where the first and last points are considered connected.
type Path struct {
Points []Point
Closed bool `json:"closed"`
}//Boxes are represented by pairs of points that are opposite corners of the box.
type Box [2]Point//Line segments are represented by pairs of points that are the endpoints of the segment.
type Lseg [2]Point//Polygons are represented by lists of points (the vertexes of the polygon).
type Polygon []Point
```### Null Types
```go
type NullPoint struct {
Point
Valid bool `json:"valid"`
}//Same for others...
```# Functions
### Create Types
```go
NewPoint(Lat, Lng float64) PointNewLine(A, B, C float64) Line
NewLseg(A, B Point) Lseg
NewBox(A, B Point) Box
NewPath(P []Point, Closed bool) Path
NewPolygon(P []Point) Polygon
NewCircle(P Point, Radius float64) Circle
```### Null Types
```go
NewNullPoint(P Point, valid bool) NullPointNewNullLine(L Line, valid bool) NullLine
NewNullLseg(L Lseg, valid bool) NullLseg
NewNullBox(B Box, valid bool) NullBox
NewNullPath(P Path, valid bool) NullPath
NewNullPolygon(P Polygon, valid bool) NullPolygon
NewNullCircle(C Circle, valid bool) NullCircle
```### Rand Types
```go
NewRandPoint() PointNewRandLine() Line
NewRandLseg() Lseg
NewRandBox() Box
NewRandPath() Path
NewRandPolygon() Polygon
NewRandCircle() Circle
```### Zero Point
```go
//Returns a Point Lat=0, Lng=0
NewZeroPoint() Point
```