vicky
vicky

Reputation: 591

How to find polygons within the radius of GEOGRAPHY (point)

I have a table having all areas with their covered polygons.

area_name, polygon

Now i want to write a query to fetch all the polygons within 60km radius of specific point(lng/lat)

Thanks in advance

Upvotes: 2

Views: 917

Answers (2)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172974

Consider below toy example of looking for all zip codes within the 10km from Los Angeles Disneyland Park

SELECT point, zipcode, ST_GEOGFROMTEXT(zipcode_geom) zip_geom
FROM `bigquery-public-data.utility_us.zipcode_area`,
UNNEST([ST_GEOGPOINT(-117.9190, 33.8121)]) point
WHERE state_code = 'CA'
AND ST_DWITHIN(ST_GEOGFROMTEXT(zipcode_geom), point, 10000)

the output is 36 zip codes like below

enter image description here

if to visualize this result - you get below

enter image description here

Upvotes: 2

Hui Zheng
Hui Zheng

Reputation: 3077

You could use ST_DWITHIN function.


SELECT 
  area_name, 
  polygon
FROM source AS s
WHERE ST_DWITHIN(s.polygon, ST_GEOGPOINT(lng, lat), 60*1000)

Upvotes: 4

Related Questions