Exemple #1
0
func GetXYOnSurface(g Geom) (float64, float64) {
	pt := C.GEOSGetCentroid(g.geom)

	var x C.double
	var y C.double

	coord := C.GEOSGeom_getCoordSeq(pt)

	err := C.GEOSCoordSeq_getX(coord, 0, &x)

	if err == -1 {
		panic(err)
	}

	err = C.GEOSCoordSeq_getY(coord, 0, &y)

	if err == -1 {
		panic(err)
	}

	return float64(x), float64(y)
}
Exemple #2
0
func (this *Geom) Bounds() Bounds {
	geom := C.GEOSEnvelope(this.v)
	if geom == nil {
		return NilBounds
	}
	extRing := C.GEOSGetExteriorRing(geom)
	if extRing == nil {
		return NilBounds
	}
	cs := C.GEOSGeom_getCoordSeq(extRing)
	var csLen C.uint
	C.GEOSCoordSeq_getSize(cs, &csLen)
	minx := 1.e+20
	maxx := -1e+20
	miny := 1.e+20
	maxy := -1e+20
	var temp C.double
	for i := 0; i < int(csLen); i++ {
		C.GEOSCoordSeq_getX(cs, C.uint(i), &temp)
		x := float64(temp)
		if x < minx {
			minx = x
		}
		if x > maxx {
			maxx = x
		}
		C.GEOSCoordSeq_getY(cs, C.uint(i), &temp)
		y := float64(temp)
		if y < miny {
			miny = y
		}
		if y > maxy {
			maxy = y
		}
	}

	return Bounds{minx, miny, maxx, maxy}
}