SQLY Geospatial Queries
π Introduction
Geospatial queries enable querying, filtering, and analyzing location-based data. SQLY supports operations for points, polygons, distances, and spatial joins.
π Filtering by Location
You can filter records based on geographic coordinates.
β Example 1: Find Stores in a Specific City
query:
select: [id, name, location]
from: stores
where:
city: "San Francisco"
This retrieves all stores located in San Francisco.
π Distance-Based Queries
You can find locations within a certain radius of a given point.
β Example 2: Find Restaurants Within 10 km of a Userβs Location
query:
select: [id, name, location]
from: restaurants
where:
location:
within_distance:
point: [37.7749, -122.4194]
distance: 10km
This retrieves all restaurants within 10 km of the given latitude/longitude (San Francisco coordinates).
π Bounding Box Queries
Find records within a rectangular region.
β Example 3: Find Parks Within a Defined Area
query:
select: [id, name, location]
from: parks
where:
location:
within_bbox:
min: [37.70, -122.50]
max: [37.80, -122.40]
This retrieves all parks within the defined latitude/longitude boundaries.
πΊοΈ Spatial Joins
Geospatial joins allow comparing locations between datasets.
β Example 4: Find Customers Near a Store
query:
select: [customers.id, customers.name]
from: customers
join: stores
on:
customers.location:
within_distance:
point: stores.location
distance: 5km
This retrieves customers located within 5 km of any store.
π Summary
- Use
within_distancefor radius-based queries. - Use
within_bboxto filter by rectangular regions. - Spatial joins enable location-based comparisons.