Documentation
¶
Index ¶
- Constants
- func CalcProjection(line s2.Polyline, point s2.Point) (projected s2.Point, fraction float64, next int)
- func CalcProjectionEuclidean(line s2.Polyline, point s2.Point) (projected s2.Point, fraction float64, next int)
- func ExtractCutUpFrom(polyline s2.Polyline, projected s2.Point, projectedIdx int) (s2.Polyline, s2.Polyline)
- func ExtractCutUpTo(polyline s2.Polyline, projected s2.Point, projectedIdx int) (s2.Polyline, s2.Polyline)
- func GeoJSONToS2PointFeature(pts *geojson.Geometry) (s2.Point, error)
- func GeoJSONToS2PolylineFeature(pts *geojson.Geometry) (*s2.Polyline, error)
- func NewEuclideanS2Point(x, y float64) s2.Point
- func S2PointToGeoJSONFeature(pt *s2.Point) *geojson.Feature
- func S2PolylineToGeoJSONFeature(pts s2.Polyline) *geojson.Feature
- func WKTToS2PointFeature(wkt string) (s2.Point, error)
- func WKTToS2PolylineFeature(wkt string) (*s2.Polyline, error)
- type Edge
- type EuclideanStorage
- func (storage *EuclideanStorage) AddEdge(edgeID uint64, edge *Edge) error
- func (storage *EuclideanStorage) FindInRadius(pt s2.Point, radiusMeters float64) (map[uint64]float64, error)
- func (storage *EuclideanStorage) FindNearest(pt s2.Point, n int) ([]NearestObject, error)
- func (storage *EuclideanStorage) FindNearestInRadius(pt s2.Point, radiusMeters float64, n int) ([]NearestObject, error)
- func (storage *EuclideanStorage) GetEdge(edgeID uint64) *Edge
- type GeoPoint
- type NearestObject
- type S2Storage
- func (storage *S2Storage) AddEdge(edgeID uint64, edge *Edge) error
- func (storage *S2Storage) FindInRadius(pt s2.Point, radiusMeters float64) (map[uint64]float64, error)
- func (storage *S2Storage) FindNearest(pt s2.Point, n int) ([]NearestObject, error)
- func (storage *S2Storage) FindNearestInRadius(pt s2.Point, radiusMeters float64, n int) ([]NearestObject, error)
- func (storage *S2Storage) GetEdge(edgeID uint64) *Edge
- func (storage *S2Storage) NearestNeighborsInRadius(pt s2.Point, radius float64, n int) ([]NearestObject, error)
- func (storage *S2Storage) SearchInRadius(pt s2.Point, radius float64) (map[uint64]float64, error)
- func (storage *S2Storage) SearchInRadiusLonLat(lon, lat float64, radius float64) (map[uint64]float64, error)
- type Storage
- type StorageOption
- type StorageOptions
- type StorageType
- type Vertex
Constants ¶
const (
// EarthRadius Approximate radius of Earth
EarthRadius = 6370986.884258304
)
Variables ¶
This section is empty.
Functions ¶
func CalcProjection ¶
func CalcProjection(line s2.Polyline, point s2.Point) (projected s2.Point, fraction float64, next int)
CalcProjection Returns projection on line and fraction for point (spherical geometry)
line - s2.Polyline point - s2.Point projected - projection of point on line fraction - number in [0;1], describes how far projected point from first point of polyline next - index of the next vertex after the projected point
func CalcProjectionEuclidean ¶
func CalcProjectionEuclidean(line s2.Polyline, point s2.Point) (projected s2.Point, fraction float64, next int)
CalcProjectionEuclidean Returns projection on line and fraction for point (Euclidean/planar geometry)
line - s2.Polyline (using Vector.X/Y as Euclidean coordinates) point - s2.Point (using Vector.X/Y as Euclidean coordinates) projected - projection of point on line fraction - number in [0;1], describes how far projected point from first point of polyline next - index of the next vertex after the projected point
func ExtractCutUpFrom ¶
func ExtractCutUpFrom(polyline s2.Polyline, projected s2.Point, projectedIdx int) (s2.Polyline, s2.Polyline)
ExtractCutUpFrom cuts geometry between neighbor of the projected point index in the polyline and last point
func ExtractCutUpTo ¶
func ExtractCutUpTo(polyline s2.Polyline, projected s2.Point, projectedIdx int) (s2.Polyline, s2.Polyline)
ExtractCutUpTo cuts geometry between very first point and neighbor of the projected point index in the polyline
func GeoJSONToS2PointFeature ¶
GeoJSONToS2PointFeature Returns s2.Point representation of *geojson.Geometry (of Point type)
func GeoJSONToS2PolylineFeature ¶
GeoJSONToS2PolylineFeature Returns *s2.Polyline representation of *geojson.Geometry (of LineString type)
func NewEuclideanS2Point ¶
NewEuclideanS2Point Returns s2.Point with raw Euclidean coordinates (not normalized) Use this when you need s2.Point for EuclideanStorage without GeoPoint wrapper. Note: s2.PointFromCoords normalizes to unit sphere, which would distort Euclidean coordinates.
func S2PointToGeoJSONFeature ¶
S2PointToGeoJSONFeature Returns GeoJSON representation of *s2.Point
func S2PolylineToGeoJSONFeature ¶
S2PolylineToGeoJSONFeature Returns GeoJSON representation of *s2.Polyline
func WKTToS2PointFeature ¶ added in v0.10.0
WKTToS2PointFeature parses WKT POINT and returns s2.Point Expected format: POINT(lon lat)
Types ¶
type Edge ¶
Edge Representation of segment of road (edge in graph)
ID - unique identifier Source - identifier of source vertex Target - identifier of target vertex Weight - cost of moving on edge (usually it is length or time) Polyline - geometry of edge, pointer to s2.Polyline (wrapper)
type EuclideanStorage ¶
type EuclideanStorage struct {
// contains filtered or unexported fields
}
EuclideanStorage Spatial datastore for Euclidean/Cartesian coordinates
func NewEuclideanStorage ¶
func NewEuclideanStorage() *EuclideanStorage
NewEuclideanStorage Returns pointer to created EuclideanStorage
func (*EuclideanStorage) AddEdge ¶
func (storage *EuclideanStorage) AddEdge(edgeID uint64, edge *Edge) error
AddEdge Add edge (polyline) to storage
func (*EuclideanStorage) FindInRadius ¶
func (storage *EuclideanStorage) FindInRadius(pt s2.Point, radiusMeters float64) (map[uint64]float64, error)
FindInRadius implements Storage interface For EuclideanStorage: uses pt.Vector.X/Y as Cartesian coordinates
func (*EuclideanStorage) FindNearest ¶ added in v0.11.0
func (storage *EuclideanStorage) FindNearest(pt s2.Point, n int) ([]NearestObject, error)
FindNearest implements Storage interface using iterative radius expansion For EuclideanStorage: uses pt.Vector.X/Y as Cartesian coordinates
func (*EuclideanStorage) FindNearestInRadius ¶
func (storage *EuclideanStorage) FindNearestInRadius(pt s2.Point, radiusMeters float64, n int) ([]NearestObject, error)
FindNearestInRadius implements Storage interface For EuclideanStorage: uses pt.Vector.X/Y as Cartesian coordinates
func (*EuclideanStorage) GetEdge ¶
func (storage *EuclideanStorage) GetEdge(edgeID uint64) *Edge
GetEdge Returns edge by ID from storage
type GeoPoint ¶
GeoPoint Wrapper around of s2.Point
Needs additional field "srid" to determine what algorithm has to be used to calculate distance between objects SRID = 0, Euclidean distance SRID = 4326 (WGS84), Distance on sphere
func NewEuclideanPoint ¶
NewEuclideanPoint Returns pointer to created GeoPoint with SRID = 0 Uses raw r3.Vector to preserve exact Cartesian coordinates. Note: s2.PointFromCoords normalizes to unit sphere, which would distort Euclidean coordinates.
func NewWGS84Point ¶
NewWGS84Point Returns pointer to created GeoPoint with SRID = 4326
func (*GeoPoint) DistanceTo ¶
DistanceTo Compute distance between two points.
Algorithm of distance calculation depends on SRID. SRID = 0, Euclidean distance SRID = 4326 (WGS84), Distance on sphere
type NearestObject ¶
NearestObject Nearest object to given point
EdgeID - unique identifier DistanceTo - distance to object
type S2Storage ¶
S2Storage Spatial datastore
storageLevel - level for S2 edges - map of edges BTree - b-tree (wraps)
func NewS2Storage ¶
NewS2Storage Returns pointer to created S2Storage
storageLevel - level for S2 degree - degree of b-tree
func (*S2Storage) AddEdge ¶
AddEdge Add edge (polyline) to storage
edgeID - unique identifier edge - edge
func (*S2Storage) FindInRadius ¶
func (storage *S2Storage) FindInRadius(pt s2.Point, radiusMeters float64) (map[uint64]float64, error)
FindInRadius implements Storage interface
func (*S2Storage) FindNearest ¶ added in v0.11.0
FindNearest implements Storage interface using iterative cell expansion. Expands search from center cell outward until n edges are found. Uses incremental frontier expansion to avoid recalculating BFS on each ring.
func (*S2Storage) FindNearestInRadius ¶
func (storage *S2Storage) FindNearestInRadius(pt s2.Point, radiusMeters float64, n int) ([]NearestObject, error)
FindNearestInRadius implements Storage interface
func (*S2Storage) NearestNeighborsInRadius ¶
func (storage *S2Storage) NearestNeighborsInRadius(pt s2.Point, radius float64, n int) ([]NearestObject, error)
NearestNeighborsInRadius Returns edges in radius with max objects restriction (KNN)
pt - s2.Point radius - radius of search n - first N closest edges
func (*S2Storage) SearchInRadius ¶
SearchInRadius Returns edges in radius
pt - s2.Point radius - radius of search
type Storage ¶
type Storage interface {
// AddEdge adds an edge to the storage
AddEdge(edgeID uint64, edge *Edge) error
// GetEdge returns an edge by ID
GetEdge(edgeID uint64) *Edge
// FindInRadius searches for edges within a radius from point
// For spherical: uses s2.Point on unit sphere
// For Euclidean: uses s2.Point.Vector.X/Y as Cartesian coordinates
// Returns map of edge ID to distance
FindInRadius(pt s2.Point, radiusMeters float64) (map[uint64]float64, error)
// FindNearestInRadius returns the N nearest edges within a radius
// For spherical: uses s2.Point on unit sphere
// For Euclidean: uses s2.Point.Vector.X/Y as Cartesian coordinates
FindNearestInRadius(pt s2.Point, radiusMeters float64, n int) ([]NearestObject, error)
// FindNearest returns the N nearest edges using iterative cell expansion
// No radius limit - expands search until N edges are found or maxRings reached
// For spherical: uses s2.Point on unit sphere
// For Euclidean: uses s2.Point.Vector.X/Y as Cartesian coordinates
FindNearest(pt s2.Point, n int) ([]NearestObject, error)
}
Storage is the interface for spatial storage implementations
func NewStorage ¶
func NewStorage(storageType StorageType, opts ...StorageOption) Storage
NewStorage creates a new Storage based on provided options
type StorageOption ¶
type StorageOption func(*StorageOptions)
StorageOption is a functional option for configuring Storage
func WithBTreeDegree ¶
func WithBTreeDegree(degree int) StorageOption
WithBTreeDegree sets the B-tree degree
func WithStorageLevel ¶
func WithStorageLevel(level int) StorageOption
WithStorageLevel sets the S2 cell level for spherical storage
type StorageOptions ¶
type StorageOptions struct {
StorageType StorageType
StorageLevel int // S2 cell level for spherical storage
BTreeDegree int // B-tree degree
}
StorageOptions holds configuration for creating a Storage
type StorageType ¶
type StorageType int
StorageType represents the type of spatial storage
const ( // StorageTypeSpherical uses S2 geometry for WGS84 coordinates (lon/lat) StorageTypeSpherical StorageType = iota // StorageTypeEuclidean uses Euclidean geometry for Cartesian coordinates (future) StorageTypeEuclidean )