简体   繁体   中英

Is it possible to get multipolygon type data as string from spatialite?

sql.Register("sqlite3_with_extensions",
    &sqlite3.SQLiteDriver{
        Extensions: []string{
            "mod_spatialite",
        },
    })

db, err := sql.Open("sqlite3_with_extensions", "./map.gpkg")
if err != nil {
    panic(err.Error())
}

query := "select AsText(geom) from level0"
rows, err := db.Query(query)
if err != nil {
    panic(err.Error())
}

for rows.Next() {
    var s []byte
    rows.Scan(&s)
    fmt.Print(s)
}

First of all, the code I wrote is as above, I want to receive the geom data as text like multipolygon((((......))), but only an empty array is returned.

Below is what the database looks like, data is stored in multipolygon type在此处输入图像描述

Loading this data into golang returns data like the picture below在此处输入图像描述

I want text like multipolygon ((((......))), not datatype like above, but I don't know how to do it,

I have loaded extended spatialite into sqlite3 and loaded data through astext, but an empty array is returned as [], [], []. How can I return the multipolygon text I want? Any help would be appreciated

Try this:

query := "select ST_AsBinary(geom) from level0"
rows, err := db.Query(query)
if err != nil {
    panic(err.Error())
}

for rows.Next() {
    var mp geom.MultiPolygon
    if err := rows.Scan(&mp); err != nil {
         log.Fatal(err)
    }
    fmt.Printf("%+v", mp)
}

geom parser: https://github.com/twpayne/go-geom

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM