Skip to main content
edited tags
Link
geozelot
  • 30.9k
  • 4
  • 34
  • 57
deleted 25 characters in body; edited tags
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I have two tables - first is a list of positions (points) and second is a list of cities (cities). I am using PostGIS and can find all points outside 10nm of New York by using the SQL statement -

SELECT * FROM points, cities 
    WHERE ST_Distance(points.position, cities.geom) > 1 AND cities.city = 'New York'

However, if I want to find all points which are outside both New York and Washington, the query with an AND clause gives zero results..

SELECT * FROM points, cities 
    WHERE (ST_Distance(points.position, cities.geom) > 1 AND cities.city = 'New York') 
      AND (ST_Distance(points.position, cities.geom) > 1 AND cities.city = 'Washington')

PleaseCan you help on constructing an SQL statement which will find all points outside a certain range of multiple cities.?

A solutionI am also using SQLAlchemy would also be welcome.

I have two tables - first is a list of positions (points) and second is a list of cities (cities). I am using PostGIS and can find all points outside 10nm of New York by using the SQL statement -

SELECT * FROM points, cities 
    WHERE ST_Distance(points.position, cities.geom) > 1 AND cities.city = 'New York'

However, if I want to find all points which are outside both New York and Washington, the query with an AND clause gives zero results..

SELECT * FROM points, cities 
    WHERE (ST_Distance(points.position, cities.geom) > 1 AND cities.city = 'New York') 
      AND (ST_Distance(points.position, cities.geom) > 1 AND cities.city = 'Washington')

Please help on constructing an SQL statement which will find all points outside a certain range of multiple cities.

A solution using SQLAlchemy would also be welcome.

I have two tables - first is a list of positions (points) and second is a list of cities (cities). I am using PostGIS and can find all points outside 10nm of New York by using the SQL statement -

SELECT * FROM points, cities 
    WHERE ST_Distance(points.position, cities.geom) > 1 AND cities.city = 'New York'

However, if I want to find all points which are outside both New York and Washington, the query with an AND clause gives zero results..

SELECT * FROM points, cities 
    WHERE (ST_Distance(points.position, cities.geom) > 1 AND cities.city = 'New York') 
      AND (ST_Distance(points.position, cities.geom) > 1 AND cities.city = 'Washington')

Can you help on constructing an SQL statement which will find all points outside a certain range of multiple cities?

I am also using SQLAlchemy.

Tweeted twitter.com/StackGIS/status/1515117823919538178
edited tags
Link
geozelot
  • 30.9k
  • 4
  • 34
  • 57
Became Hot Network Question
Source Link
Loading