2 回答

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個贊
您可以嘗試在結(jié)構(gòu)和結(jié)構(gòu)中用作字段。我為您的方案創(chuàng)建了一個簡單的程序,如下所示:interfacepolygonpoint
package main
import (
"fmt"
)
type figure struct {
name string
coordinates interface{}
}
func main() {
Point := figure{"Point", [2]float64{2.0, 7.88}}
Polygon := figure{"Polygon", [2][2]float64{{2.0, 7.88}, {3.0, 7.88}}}
fmt.Println(Point)
fmt.Println(Polygon)
}
輸出:
{Point [2 7.88]}
{Polygon [[2 7.88] [3 7.88]]}

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個贊
首先,Ghoper的答案是100%正確的。的加入對我?guī)椭艽蟆τ趯碓L問此處的任何人,這是我的GeoJson要素集合結(jié)構(gòu)布局,以供參考:Coordinates interface{}
// Feature Collection
type FeatureCollection struct {
ID string `json:"_id,omitempty" bson:"_id,omitempty"`
Features []Feature `json:"features" bson:"features"`
Type string `json:"type" bson:"type"`
}
// Individual Feature
type Feature struct {
Type string `json:"type" bson:"type"`
Properties Properties `json:"properties" bson:"properties"`
Geometry Geometry `json:"geometry" bson:"geometry"`
}
// Feature Properties
type Properties struct {
Name string `json:"name" bson:"name"`
Height uint64 `json:"height" bson:"height"`
Purchased bool `json:"purchased" bson:"purchased"`
LastUpdated string `json:"last_updated" bson:"last_updated"`
}
// Feature Geometry
type Geometry struct {
Type string `json:"type" bson:"type"`
Coordinates interface{} `json:"coordinates" bson:"coordinates"`
}
適用于所有 GeoJson 類型 ( 線串、 點(diǎn)、 多邊形、 多多邊形 )
- 2 回答
- 0 關(guān)注
- 162 瀏覽
添加回答
舉報(bào)