// Polygon calls the stored procedure 'pg_catalog.polygon(path, box, circle, integer, circle) polygon' on db.
555695
func Polygon(db XODB, v0 pgtypes.Path, v1 pgtypes.Box, v2 pgtypes.Circle, v3 int, v4 pgtypes.Circle) (pgtypes.Polygon, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.polygon($1, $2, $3, $4, $5)`

	// run query
	var ret pgtypes.Polygon
	XOLog(sqlstr, v0, v1, v2, v3, v4)
	err = db.QueryRow(sqlstr, v0, v1, v2, v3, v4).Scan(&ret)
	if err != nil {
		return pgtypes.Polygon{}, err
	}

	return ret, nil
}
1265300
func NewPolygon(coordinates MultiLine) *Polygon {
	if coordinates == nil {
		coordinates = make(MultiLine, 0, INIT_GEOM_CAP)
	}
	return &Polygon{Type: "Polygon", Coordinates: coordinates}
}
827168
func CircleSend(db XODB, v0 pgtypes.Circle) ([]byte, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.circle_send($1)`

	// run query
	var ret []byte
	XOLog(sqlstr, v0)
	err = db.QueryRow(sqlstr, v0).Scan(&ret)
	if err != nil {
		return nil, err
	}

	return ret, nil
}
1163462
func Polygon(p orb.Polygon, z maptile.Zoom) maptile.Set {
	set := make(maptile.Set)
	polygon(set, p, z)

	return set
}
139362
func (p *Polygon) Intersects(o *Polygon) bool {
	// If both polygons have one loop, use the more efficient Loop method.
	// Note that Loop Intersects does its own bounding rectangle check.
	if len(p.loops) == 1 && len(o.loops) == 1 {
		return p.loops[0].Intersects(o.loops[0])
	}

	// Otherwise if neither polygon has holes, we can still use the more
	// efficient Loop.Intersects method. The polygons intersect if and
	// only if some pair of loop regions intersect.
	if !p.bound.Intersects(o.bound) {
		return false
	}

	if !p.hasHoles && !o.hasHoles {
		for _, l := range o.loops {
			if p.anyLoopIntersects(l) {
				return true
			}
		}
		return false
	}

	// Polygon A is disjoint from B if A excludes the entire boundary of B and B
	// excludes all shell boundaries of A. (It can be shown that B must then
	// exclude the entire boundary of A.) The first call below returns false if
	// the boundaries cross, therefore the second call does not need to check
	// for crossing edges.
	return !p.excludesBoundary(o) || !o.excludesNonCrossingShells(p)
}
1151494
func (d *Dataset) Postgres(table string) *Exportable {
	return d.sql(table, typePostgres)
}
898363
func PgLargeobjectMetadatumByOid(db XODB, oid pgtypes.Oid) (*PgLargeobjectMetadatum, error) {
	var err error

	// sql query
	const sqlstr = `SELECT ` +
		`tableoid, cmax, xmax, cmin, xmin, oid, ctid, lomowner, lomacl ` +
		`FROM pg_catalog.pg_largeobject_metadata ` +
		`WHERE oid = $1`

	// run query
	XOLog(sqlstr, oid)
	plm := PgLargeobjectMetadatum{}

	err = db.QueryRow(sqlstr, oid).Scan(&plm.Tableoid, &plm.Cmax, &plm.Xmax, &plm.Cmin, &plm.Xmin, &plm.Oid, &plm.Ctid, &plm.Lomowner, &plm.Lomacl)
	if err != nil {
		return nil, err
	}

	return &plm, nil
}
933358
func MultiPolygon(box orb.Bound, mp orb.MultiPolygon, o orb.Orientation) orb.MultiPolygon {
	if len(mp) == 0 {
		return nil
	}

	// outer rings
	outerRings := make([]orb.Ring, 0, len(mp))
	for _, p := range mp {
		outerRings = append(outerRings, p[0])
	}

	outers, closedOuters := clipRings(box, outerRings)
	if len(outers) == 0 {
		// nothing was clipped
		if len(closedOuters) == 0 {
			return nil // everything outside bound
		}

		return mp // everything inside bound
	}

	// inner rings
	var innerRings []orb.Ring
	for _, p := range mp {
		for _, r := range p[1:] {
			innerRings = append(innerRings, r)
		}
	}

	inners, closedInners := clipRings(box, innerRings)

	// smart wrap everything that touches the edges
	result := smartWrap(box, append(outers, inners...), o)
	for _, o := range closedOuters {
		result = append(result, orb.Polygon{o})
	}

	for _, i := range closedInners {
		result = addToMultiPolygon(result, i)
	}

	return result
}
98127
func (calc *AreaCentroidCalculator) AddPolygon(polygon *geom.Polygon) {
	calc.setBasePoint(polygon.Coord(0))

	calc.addShell(polygon.LinearRing(0).FlatCoords())
	for i := 1; i < polygon.NumLinearRings(); i++ {
		calc.addHole(polygon.LinearRing(i).FlatCoords())
	}
}
969839
func (q *ConvexHullQuery) AddPolygon(p *Polygon) {
	q.bound = q.bound.Union(p.RectBound())
	for _, l := range p.loops {
		// Only loops at depth 0 can contribute to the convex hull.
		if l.depth == 0 {
			q.AddLoop(l)
		}
	}
}
35280
func (t *Polygon) AddGeometry(g interface{}) error {
	switch c := g.(type) {
	case MultiLine:
		t.AddCoordinates(c...)
		break
	case Coordinates:
		t.AddCoordinates(c)
		break
	default:
		return errors.New(fmt.Sprintf("AssertionError %v", g))
	}
	return nil
}
508989
func FullPolygon() *Polygon {
	ret := &Polygon{
		loops: []*Loop{
			FullLoop(),
		},
		numVertices:    len(FullLoop().Vertices()),
		bound:          FullRect(),
		subregionBound: FullRect(),
	}
	ret.initEdgesAndIndex()
	return ret
}
356725
func (p *Polygon) Area() float64 {
	var area float64
	for _, loop := range p.loops {
		area += float64(loop.Sign()) * loop.Area()
	}
	return area
}
1171924
func (s *VisvalingamSimplifier) MultiPolygon(mp orb.MultiPolygon) orb.MultiPolygon {
	return multiPolygon(s, mp)
}
943954
func PgAmopByOid(db XODB, oid pgtypes.Oid) (*PgAmop, error) {
	var err error

	// sql query
	const sqlstr = `SELECT ` +
		`tableoid, cmax, xmax, cmin, xmin, oid, ctid, amopfamily, amoplefttype, amoprighttype, amopstrategy, amoppurpose, amopopr, amopmethod, amopsortfamily ` +
		`FROM pg_catalog.pg_amop ` +
		`WHERE oid = $1`

	// run query
	XOLog(sqlstr, oid)
	pa := PgAmop{}

	err = db.QueryRow(sqlstr, oid).Scan(&pa.Tableoid, &pa.Cmax, &pa.Xmax, &pa.Cmin, &pa.Xmin, &pa.Oid, &pa.Ctid, &pa.Amopfamily, &pa.Amoplefttype, &pa.Amoprighttype, &pa.Amopstrategy, &pa.Amoppurpose, &pa.Amopopr, &pa.Amopmethod, &pa.Amopsortfamily)
	if err != nil {
		return nil, err
	}

	return &pa, nil
}
1280083
func NewPolygonFlat(layout Layout, flatCoords []float64, ends []int) *Polygon {
	g := new(Polygon)
	g.layout = layout
	g.stride = layout.Stride()
	g.flatCoords = flatCoords
	g.ends = ends
	return g
}
589010
func (g *Polygon) Push(lr *LinearRing) error {
	if lr.layout != g.layout {
		return ErrLayoutMismatch{Got: lr.layout, Want: g.layout}
	}
	g.flatCoords = append(g.flatCoords, lr.flatCoords...)
	g.ends = append(g.ends, len(g.flatCoords))
	return nil
}