-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdoc.go
More file actions
72 lines (72 loc) · 2.38 KB
/
Copy pathdoc.go
File metadata and controls
72 lines (72 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Package gogis provides PostGIS geometry types for GORM.
//
// This package implements PostGIS geometric types that can be used with GORM
// for storing and querying spatial data in PostgreSQL databases with the PostGIS extension.
//
// # Supported Geometry Types
//
// The package supports all major PostGIS geometry types:
// - Point: Represents a single location with longitude and latitude
// - LineString: Represents a path as an ordered series of points
// - Polygon: Represents an area with outer boundary and optional holes
// - GeometryCollection: Represents a collection of heterogeneous geometries
//
// # Database Setup
//
// Before using this package, ensure your PostgreSQL database has the PostGIS extension enabled:
//
// CREATE EXTENSION IF NOT EXISTS postgis;
//
// # GORM Integration
//
// All geometry types implement the sql.Scanner and driver.Valuer interfaces,
// making them compatible with GORM out of the box:
//
// type Location struct {
// ID uint
// Name string
// Point gogis.Point `gorm:"type:geometry(Point,4326)"`
// Area gogis.Polygon `gorm:"type:geometry(Polygon,4326)"`
// Path gogis.LineString `gorm:"type:geometry(LineString,4326)"`
// }
//
// # Coordinate System
//
// All geometries use SRID 4326 (WGS 84) coordinate system by default.
// Coordinates are stored as longitude (X) and latitude (Y) in decimal degrees.
//
// # Indexing
//
// For optimal performance with spatial queries, create spatial indexes:
//
// CREATE INDEX idx_locations_point ON locations USING GIST (point);
// CREATE INDEX idx_locations_area ON locations USING GIST (area);
//
// # Example Usage
//
// // Create a location
// location := Location{
// Name: "Central Park",
// Point: gogis.Point{
// Lng: -73.965355, // Longitude (X)
// Lat: 40.782865, // Latitude (Y)
// },
// }
//
// // Save to database
// db.Create(&location)
//
// // Query within distance
// var nearby []Location
// db.Where("ST_DWithin(point, ST_Point(?, ?), ?)", -73.965355, 40.782865, 0.01).Find(&nearby)
//
// # Well-Known Binary (WKB) Support
//
// All geometry types can parse and generate Well-Known Binary (WKB) format
// as used by PostGIS, supporting both little-endian and big-endian byte orders.
//
// # Well-Known Text (WKT) Support
//
// All geometry types provide String() methods that generate Well-Known Text (WKT)
// format with SRID specification for use in SQL queries.
package gogis