Golang从坐标列表创建wkb.多边形
我有一个文件中的坐标列表,我想得到它们的多边形。我使用wkb library加载坐标,但当我尝试将它们设置到wkb.Polygon对象中时,出现了一个错误:Golang从坐标列表创建wkb.多边形,go,coordinates,polygon,wkb,Go,Coordinates,Polygon,Wkb,我有一个文件中的坐标列表,我想得到它们的多边形。我使用wkb library加载坐标,但当我尝试将它们设置到wkb.Polygon对象中时,出现了一个错误: panic: interface conversion: interface {} is [][][]float64, not [][]geom.Coord 这是我的代码: var cc interface {} = collection.Features[0].Geometry.Polygon c := cc.([][]geom.Coo
panic: interface conversion: interface {} is [][][]float64, not [][]geom.Coord
这是我的代码:
var cc interface {} = collection.Features[0].Geometry.Polygon
c := cc.([][]geom.Coord)
po, err := wkb.Polygon{}.SetCoords(c)
我还尝试:
c := collection.Features[0].Geometry.Polygon.([][]geom.Coord)
但我得到了:
Invalid type assertion: collection.Features[0].Geometry.Polygon.([][]geom.Coord) (non-interface type [][][]float64 on left)
首先,您需要创建一个通用多边形,如下所示: 包干管 进口 fmt github.com/twpayne/go-geom func main{ unitSquare:=geom.NewPolygongeom.XY.MustSetCoords[]geom.Coords{ {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}, } fmt.PrintfunitSquare.Area==%f,unitSquare.Area } 然后可以将其封送为wkb格式 //与litten endian一起进入wkb b、 错误:=wkb.marshallUnitSquare,wkb.NDR 如果出错!=零{ fmt.Printfwkb封送处理错误:%s\n,错误.error 回来 } 打印格式
首先,您需要创建一个通用多边形,如下所示: 包干管 进口 fmt github.com/twpayne/go-geom func main{ unitSquare:=geom.NewPolygongeom.XY.MustSetCoords[]geom.Coords{ {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}, } fmt.PrintfunitSquare.Area==%f,unitSquare.Area } 然后可以将其封送为wkb格式 //与litten endian一起进入wkb b、 错误:=wkb.marshallUnitSquare,wkb.NDR 如果出错!=零{ fmt.Printfwkb封送处理错误:%s\n,错误.error 回来 } 打印格式