-
Notifications
You must be signed in to change notification settings - Fork 1
/
countries_map.go
85 lines (78 loc) · 1.44 KB
/
countries_map.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
package main
import (
"database/sql"
"log"
"strings"
_ "github.com/lib/pq"
)
type tmpCountryInfoIDToISO struct {
geonameid string
iso string
}
type tmpShapesAllLow struct {
polygonData string
}
func listOfNeighbours(lst string) []int {
lsta := strings.Split(lst, ",")
result := []int{}
for _, isoName := range lsta {
if _, ok := isoToGeonameID[isoName]; ok {
result = append(result, isoToGeonameID[isoName])
}
}
return result
}
func getCountryPolygon(db *sql.DB, geoname int) string {
rows, err := db.Query(`
SELECT
"polygonData"
FROM "tmp_shapesAllLow"
WHERE "geonameid_1" = $1
`, geoname)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var r tmpShapesAllLow
e := rows.Scan(
&r.polygonData,
)
if e == nil {
return r.polygonData
} else {
log.Fatal(err)
}
}
return ""
}
func getIsoToGeonameID(db *sql.DB) (map[string]int, map[int]string) {
isoToGeonameIDL := make(map[string]int)
geonameIDToISOL := make(map[int]string)
rows, err := db.Query(`
SELECT
"geonameid",
"iso"
FROM "tmp_countryInfo"
WHERE "geonameid" != ''
`)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var r tmpCountryInfoIDToISO
e := rows.Scan(
&r.geonameid,
&r.iso,
)
if e == nil {
id := toInt(r.geonameid)
isoToGeonameIDL[r.iso] = id
geonameIDToISOL[id] = r.iso
} else {
log.Fatal(err)
}
}
return isoToGeonameIDL, geonameIDToISOL
}