-
Notifications
You must be signed in to change notification settings - Fork 0
/
geojson.go
137 lines (115 loc) · 3.63 KB
/
geojson.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
package main
import (
"strconv"
"log"
"strings"
geojson "github.com/paulmach/go.geojson"
"github.com/tealeg/xlsx"
)
// getGeoJSON takes the excel sheet and converts it to geoJSON struct
func getGeoJSON(xlSheet *xlsx.Sheet) *geojson.FeatureCollection {
featureCollection := geojson.NewFeatureCollection()
for i, row := range xlSheet.Rows {
if i == 0 || row.Cells[0].Value == "" {
continue
}
ex := &Exonym{}
err := row.ReadStruct(ex)
if err != nil {
log.Fatal("Error reading to struct:", err)
}
errMsg := ""
ex.Lat, err = ParseDMS(ex.LatDMS)
if err != nil {
errMsg = errMsg + "; " + err.Error()
}
ex.Lon, err = ParseDMS(ex.LonDMS)
if err != nil {
errMsg = errMsg + "; " + err.Error()
}
//fmt.Println(ex)
// for _, lang := range strings.Split(ex.LangOrig,"/") {
// fmt.Println(lang+",")
//}
f := geojson.NewPointFeature([]float64{ex.Lon, ex.Lat})
f.SetProperty("name", ex.NameOrig)
var nameSlTag string
switch ex.Status {
case "standardiziran", "standardized":
switch strings.ToUpper(ex.RecommendedUse) {
case "A", "B", "C":
nameSlTag = "name:sl"
f.SetProperty(nameSlTag, ex.NameSl)
default:
errMsg = errMsg + "; Invalid recommendedUse " + strconv.Quote(ex.RecommendedUse) + " of standardized exonym"
}
case "nestandardiziran", "non-standardized":
switch strings.ToUpper(ex.RecommendedUse) {
case "A", "B", "C":
nameSlTag = "name:sl"
f.SetProperty(nameSlTag, ex.NameSl)
case "D", "E":
nameSlTag = "alt_name:sl"
if hasValue(ex.NameSlAlt) {
ex.NameSlAlt = ex.NameSl + ";" + ex.NameSlAlt
} else {
ex.NameSlAlt = ex.NameSl
}
f.SetProperty("marker-size", "small")
default:
errMsg = errMsg + "; Unknown recommendedUse " + strconv.Quote(ex.RecommendedUse)
}
default:
errMsg = errMsg + "; Unknown status " + strconv.Quote(ex.Status)
}
f.SetProperty("source:"+nameSlTag, "GIAM")
setFeatureType(f, ex.FeatureType)
if hasValue(ex.NameSlAlt) {
ex.NameSlAlt = strings.ReplaceAll(ex.NameSlAlt, "/", ";")
ex.NameSlAlt = strings.ReplaceAll(ex.NameSlAlt, ", ", ";")
f.SetProperty("alt_name:sl", ex.NameSlAlt)
}
setOptionalProperty(f, "name:en", ex.NameEn)
setOptionalProperty(f, "name:fr", ex.NameFr)
setOptionalProperty(f, "name:de", ex.NameDe)
setOptionalProperty(f, "name:es", ex.NameEs)
setOptionalProperty(f, "name:ru", ex.NameRu)
setOptionalProperty(f, "name:it", ex.NameIt)
setOptionalProperty(f, "name:hr", ex.NameHr)
setOptionalProperty(f, "name:hu", ex.NameHu)
setOptionalProperty(f, "name:etymology:sl", ex.Etymology)
setOptionalProperty(f, "note:sl", ex.Note)
if errMsg != "" {
errMsg = strings.TrimPrefix(errMsg, "; ")
log.Println("ERROR:", ex.NameSl, "-", errMsg)
f.SetProperty("error", errMsg)
f.SetProperty("marker-color", "#ff0000")
}
featureCollection.AddFeature(f)
}
log.Printf("Read %d features.", len(featureCollection.Features))
return featureCollection
}
func setFeatureType(f *geojson.Feature, featureType string) {
f.SetProperty("semantic-type", featureType)
if strings.Contains(featureType, "upravn") {
f.SetProperty("marker-symbol", "circle-stroked")
}
if strings.Contains(featureType, "naselj") {
f.SetProperty("marker-symbol", "city")
}
if strings.Contains(featureType, "zgodovinsk") {
f.SetProperty("marker-color", "#D2B48C")
}
if strings.Contains(featureType, "država") {
f.SetProperty("marker-color", "#D400D4")
f.SetProperty("marker-size", "large")
f.SetProperty("marker-symbol", "embassy")
}
}
func setOptionalProperty(f *geojson.Feature, key string, value string) {
if !hasValue(value) {
return
}
f.SetProperty(key, strings.TrimSpace(value))
}