-
Notifications
You must be signed in to change notification settings - Fork 1
/
whosonfirst_alt.go
220 lines (168 loc) · 5.11 KB
/
whosonfirst_alt.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package spr
import (
"fmt"
"github.com/sfomuseum/go-edtf"
"github.com/whosonfirst/go-whosonfirst-feature/geometry"
"github.com/whosonfirst/go-whosonfirst-feature/properties"
"github.com/whosonfirst/go-whosonfirst-flags"
"github.com/whosonfirst/go-whosonfirst-uri"
"strconv"
"strings"
)
// WOFStandardPlacesResult is a struct that implements the `StandardPlacesResult` for
// Who's On First GeoJSON Feature alternate geometry records.
type WOFAltStandardPlacesResult struct {
StandardPlacesResult `json:",omitempty"`
WOFId string `json:"wof:id"`
WOFParentId int64 `json:wof:parent_id"`
WOFName string `json:"wof:name"`
WOFPlacetype string `json:"wof:placetype"`
MZLatitude float64 `json:"mz:latitude"`
MZLongitude float64 `json:"mz:longitude"`
MZMinLatitude float64 `json:"mz:min_latitude"`
MZMinLongitude float64 `json:"mz:min_longitude"`
MZMaxLatitude float64 `json:"mz:max_latitude"`
MZMaxLongitude float64 `json:"mz:max_longitude"`
WOFPath string `json:"wof:path"`
WOFRepo string `json:"wof:repo"`
}
// WhosOnFirstAltSPR will derive a new `WOFStandardPlacesResult` instance from 'f'.
func WhosOnFirstAltSPR(f []byte) (StandardPlacesResult, error) {
id, err := properties.Id(f)
if err != nil {
return nil, fmt.Errorf("Failed to derive ID, %w", err)
}
source, err := properties.Source(f)
if err != nil {
return nil, fmt.Errorf("Failed to derive source, %w", err)
}
name := fmt.Sprintf("%d alt geometry (%s)", id, source)
alt_label, err := properties.AltLabel(f)
if err != nil {
return nil, fmt.Errorf("Failed to derive alt label, %w", err)
}
label_parts := strings.Split(alt_label, "-")
if len(label_parts) == 0 {
return nil, fmt.Errorf("Invalid src:alt_label property")
}
alt_geom := &uri.AltGeom{
Source: label_parts[0],
}
if len(label_parts) >= 2 {
alt_geom.Function = label_parts[1]
}
if len(label_parts) >= 3 {
alt_geom.Extras = label_parts[2:]
}
uri_args := &uri.URIArgs{
IsAlternate: true,
AltGeom: alt_geom,
}
rel_path, err := uri.Id2RelPath(id, uri_args)
if err != nil {
return nil, fmt.Errorf("Failed to derive path for %d, %w", id, err)
}
repo, err := properties.Repo(f)
if err != nil {
return nil, fmt.Errorf("Failed to derive repo, %w", err)
}
geojson_geom, err := geometry.Geometry(f)
if err != nil {
return nil, err
}
orb_geom := geojson_geom.Geometry()
mbr := orb_geom.Bound()
lat := mbr.Min.Y() + ((mbr.Max.Y() - mbr.Min.Y()) / 2.0)
lon := mbr.Min.X() + ((mbr.Max.X() - mbr.Min.X()) / 2.0)
str_id := strconv.FormatInt(id, 10)
spr := WOFAltStandardPlacesResult{
WOFId: str_id,
WOFParentId: -1,
WOFPlacetype: "alt",
WOFName: name,
MZLatitude: lat,
MZLongitude: lon,
MZMinLatitude: mbr.Min.Y(),
MZMinLongitude: mbr.Min.X(),
MZMaxLatitude: mbr.Max.Y(),
MZMaxLongitude: mbr.Max.X(),
WOFPath: rel_path,
WOFRepo: repo,
}
return &spr, nil
}
func (spr *WOFAltStandardPlacesResult) Id() string {
return spr.WOFId
}
func (spr *WOFAltStandardPlacesResult) ParentId() string {
return "-1"
}
func (spr *WOFAltStandardPlacesResult) Name() string {
return spr.WOFName
}
func (spr *WOFAltStandardPlacesResult) Placetype() string {
return spr.WOFPlacetype
}
func (spr *WOFAltStandardPlacesResult) Country() string {
return "XX"
}
func (spr *WOFAltStandardPlacesResult) Repo() string {
return spr.WOFRepo
}
func (spr *WOFAltStandardPlacesResult) Path() string {
return spr.WOFPath
}
func (spr *WOFAltStandardPlacesResult) URI() string {
return ""
}
func (spr *WOFAltStandardPlacesResult) Latitude() float64 {
return spr.MZLatitude
}
func (spr *WOFAltStandardPlacesResult) Longitude() float64 {
return spr.MZLongitude
}
func (spr *WOFAltStandardPlacesResult) MinLatitude() float64 {
return spr.MZMinLatitude
}
func (spr *WOFAltStandardPlacesResult) MinLongitude() float64 {
return spr.MZMinLongitude
}
func (spr *WOFAltStandardPlacesResult) MaxLatitude() float64 {
return spr.MZLatitude
}
func (spr *WOFAltStandardPlacesResult) MaxLongitude() float64 {
return spr.MZMaxLongitude
}
func (spr *WOFAltStandardPlacesResult) Inception() *edtf.EDTFDate {
return nil
}
func (spr *WOFAltStandardPlacesResult) Cessation() *edtf.EDTFDate {
return nil
}
func (spr *WOFAltStandardPlacesResult) IsCurrent() flags.ExistentialFlag {
return existentialFlag(-1)
}
func (spr *WOFAltStandardPlacesResult) IsCeased() flags.ExistentialFlag {
return existentialFlag(-1)
}
func (spr *WOFAltStandardPlacesResult) IsDeprecated() flags.ExistentialFlag {
return existentialFlag(-1)
}
func (spr *WOFAltStandardPlacesResult) IsSuperseded() flags.ExistentialFlag {
return existentialFlag(-1)
}
func (spr *WOFAltStandardPlacesResult) IsSuperseding() flags.ExistentialFlag {
return existentialFlag(-1)
}
func (spr *WOFAltStandardPlacesResult) SupersededBy() []int64 {
return []int64{}
}
func (spr *WOFAltStandardPlacesResult) Supersedes() []int64 {
return []int64{}
}
func (spr *WOFAltStandardPlacesResult) BelongsTo() []int64 {
return []int64{}
}
func (spr *WOFAltStandardPlacesResult) LastModified() int64 {
return -1
}