第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

GoLang Mongo GeoJSON

GoLang Mongo GeoJSON

Go
慕姐4208626 2022-09-05 10:27:29
在Golang中,使用MongoDB,我試圖存儲GeoJSON對象,同時保留2dsphere索引。我無法聲明可以同時處理“點(diǎn)”和“多邊形”的通用結(jié)構(gòu),因?yàn)椤包c(diǎn)”具有坐標(biāo)字段,而“多邊形”具有坐標(biāo)字段。[]float64[][]float64你對如何聲明這樣的結(jié)構(gòu)有任何想法嗎?
查看完整描述

2 回答

?
jeck貓

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]]}


查看完整回答
反對 回復(fù) 2022-09-05
?
藍(lán)山帝景

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)、 多邊形、 多多邊形 )


查看完整回答
反對 回復(fù) 2022-09-05
  • 2 回答
  • 0 關(guān)注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

<var id="hwhol"></var>