query.Query
query.Query()Builder for SQL queries against Soil Data Access.
Unified query builder supporting both regular SQL queries and spatial queries.
Spatial queries can be constructed by chaining spatial filter methods: - intersects_bbox(): Filter by bounding box intersection - contains_point(): Filter by point containment - intersects_geometry(): Filter by geometry intersection using WKT
Examples: # Regular query query = Query().select(“mukey”, “muname”).from_(“mapunit”).where(“areasymbol = ‘IA109’”)
# Spatial query (same Query class!)
query = Query().select("mukey").from_("mupolygon").contains_point(-93.5, 42.5)
Methods
| Name | Description |
|---|---|
| contains_point | Add a point containment filter (spatial query). |
| from_ | Set the FROM clause. |
| from_sql | Create a query from raw SQL. |
| inner_join | Add an INNER JOIN clause. |
| intersects_bbox | Add a bounding box intersection filter (spatial query). |
| intersects_geometry | Add a geometry intersection filter using WKT (spatial query). |
| join | Add a JOIN clause. |
| left_join | Add a LEFT JOIN clause. |
| limit | Set the LIMIT (uses TOP in SQL Server). |
| order_by | Set the ORDER BY clause. |
| select | Set the SELECT clause. |
| to_sql | Build the SQL query string. |
| where | Add a WHERE condition. |
contains_point
query.Query.contains_point(x, y)Add a point containment filter (spatial query).
Args: x: Longitude of the point. y: Latitude of the point.
Returns: Query: This Query instance for method chaining.
from_
query.Query.from_(table)Set the FROM clause.
Args: table: Name of the table to query from.
Returns: Query: This Query instance for method chaining.
from_sql
query.Query.from_sql(sql)Create a query from raw SQL.
Args: sql: Raw SQL query string.
Returns: Query: A new Query instance with the provided SQL.
inner_join
query.Query.inner_join(table, on_condition)Add an INNER JOIN clause.
Args: table: Name of the table to join. on_condition: JOIN condition (ON clause).
Returns: Query: This Query instance for method chaining.
intersects_bbox
query.Query.intersects_bbox(min_x, min_y, max_x, max_y)Add a bounding box intersection filter (spatial query).
Args: min_x: Minimum longitude (west bound). min_y: Minimum latitude (south bound). max_x: Maximum longitude (east bound). max_y: Maximum latitude (north bound).
Returns: Query: This Query instance for method chaining.
intersects_geometry
query.Query.intersects_geometry(wkt)Add a geometry intersection filter using WKT (spatial query).
Args: wkt: Well-Known Text representation of the geometry.
Returns: Query: This Query instance for method chaining.
join
query.Query.join(table, on_condition, join_type='INNER')Add a JOIN clause.
Args: table: Name of the table to join. on_condition: JOIN condition (ON clause). join_type: Type of join (“INNER”, “LEFT”, “RIGHT”, “FULL”).
Returns: Query: This Query instance for method chaining.
left_join
query.Query.left_join(table, on_condition)Add a LEFT JOIN clause.
Args: table: Name of the table to join. on_condition: JOIN condition (ON clause).
Returns: Query: This Query instance for method chaining.
limit
query.Query.limit(count)Set the LIMIT (uses TOP in SQL Server).
Args: count: Maximum number of rows to return.
Returns: Query: This Query instance for method chaining.
order_by
query.Query.order_by(column, direction='ASC')Set the ORDER BY clause.
Args: column: Column name to order by. direction: Sort direction (“ASC” or “DESC”).
Returns: Query: This Query instance for method chaining.
select
query.Query.select(*columns)Set the SELECT clause.
Args: columns: Column names to select. Use “” for all columns.
Returns: Query: This Query instance for method chaining.
to_sql
query.Query.to_sql()Build the SQL query string.
Supports both regular SQL queries and spatial queries with geometry filters.
Returns: str: The complete SQL query string.
where
query.Query.where(condition)Add a WHERE condition.
Args: condition: SQL WHERE condition string.
Returns: Query: This Query instance for method chaining.