// Return the geometry as a GeoJSON element
541050
func AsGeoJSON(c aspect.ColumnElem) aspect.ColumnElem {
	return c.SetInner(
		aspect.FuncClause{Inner: c.Inner(), F: "ST_AsGeoJSON"},
	)
}
516319
func (e *wktEncoder) encode(g *Geometry) (string, error) {
	cstr := cGEOSWKTWriter_write(e.w, g.g)
	if cstr == nil {
		return "", Error()
	}
	return C.GoString(cstr), nil
}
121331
func (g *Geometry) Coords() ([]Coord, error) {
	ptr := cGEOSGeom_getCoordSeq(g.g)
	if ptr == nil {
		return nil, Error()
	}
	//cs := coordSeqFromPtr(ptr)
	cs := &coordSeq{c: ptr}
	return coordSlice(cs)
}
599213
func (g *Geometry) Snap(other *Geometry, tolerance float64) (*Geometry, error) {
	return geomFromC("Snap", cGEOSSnap(g.g, other.g, C.double(tolerance)))
}
548090
func (ps PointSet) ToGeoJSON() *geojson.Feature {
	f := geojson.NewMultiPointFeature()
	for _, v := range ps {
		f.Geometry.MultiPoint = append(f.Geometry.MultiPoint, []float64{v[0], v[1]})
	}

	return f
}
1297045
func (polygon Polygon) String() string {
	var result string
	if bytes, err := json.Marshal(polygon); err == nil {
		result = string(bytes)
	} else {
		result = err.Error()
	}
	return result
}
737240
func (t *GeometryCollection) AddGeometries(g ...interface{}) {
	t.Geometries = append(t.Geometries, g...)
}
1160012
func EncodeGeometryCollection(g *geom.GeometryCollection) (kml.Element, error) {
	geometries := make([]kml.Element, g.NumGeoms())
	for i, g := range g.Geoms() {
		var err error
		geometries[i], err = Encode(g)
		if err != nil {
			return nil, err
		}
	}
	return kml.MultiGeometry(geometries...), nil
}
781729
func (bb BoundingBox) Geometry() interface{} {
	var result interface{}
	switch len(bb) {
	case 4:
		if (bb[0] == bb[2]) && (bb[1] == bb[3]) {
			result = NewPoint(bb[0:2])
		} else {
			coordinates := make([][][]float64, 1)
			coordinates[0] = make([][]float64, 5)
			coordinates[0][0] = make([]float64, 2)
			coordinates[0][0][0] = bb[0]
			coordinates[0][0][1] = bb[1]
			coordinates[0][1] = make([]float64, 2)
			coordinates[0][1][0] = bb[2]
			coordinates[0][1][1] = bb[1]
			coordinates[0][2] = make([]float64, 2)
			coordinates[0][2][0] = bb[2]
			coordinates[0][2][1] = bb[3]
			coordinates[0][3] = make([]float64, 2)
			coordinates[0][3][0] = bb[0]
			coordinates[0][3][1] = bb[3]
			coordinates[0][4] = make([]float64, 2)
			coordinates[0][4][0] = bb[0]
			coordinates[0][4][1] = bb[1]
			result = NewPolygon(coordinates)
		}
	}
	return result
}
643522
func (p *Pattern) geoXes() {
	squareSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 10, 25)
	xShape := shapes.BuildPlus(squareSize)
	xSize := squareSize * 3 * 0.943

	p.Svg.SetHeight(int(xSize * 3))
	p.Svg.SetWidth(int(xSize * 3))

	i := 0
	for y := 0; y <= 5; y++ {
		for x := 0; x <= 5; x++ {

			val := utils.HexVal(p.Hash, i, 1)
			opacity := utils.Opacity(val)
			fill := utils.FillColor(val)

			var dy float64
			if x%2 == 0 {
				dy = float64(y)*xSize - xSize*0.5
			} else {
				dy = float64(y)*xSize - xSize*0.5 + xSize/4
			}

			styles := make(map[string]interface{})
			styles["fill"] = fill
			styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity)}

			style := make(map[string]interface{})

			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", float64(x)*xSize/2-xSize/2, dy-float64(y)*xSize/2, xSize/2, xSize/2)
			p.Svg.Group(xShape, utils.Merge(styles, style))

			if x == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", 6*xSize/2-xSize/2, dy-float64(y)*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			if y == 0 {
				if x%2 == 0 {
					dy = 6*xSize - xSize/2
				} else {
					dy = 6*xSize - xSize/2 + xSize/4
				}

				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", float64(x)*xSize/2-xSize/2, dy-float64(y)*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			if y == 5 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", float64(x)*xSize/2-xSize/2, dy-11*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			if x == 0 && y == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", 6*xSize/2-xSize/2, dy-6*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			i = i + 1
		}
	}
}
1656
func (w *Window) Geometry() (xrect.Rect, error) {
	geom, err := RawGeometry(w.X, xproto.Drawable(w.Id))
	if err != nil {
		return nil, err
	}
	w.Geom = geom
	return geom, err
}
1003693
func (mp *MultiPoint) UnmarshalJSON(data []byte) error {
	g := &Geometry{}
	err := json.Unmarshal(data, &g)
	if err != nil {
		return err
	}

	multiPoint, ok := g.Coordinates.(orb.MultiPoint)
	if !ok {
		return errors.New("geojson: not a MultiPoint type")
	}

	*mp = MultiPoint(multiPoint)
	return nil
}
404932
func Marshal(geom orb.Geometry, byteOrder ...binary.ByteOrder) ([]byte, error) {

	buf := bytes.NewBuffer(make([]byte, 0, geomLength(geom)))

	e := NewEncoder(buf)
	if len(byteOrder) > 0 {
		e.SetByteOrder(byteOrder[0])
	}

	err := e.Encode(geom)
	if err != nil {
		return nil, err
	}

	if buf.Len() == 0 {
		return nil, nil
	}

	return buf.Bytes(), nil
}
985619
func Polygon(b orb.Bound, p orb.Polygon) orb.Polygon {
	if len(p) == 0 {
		return nil
	}

	r := Ring(b, p[0])
	if r == nil {
		return nil
	}

	result := orb.Polygon{r}
	for i := 1; i < len(p); i++ {
		r := Ring(b, p[i])
		if r != nil {
			result = append(result, r)
		}
	}

	return result
}
933246
func geomLength(geom orb.Geometry) int {
	switch g := geom.(type) {
	case orb.Point:
		return 21
	case orb.MultiPoint:
		return 9 + 21*len(g)
	case orb.LineString:
		return 9 + 16*len(g)
	case orb.MultiLineString:
		sum := 0
		for _, ls := range g {
			sum += 9 + 16*len(ls)
		}

		return 9 + sum
	case orb.Polygon:
		sum := 0
		for _, r := range g {
			sum += 4 + 16*len(r)
		}

		return 9 + sum
	case orb.MultiPolygon:
		sum := 0
		for _, c := range g {
			sum += geomLength(c)
		}

		return 9 + sum
	case orb.Collection:
		sum := 0
		for _, c := range g {
			sum += geomLength(c)
		}

		return 9 + sum
	}

	return 0
}
216479
func (g *Geometry) ToWKT() (string, error) {
	encoder := newWktEncoder()
	return encoder.encode(g)
}
1039730
func (grng GeometricGenerator) Geometric(p float64) int64 {
	if !(0.0 <= p && p <= 1.0) {
		panic(fmt.Sprintf("Invalid probability p: %.2f", p))
	}
	return grng.geometric(p)
}