-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature.go
79 lines (62 loc) · 2.06 KB
/
feature.go
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
73
74
75
76
77
78
79
package gegography
import "fmt"
// Point describes a set of coordinates
type Point struct {
X float64
Y float64
}
// MultiPoint describes a collection of points
type MultiPoint []Point
// LineString describes a collection of points which together form a line
type LineString []Point
// Polygon describes a collection of point collections which together form a polygon
type Polygon []MultiPoint
// MultiPolygon describes a collection of Polygons
type MultiPolygon []Polygon
// CRSProperties are coordinate reference system properties according to the GeoJSON format specification
type CRSProperties struct {
Name string `json:"name,omitempty"`
Href string `json:"href,omitempty"`
Type string `json:"type,omitempty"`
}
// CRS describes a coordinate reference system according to the GeoJSON format specification
type CRS struct {
Type string `json:"type"`
Properties CRSProperties `json:"properties"`
}
// Feature represents a geographical feature
type Feature struct {
Type string
Properties map[string]interface{}
Coordinates interface{}
}
// FeatureCollection represents a collection of geographical features and accompanying information
type FeatureCollection struct {
Name string
CoordinateReferenceSystem *CRS
Features []Feature
}
// GeoTypeError describes an error involving an unsupported geographical type
type GeoTypeError struct {
Type string
}
func (g GeoTypeError) Error() string {
return fmt.Sprintf("%s: bad or unsupported geographical type.", g.Type)
}
// GeoFormatError describes an error involving badly formatted geographical information
type GeoFormatError struct {
Msg string
}
func (g GeoFormatError) Error() string {
return g.Msg
}
// NewFeatureCollection returns a new blank FeatureCollection with an instantiated feature array
func NewFeatureCollection() FeatureCollection {
fc := FeatureCollection{}
fc.Features = make([]Feature, 0)
return fc
}
// AddFeature adds a feature to a FeatureCollection
func (fc *FeatureCollection) AddFeature(f Feature) {
fc.Features = append(fc.Features, f)
}