Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Golang从坐标列表创建wkb.多边形_Go_Coordinates_Polygon_Wkb - Fatal编程技术网

Golang从坐标列表创建wkb.多边形

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

我有一个文件中的坐标列表,我想得到它们的多边形。我使用wkb library加载坐标,但当我尝试将它们设置到wkb.Polygon对象中时,出现了一个错误:

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 回来 } 打印格式