/
wfs.go
54 lines (48 loc) · 1.27 KB
/
wfs.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
package main
import (
"fmt"
"net/url"
"strings"
"github.com/golang/geo/s2"
"github.com/paulmach/go.geojson"
)
const DefaultLimit = 10
const MaxLimit = 10000
type WFSLink struct {
Href string `json:"href"`
Rel string `json:"rel"`
Type string `json:"type"`
Title string `json:"title"`
}
type WFSFeatureCollection struct {
Type string `json:"type"`
Links []*WFSLink `json:"links,omitempty"`
BoundingBox []float64 `json:"bbox,omitempty"`
Features []*geojson.Feature `json:"features"`
}
func FormatItemsURL(prefix string, collection string,
startID string, start int, limit int, bbox s2.Rect) string {
params := make([]string, 0, 4)
if len(startID) > 0 {
params = append(params, "startID="+url.QueryEscape(startID))
}
if start > 0 {
params = append(params, fmt.Sprintf("start=%d", start))
}
if limit != DefaultLimit {
params = append(params, fmt.Sprintf("limit=%d", limit))
}
if !bbox.IsFull() {
r := EncodeBbox(bbox)
if r != nil {
boxParam := fmt.Sprintf("bbox=%.7f,%.7f,%.7f,%.7f", r[0], r[1], r[2], r[3])
params = append(params, boxParam)
}
}
u := prefix + "collections/" + url.PathEscape(collection) + "/items"
if len(params) > 0 {
return u + "?" + strings.Join(params, "&")
} else {
return u
}
}