本文整理汇总了Golang中github.com/paulsmith/gogeos/geos.Geometry类的典型用法代码示例。如果您正苦于以下问题:Golang Geometry类的具体用法?Golang Geometry怎么用?Golang Geometry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Geometry类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ToGjFeature
func ToGjFeature(g *geos.Geometry) (gjFeature, error) {
var gjf gjFeature
gjf.Type = "Feature"
gjf.Geometry.Type = "MultiPolygon"
ngeoms, _ := g.NGeometry()
gjf.Geometry.Coords = make([][][][]float64, ngeoms)
for i := 0; i < ngeoms; i++ {
subg, err := g.Geometry(i)
if err != nil {
return gjf, err
}
holes, err := subg.Holes()
if err != nil {
return gjf, err
}
gjf.Geometry.Coords[i] = make([][][]float64, 1+len(holes))
shell, err := subg.Shell()
if err != nil {
return gjf, err
}
coords, err := shell.Coords()
if err != nil {
return gjf, err
}
gjf.Geometry.Coords[i][0] = make([][]float64, len(coords))
for j, coord := range coords {
gjf.Geometry.Coords[i][0][j] = make([]float64, 2)
gjf.Geometry.Coords[i][0][j][0] = coord.X
gjf.Geometry.Coords[i][0][j][1] = coord.Y
}
for k, hole := range holes {
coords, err := hole.Coords()
if err != nil {
return gjf, err
}
gjf.Geometry.Coords[i][1+k] = make([][]float64, len(coords))
for j, coord := range coords {
gjf.Geometry.Coords[i][1+k][j] = make([]float64, 2)
gjf.Geometry.Coords[i][1+k][j][0] = coord.X
gjf.Geometry.Coords[i][1+k][j][1] = coord.Y
}
}
}
return gjf, nil
}
示例2: drawPolygon
func drawPolygon(ctxt draw2d.GraphicContext, g *geos.Geometry, fillColor color.Color, strokeColor color.Color, width float64, scale func(x, y float64) (float64, float64)) {
ctxt.SetFillColor(fillColor)
ctxt.SetStrokeColor(strokeColor)
ctxt.SetLineWidth(width)
// exterior ring
ring := geos.Must(g.ExteriorRing())
cs, err := ring.coordSeq()
if err != nil {
log.Fatal(err)
}
lineCoordSeq(ctxt, cs, scale)
ctxt.FillStroke()
// interior rings...
}
示例3: drawLine
func drawLine(ctxt draw2d.GraphicContext, g *geos.Geometry, c color.Color, width float64, scale func(x, y float64) (float64, float64)) {
if c != nil {
ctxt.SetStrokeColor(c)
}
if width != 0.0 {
ctxt.SetLineWidth(width)
}
// XXX: should get a [] of points
cs, err := g.coordSeq()
if err != nil {
log.Fatal(err)
}
lineCoordSeq(ctxt, cs, scale)
ctxt.Stroke()
}
示例4: GetBoundingBox
//GetBoundingBox computes the bounding box for a given geometry
func GetBoundingBox(g *geos.Geometry) (geographic.BoundingBox, error) {
bbox := geographic.BoundingBox{}
envelope, err := g.Envelope()
if err != nil {
return bbox, err
}
envelope, err = envelope.Shell()
if err != nil {
return bbox, err
}
centroid, err := envelope.Centroid()
if err != nil {
return bbox, err
}
bbox.LatitudeMinDeg, _ = centroid.Y()
bbox.LongitudeMinDeg, _ = centroid.X()
bbox.LatitudeMaxDeg = bbox.LatitudeMinDeg
bbox.LongitudeMaxDeg = bbox.LongitudeMinDeg
npoints, err := envelope.NPoint()
if err != nil {
return bbox, err
}
for i := 0; i < npoints; i++ {
pt := geos.Must(envelope.Point(i))
lon, _ := pt.X()
lat, _ := pt.Y()
if lon < bbox.LongitudeMinDeg {
bbox.LongitudeMinDeg = lon
}
if lon > bbox.LongitudeMaxDeg {
bbox.LongitudeMaxDeg = lon
}
if lat < bbox.LatitudeMinDeg {
bbox.LatitudeMinDeg = lat
}
if lat > bbox.LatitudeMaxDeg {
bbox.LatitudeMaxDeg = lat
}
}
return bbox, nil
}
示例5: IntersectsFilter
//IntersectsFilter creates a Filter allowing to skip tiles outside of a given geometry
func IntersectsFilter(g *geos.Geometry) raster.Filter {
//TODO: use a prepared geometry
return func(level, x, y int) (bool, error) {
tile, err := newTilePolygon(level, x, y)
if err != nil {
return false, err
}
intersects, err := g.Intersects(tile)
if err != nil {
return false, err
}
return !intersects, nil //Tiles that do not intersect are excluded
}
}
示例6: drawPoint
func drawPoint(ctxt draw2d.GraphicContext, g *geos.Geometry, c color.Color, radius float64, scale func(x, y float64) (float64, float64)) {
if c != nil {
ctxt.SetFillColor(c)
}
x, err := g.X()
if err != nil {
log.Fatal(err)
}
y, err := g.Y()
if err != nil {
log.Fatal(err)
}
x, y = scale(x, y)
ctxt.MoveTo(x, y)
ctxt.ArcTo(x, y, radius, radius, 0, 2*math.Pi)
ctxt.Fill()
}
示例7: envelope
func envelope(g *geos.Geometry) Envelope {
env, err := g.Envelope()
if err != nil {
log.Fatal(err)
}
ring, err := env.ExteriorRing()
if err != nil {
log.Fatal(err)
}
cs, err := ring.coordSeq()
if err != nil {
log.Fatal(err)
}
getX := getOrd(cs, (*geos.CoordSeq).GetX)
getY := getOrd(cs, (*geos.CoordSeq).GetY)
return Env(getX(0), getY(0), getX(2), getY(2))
}
示例8: RtreeBboxg
// Returns the bounding box of the geos.Geometry as a rtreego.Rect
func RtreeBboxg(g *geos.Geometry, tol float64) (*rtreego.Rect, error) {
env, err := g.Envelope()
if err != nil {
return nil, err
}
shell, _ := env.Shell()
if err != nil {
return nil, err
}
c, err := shell.Coords()
if err != nil {
return nil, err
}
return rtreego.NewRect(rtreego.Point{c[0].X, c[0].Y},
[]float64{math.Max(tol, c[2].X-c[0].X),
math.Max(tol, c[2].Y-c[0].Y)})
}