Skip to main content
edited title; deleted 27 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

If I want to find Finding points 100 miles outside a county, what should I do using PostGIS?

Which way is correct? Use distance or buffer? I am not sure about this.

Here is how I use distance:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_Distance(ST_Transform(tw.location,26986),
               ST_Transform(ce.geom,26986))>=160934 
               AND ce.name10='Alameda'; """)

cursor.fetchall()

and here is how I use buffer:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_within(ST_Transform(tw.location,26986),
               ST_Buffer(ST_Transform(ce.geom,26986), 160934))=false
               AND ce.name10='Alameda'; """)

cursor.fetchall()

The tw.location are points.

Thank you very much!

 

------EDIT------ There There was a small difference in the result and a huge difference in running time. The result from distance was 14818 and the result from buffer was 14899. I don't understand why there was a difference. And, the running time of buffer was much longer. By the way, the total number of the dataset was 100K.

If I want to find points 100 miles outside a county, what should I do?

Which way is correct? Use distance or buffer? I am not sure about this.

Here is how I use distance:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_Distance(ST_Transform(tw.location,26986),
               ST_Transform(ce.geom,26986))>=160934 
               AND ce.name10='Alameda'; """)

cursor.fetchall()

and here is how I use buffer:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_within(ST_Transform(tw.location,26986),
               ST_Buffer(ST_Transform(ce.geom,26986), 160934))=false
               AND ce.name10='Alameda'; """)

cursor.fetchall()

The tw.location are points.

Thank you very much!

------EDIT------ There was a small difference in the result and a huge difference in running time. The result from distance was 14818 and the result from buffer was 14899. I don't understand why there was a difference. And, the running time of buffer was much longer. By the way, the total number of the dataset was 100K.

Finding points 100 miles outside county using PostGIS?

Which way is correct? Use distance or buffer? I am not sure about this.

Here is how I use distance:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_Distance(ST_Transform(tw.location,26986),
               ST_Transform(ce.geom,26986))>=160934 
               AND ce.name10='Alameda'; """)

cursor.fetchall()

and here is how I use buffer:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_within(ST_Transform(tw.location,26986),
               ST_Buffer(ST_Transform(ce.geom,26986), 160934))=false
               AND ce.name10='Alameda'; """)

cursor.fetchall()

The tw.location are points.

 

There was a small difference in the result and a huge difference in running time. The result from distance was 14818 and the result from buffer was 14899. I don't understand why there was a difference. And, the running time of buffer was much longer. By the way, the total number of the dataset was 100K.

added 326 characters in body
Source Link
user3716774
  • 333
  • 1
  • 2
  • 7

Which way is correct? Use distance or buffer? I am not sure about this.

Here is how I use distance:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_Distance(ST_Transform(tw.location,26986),
               ST_Transform(ce.geom,26986))>=160934 
               AND ce.name10='Alameda'; """)

cursor.fetchall()

and here is how I use buffer:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_within(ST_Transform(tw.location,26986),
               ST_Buffer(ST_Transform(ce.geom,26986), 160934))=false
               AND ce.name10='Alameda'; """)

cursor.fetchall()

The tw.location are points.

Thank you very much!

------EDIT------ There was a small difference in the result and a huge difference in running time. The result from distance was 14818 and the result from buffer was 14899. I don't understand why there was a difference. And, the running time of buffer was much longer. By the way, the total number of the dataset was 100K.

Which way is correct? Use distance or buffer? I am not sure about this.

Here is how I use distance:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_Distance(ST_Transform(tw.location,26986),
               ST_Transform(ce.geom,26986))>=160934 
               AND ce.name10='Alameda'; """)

cursor.fetchall()

and here is how I use buffer:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_within(ST_Transform(tw.location,26986),
               ST_Buffer(ST_Transform(ce.geom,26986), 160934))=false
               AND ce.name10='Alameda'; """)

cursor.fetchall()

The tw.location are points.

Thank you very much!

Which way is correct? Use distance or buffer? I am not sure about this.

Here is how I use distance:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_Distance(ST_Transform(tw.location,26986),
               ST_Transform(ce.geom,26986))>=160934 
               AND ce.name10='Alameda'; """)

cursor.fetchall()

and here is how I use buffer:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_within(ST_Transform(tw.location,26986),
               ST_Buffer(ST_Transform(ce.geom,26986), 160934))=false
               AND ce.name10='Alameda'; """)

cursor.fetchall()

The tw.location are points.

Thank you very much!

------EDIT------ There was a small difference in the result and a huge difference in running time. The result from distance was 14818 and the result from buffer was 14899. I don't understand why there was a difference. And, the running time of buffer was much longer. By the way, the total number of the dataset was 100K.

edited body
Source Link
user3716774
  • 333
  • 1
  • 2
  • 7

Which way is correct? Use distance or buffer? I am not sure about this.

Here is how I use distance:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_Distance(ST_Transform(tw.location,26986),
               ST_Transform(ce.geom,26986))>=160934 
               AND ce.name10='Alameda'; """)

cursor.fetchall()

and here is how I use buffer:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_within(ST_Transform(tw.location,26986),
               ST_Buffer(ST_Transform(ce.geom,26986)), 160934))=false
               AND ce.name10='Alameda'; """)

cursor.fetchall()

The tw.location are points.

Thank you very much!

Which way is correct? Use distance or buffer? I am not sure about this.

Here is how I use distance:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_Distance(ST_Transform(tw.location,26986),
               ST_Transform(ce.geom,26986))>=160934 
               AND ce.name10='Alameda'; """)

cursor.fetchall()

and here is how I use buffer:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_within(ST_Transform(tw.location,26986),
               ST_Buffer(ST_Transform(ce.geom,26986)), 160934)
               AND ce.name10='Alameda'; """)

cursor.fetchall()

The tw.location are points.

Thank you very much!

Which way is correct? Use distance or buffer? I am not sure about this.

Here is how I use distance:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_Distance(ST_Transform(tw.location,26986),
               ST_Transform(ce.geom,26986))>=160934 
               AND ce.name10='Alameda'; """)

cursor.fetchall()

and here is how I use buffer:

cursor.execute(""" SELECT COUNT(tw.user_id)
               FROM tweets tw, ca_census_tract ce
               WHERE ST_within(ST_Transform(tw.location,26986),
               ST_Buffer(ST_Transform(ce.geom,26986), 160934))=false
               AND ce.name10='Alameda'; """)

cursor.fetchall()

The tw.location are points.

Thank you very much!

Source Link
user3716774
  • 333
  • 1
  • 2
  • 7
Loading