这是一个基于go的基础计算几何库,提供多种空间计算能力 Package go-geo is a general golang libary work for gis, it provide several basic function of spacial calculation.
定义了若干种通用的几何类型 如Point,LineString,Polygon,MultiPoint,MultiLineString,PointZ,LineStringZ等
geojson/ #使用geojson的编解码相关功能
geos/ #支持使用使用c编写的geos库进行更多计算几何方法的扩展(需安装geos库)
wkt/ #使用wkt进行编解码相关功能
test/ #功能测试
//define 3 points
newPoint1 := geo.NewPoint(0, 0)
newPoint2 := geo.NewPoint(0.5, 0.5)
newPoint3 := geo.NewPoint(1, 1)
//define linestring by points
line := geo.NewLineString(*newPoint1, *newPoint2, *newPoint3)
//define a polygon by points
poly1 := geo.NewPolygonFromPois(*newPoint1, *newPoint2, *newPoint3)
//Geometry is interface of all type
geom := Geometry(*poly1)
//convert geom to Polygon
poly1 = geom.(geo.Polygon)
//convert geometry to wkt string
wktStr := wkt.Encode(*poly1))
//transform wkt to geometry
geom,_ := wkt.Decode(wktStr)
//convert geometry to geojson string
fea := geojson.NewFeature(geom)
geojsonStr := MarshalJSON(fea)
// transform geojson to feature
f, err := geojson.UnmarshalFeature([]byte(geojsonStr))
//calculate area
calculation.Area(poly)
空间关系相关,包含、相离、相交等的空间关系判断,基本空间关系使用九交模型 spacial relation,including contain,intesect,etc. based on 9-intersection model
- define standard geometry
- output geometry to wkt,geojson
- provide basic function of spacial calculation
Use go get to install this package. go get -u github.com/hzw456/go-geo
从v1.1.0起,建议使用经纬度坐标时,将x定义为经度,y定义为纬度