Skip to content

Commit bf7127c

Browse files
committed
add geospatial coordinates
1 parent fb1b846 commit bf7127c

File tree

6 files changed

+98
-67
lines changed

6 files changed

+98
-67
lines changed

go.mod

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@ module github.com/tsirysndr/mada
22

33
go 1.18
44

5+
require (
6+
github.com/blevesearch/bleve/v2 v2.3.2
7+
github.com/everystreet/go-shapefile v1.0.0
8+
github.com/fatih/color v1.13.0
9+
github.com/mattn/go-sqlite3 v2.0.3+incompatible
10+
github.com/mitchellh/go-homedir v1.1.0
11+
github.com/spf13/cobra v1.4.0
12+
github.com/twpayne/go-geom v1.4.1
13+
)
14+
515
require (
616
github.com/RoaringBitmap/roaring v1.1.0 // indirect
717
github.com/bits-and-blooms/bitset v1.2.2 // indirect
8-
github.com/blevesearch/bleve/v2 v2.3.2 // indirect
918
github.com/blevesearch/bleve_index_api v1.0.1 // indirect
1019
github.com/blevesearch/go-porterstemmer v1.0.3 // indirect
1120
github.com/blevesearch/gtreap v0.1.1 // indirect
@@ -22,8 +31,6 @@ require (
2231
github.com/blevesearch/zapx/v15 v15.3.3 // indirect
2332
github.com/everystreet/go-geojson v1.1.1 // indirect
2433
github.com/everystreet/go-geojson/v2 v2.0.2 // indirect
25-
github.com/everystreet/go-shapefile v1.0.0 // indirect
26-
github.com/fatih/color v1.13.0 // indirect
2734
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect
2835
github.com/golang/protobuf v1.5.2 // indirect
2936
github.com/golang/snappy v0.0.4 // indirect
@@ -33,22 +40,18 @@ require (
3340
github.com/mattn/go-colorable v0.1.12 // indirect
3441
github.com/mattn/go-isatty v0.0.14 // indirect
3542
github.com/mattn/go-runewidth v0.0.13 // indirect
36-
github.com/mattn/go-sqlite3 v1.14.13 // indirect
37-
github.com/mitchellh/go-homedir v1.1.0 // indirect
3843
github.com/mschoch/smat v0.2.0 // indirect
3944
github.com/nats-io/nats.go v1.15.0 // indirect
4045
github.com/nats-io/nkeys v0.3.0 // indirect
4146
github.com/nats-io/nuid v1.0.1 // indirect
4247
github.com/olekukonko/tablewriter v0.0.5 // indirect
4348
github.com/rivo/uniseg v0.2.0 // indirect
44-
github.com/spf13/cobra v1.4.0 // indirect
4549
github.com/spf13/pflag v1.0.5 // indirect
46-
github.com/twpayne/go-geom v1.4.1 // indirect
4750
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
4851
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
4952
go.etcd.io/bbolt v1.3.6 // indirect
5053
golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898 // indirect
51-
golang.org/x/net v0.0.0-20220524220425-1d687d428aca // indirect
54+
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 // indirect
5255
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
5356
golang.org/x/text v0.3.7 // indirect
5457
google.golang.org/protobuf v1.28.0 // indirect

go.sum

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ github.com/huandu/xstrings v1.3.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq
9999
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
100100
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
101101
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
102-
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
103102
github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
104103
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
105104
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -112,7 +111,6 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
112111
github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
113112
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
114113
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
115-
github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs=
116114
github.com/lib/pq v1.10.6/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
117115
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
118116
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
@@ -126,20 +124,17 @@ github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRC
126124
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
127125
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
128126
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
129-
github.com/mattn/go-sqlite3 v1.14.13 h1:1tj15ngiFfcZzii7yd82foL+ks+ouQcj8j/TPq3fk1I=
130-
github.com/mattn/go-sqlite3 v1.14.13/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
127+
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
128+
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
131129
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
132130
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
133131
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
134132
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
135133
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
136134
github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
137135
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
138-
github.com/nats-io/nats.go v1.15.0 h1:3IXNBolWrwIUf2soxh6Rla8gPzYWEZQBUBK6RV21s+o=
139136
github.com/nats-io/nats.go v1.15.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
140-
github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
141137
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
142-
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
143138
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
144139
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
145140
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
@@ -186,9 +181,7 @@ github.com/twpayne/go-kml v1.5.2/go.mod h1:kz8jAiIz6FIdU2Zjce9qGlVtgFYES9vt7BTPB
186181
github.com/twpayne/go-polyline v1.0.0/go.mod h1:ICh24bcLYBX8CknfvNPKqoTbe+eg+MX1NPyJmSBo7pU=
187182
github.com/twpayne/go-waypoint v0.0.0-20200706203930-b263a7f6e4e8/go.mod h1:qj5pHncxKhu9gxtZEYWypA/z097sxhFlbTyOyt9gcnU=
188183
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
189-
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
190184
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
191-
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
192185
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
193186
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
194187
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
@@ -198,16 +191,15 @@ golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnf
198191
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
199192
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
200193
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
201-
golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898 h1:SLP7Q4Di66FONjDJbCYrCRrh97focO6sLogHO7/g8F0=
202194
golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
203195
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
204196
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
205197
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
206198
golang.org/x/net v0.0.0-20191003171128-d98b1b443823/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
207199
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
208200
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
209-
golang.org/x/net v0.0.0-20220524220425-1d687d428aca h1:xTaFYiPROfpPhqrfTIDXj0ri1SpfueYT951s4bAuDO8=
210-
golang.org/x/net v0.0.0-20220524220425-1d687d428aca/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
201+
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 h1:lUkvobShwKsOesNfWWlCS5q7fnbG1MEliIzwu886fn8=
202+
golang.org/x/net v0.0.0-20220526153639-5463443f8c37/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
211203
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
212204
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
213205
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

mada/commune.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ import (
66
"fmt"
77

88
"github.com/blevesearch/bleve/v2"
9+
"github.com/twpayne/go-geom"
10+
"github.com/twpayne/go-geom/encoding/wkt"
911
)
1012

1113
type Commune struct {
12-
ID string `json:"id"`
13-
Name string `json:"name"`
14-
Region string `json:"region"`
15-
District string `json:"district"`
16-
Country string `json:"country"`
14+
ID string `json:"id"`
15+
Name string `json:"name"`
16+
Region string `json:"region"`
17+
District string `json:"district"`
18+
Country string `json:"country"`
19+
Coordinates [][]geom.Coord `json:"coordinates"`
1720
}
1821

1922
type CommuneService struct {
@@ -57,19 +60,22 @@ func (c *CommuneService) List(outputInJSON bool, limit int) {
5760
}
5861

5962
func (c *CommuneService) ShowCommune(id string, outputInJSON bool) {
60-
rows, _ := c.db.Query("SELECT uid, name, region, district, country FROM commune WHERE uid = ?", id)
63+
rows, _ := c.db.Query("SELECT uid, name, region, district, country, ST_AsText(geom) FROM commune WHERE uid = ?", id)
6164
defer rows.Close()
62-
var uid, name, region, district, country string
65+
var uid, name, region, district, country, g string
6366
rows.Next()
64-
rows.Scan(&uid, &name, &region, &district, &country)
67+
rows.Scan(&uid, &name, &region, &district, &country, &g)
68+
69+
p, _ := wkt.Unmarshal(g)
6570

6671
if outputInJSON {
6772
b, _ := json.MarshalIndent(Commune{
68-
ID: uid,
69-
Name: name,
70-
Region: region,
71-
District: district,
72-
Country: country,
73+
ID: uid,
74+
Name: name,
75+
Region: region,
76+
District: district,
77+
Country: country,
78+
Coordinates: p.(*geom.Polygon).Coords(),
7379
}, "", " ")
7480

7581
fmt.Println(string(b))
@@ -90,5 +96,7 @@ func (c *CommuneService) ShowCommune(id string, outputInJSON bool) {
9096
commune
9197
country
9298
Madagascar
93-
`, uid, name, district, region)
99+
geometry
100+
%v
101+
`, uid, name, district, region, p.(*geom.Polygon).Coords())
94102
}

mada/district.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import (
66
"fmt"
77

88
"github.com/blevesearch/bleve/v2"
9+
"github.com/twpayne/go-geom"
10+
"github.com/twpayne/go-geom/encoding/wkt"
911
)
1012

1113
type District struct {
12-
ID string `json:"id"`
13-
Name string `json:"name"`
14-
Region string `json:"region"`
15-
Country string `json:"country"`
14+
ID string `json:"id"`
15+
Name string `json:"name"`
16+
Region string `json:"region"`
17+
Country string `json:"country"`
18+
Coordinates [][]geom.Coord `json:"coordinates"`
1619
}
1720

1821
type DistrictService struct {
@@ -56,14 +59,22 @@ func (d *DistrictService) List(outputInJSON bool, limit int) {
5659
}
5760

5861
func (d *DistrictService) ShowDistrict(id string, outputInJSON bool) {
59-
rows, _ := d.db.Query("SELECT uid, name, region FROM district WHERE uid = ?", id)
62+
rows, _ := d.db.Query("SELECT uid, name, region, ST_AsText(geom) FROM district WHERE uid = ?", id)
6063
defer rows.Close()
61-
var uid, name, region string
64+
var uid, name, region, g string
6265
rows.Next()
63-
rows.Scan(&uid, &name, &region)
66+
rows.Scan(&uid, &name, &region, &g)
67+
68+
p, _ := wkt.Unmarshal(g)
6469

6570
if outputInJSON {
66-
b, _ := json.MarshalIndent(District{ID: uid, Name: name, Region: region, Country: "Madagascar"}, "", " ")
71+
b, _ := json.MarshalIndent(District{
72+
ID: uid,
73+
Name: name,
74+
Region: region,
75+
Country: "Madagascar",
76+
Coordinates: p.(*geom.Polygon).Coords(),
77+
}, "", " ")
6778
fmt.Println(string(b))
6879
return
6980
}
@@ -80,5 +91,7 @@ func (d *DistrictService) ShowDistrict(id string, outputInJSON bool) {
8091
district
8192
country
8293
Madagascar
83-
`, uid, name, region)
94+
geometry
95+
%v
96+
`, uid, name, region, p.(*geom.Polygon).Coords())
8497
}

mada/fokontany.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ import (
66
"fmt"
77

88
"github.com/blevesearch/bleve/v2"
9+
"github.com/twpayne/go-geom"
10+
"github.com/twpayne/go-geom/encoding/wkt"
911
)
1012

1113
type Fokontany struct {
12-
ID string `json:"id"`
13-
Name string `json:"name"`
14-
Commune string `json:"commune"`
15-
Region string `json:"region"`
16-
District string `json:"district"`
17-
Country string `json:"country"`
14+
ID string `json:"id"`
15+
Name string `json:"name"`
16+
Commune string `json:"commune"`
17+
Region string `json:"region"`
18+
District string `json:"district"`
19+
Country string `json:"country"`
20+
Coordinates [][]geom.Coord `json:"coordinates"`
1821
}
1922

2023
type FokontanyService struct {
@@ -58,20 +61,23 @@ func (f *FokontanyService) List(outputInJSON bool, limit int) {
5861
}
5962

6063
func (f *FokontanyService) ShowFokontany(id string, outputInJSON bool) {
61-
rows, _ := f.db.Query("SELECT uid, name, commune, region, district, country FROM fokontany WHERE uid = ?", id)
64+
rows, _ := f.db.Query("SELECT uid, name, commune, region, district, country, ST_AsText(geom) FROM fokontany WHERE uid = ?", id)
6265
defer rows.Close()
63-
var uid, name, commune, district, region, country string
66+
var uid, name, commune, district, region, country, g string
6467
rows.Next()
65-
rows.Scan(&uid, &name, &commune, &region, &district, &country)
68+
rows.Scan(&uid, &name, &commune, &region, &district, &country, &g)
69+
70+
p, _ := wkt.Unmarshal(g)
6671

6772
if outputInJSON {
6873
b, _ := json.MarshalIndent(Fokontany{
69-
ID: uid,
70-
Name: name,
71-
Commune: commune,
72-
Region: region,
73-
District: district,
74-
Country: country,
74+
ID: uid,
75+
Name: name,
76+
Commune: commune,
77+
Region: region,
78+
District: district,
79+
Country: country,
80+
Coordinates: p.(*geom.Polygon).Coords(),
7581
}, "", " ")
7682
fmt.Println(string(b))
7783
return
@@ -93,5 +99,7 @@ func (f *FokontanyService) ShowFokontany(id string, outputInJSON bool) {
9399
fokontany
94100
country
95101
Madagascar
96-
`, uid, name, commune, region, district, country)
102+
geometry
103+
%v
104+
`, uid, name, commune, region, district, country, p.(*geom.Polygon).Coords())
97105
}

mada/region.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import (
66
"fmt"
77

88
"github.com/blevesearch/bleve/v2"
9+
"github.com/twpayne/go-geom"
10+
"github.com/twpayne/go-geom/encoding/wkt"
911
)
1012

1113
type Region struct {
12-
ID string `json:"id"`
13-
Name string `json:"name"`
14-
Country string `json:"country"`
14+
ID string `json:"id"`
15+
Name string `json:"name"`
16+
Country string `json:"country"`
17+
Coordinates [][]geom.Coord `json:"coordinates"`
1518
}
1619

1720
type RegionService struct {
@@ -55,14 +58,16 @@ func (r *RegionService) List(outputInJSON bool, limit int) {
5558
}
5659

5760
func (r *RegionService) ShowRegion(id string, outputInJSON bool) {
58-
rows, _ := r.db.Query("SELECT uid, name FROM region WHERE uid = ?", id)
61+
rows, _ := r.db.Query("SELECT uid, name, ST_AsText(geom) FROM region WHERE uid = ?", id)
5962
defer rows.Close()
60-
var uid, name string
63+
var uid, name, g string
6164
rows.Next()
62-
rows.Scan(&uid, &name)
65+
rows.Scan(&uid, &name, &g)
66+
67+
p, _ := wkt.Unmarshal(g)
6368

6469
if outputInJSON {
65-
b, _ := json.MarshalIndent(Region{ID: uid, Name: name, Country: "Madagascar"}, "", " ")
70+
b, _ := json.MarshalIndent(Region{ID: uid, Name: name, Country: "Madagascar", Coordinates: p.(*geom.Polygon).Coords()}, "", " ")
6671
fmt.Println(string(b))
6772
return
6873
}
@@ -76,5 +81,7 @@ func (r *RegionService) ShowRegion(id string, outputInJSON bool) {
7681
region
7782
country
7883
Madagascar
79-
`, uid, name)
84+
geometry
85+
%v
86+
`, uid, name, p.(*geom.Polygon).Coords())
8087
}

0 commit comments

Comments
 (0)