Skip to main content
Added miles to meters conversion factor.
Source Link
Sean
  • 4.2k
  • 20
  • 24

You don't give any information about your tables. Assuming the point isn't in a table and venues has fields id, radius, geom...

select
   venue.id
from
   venue
where
   st_dwithin(
            st_geographyfromtext( 'POINT(' || venues.longitude || ' ' || venues.latitude || ')'),
            'POINT(0 0)'::geography,
            venues.radius * 1609.344)

This goes through the venues table and

  • reads the point geometry stored for the venue in venues.geom,
  • and tests whether the POINT(0 0) is within venues.radius converted from miles to meters from the venue.

It returns the venue.id if they intersect.

There might be a more elegant way to construct the geography from the long/lat.

I recommend playing with SpatiaLite to learn about the basic geometry operations. It's easier to set up and get going than PostGIS. They have a nice tutorial, too. Most of the functions are the same if only named differently.

You don't give any information about your tables. Assuming the point isn't in a table and venues has fields id, radius, geom...

select
   venue.id
from
   venue
where
   st_dwithin(
            st_geographyfromtext( 'POINT(' || venues.longitude || ' ' || venues.latitude || ')'),
            'POINT(0 0)'::geography,
            venues.radius)

This goes through the venues table and

  • reads the point geometry stored for the venue in venues.geom,
  • and tests whether the POINT(0 0) is within venues.radius meters from the venue.

It returns the venue.id if they intersect.

There might be a more elegant way to construct the geography from the long/lat.

I recommend playing with SpatiaLite to learn about the basic geometry operations. It's easier to set up and get going than PostGIS. They have a nice tutorial, too. Most of the functions are the same if only named differently.

You don't give any information about your tables. Assuming the point isn't in a table and venues has fields id, radius, geom...

select
   venue.id
from
   venue
where
   st_dwithin(
            st_geographyfromtext( 'POINT(' || venues.longitude || ' ' || venues.latitude || ')'),
            'POINT(0 0)'::geography,
            venues.radius * 1609.344)

This goes through the venues table and

  • reads the point geometry stored for the venue in venues.geom,
  • and tests whether the POINT(0 0) is within venues.radius converted from miles to meters from the venue.

It returns the venue.id if they intersect.

There might be a more elegant way to construct the geography from the long/lat.

I recommend playing with SpatiaLite to learn about the basic geometry operations. It's easier to set up and get going than PostGIS. They have a nice tutorial, too. Most of the functions are the same if only named differently.

added 181 characters in body
Source Link
Sean
  • 4.2k
  • 20
  • 24

You don't give any information about your tables. Assuming the point isn't in a table and venues has fields id, radius, geom...

select
   venue.id
from
   venue
where
   st_dwithin(
            st_geographyfromtext( 'POINT(' || venues.geomlongitude || ' ' || venues.latitude || ')'),
            'POINT(0 0)'::geography,
            venues.radius)

This goes through the venues table and

  • reads the point geometry stored for the venue in venues.geom,
  • and tests whether the POINT(0 0) is within venues.radius distancemeters from the venue.

It returns the venue.id if they intersect.

There might be a more elegant way to construct the geography from the long/lat.

I recommend playing with SpatiaLite to learn about the basic geometry operations. It's easier to set up and get going than PostGIS. They have a nice tutorial, too. Most of the functions are the same if only named differently.

You don't give any information about your tables. Assuming the point isn't in a table and venues has fields id, radius, geom...

select
   venue.id
from
   venue
where
   st_dwithin(venues.geom, 'POINT(0 0)', venues.radius)

This goes through the venues table and

  • reads the point geometry stored for the venue in venues.geom,
  • and tests whether the POINT(0 0) is within venues.radius distance from the venue.

It returns the venue.id if they intersect.

I recommend playing with SpatiaLite to learn about the basic geometry operations. It's easier to set up and get going than PostGIS. They have a nice tutorial, too. Most of the functions are the same if only named differently.

You don't give any information about your tables. Assuming the point isn't in a table and venues has fields id, radius, geom...

select
   venue.id
from
   venue
where
   st_dwithin(
            st_geographyfromtext( 'POINT(' || venues.longitude || ' ' || venues.latitude || ')'),
            'POINT(0 0)'::geography,
            venues.radius)

This goes through the venues table and

  • reads the point geometry stored for the venue in venues.geom,
  • and tests whether the POINT(0 0) is within venues.radius meters from the venue.

It returns the venue.id if they intersect.

There might be a more elegant way to construct the geography from the long/lat.

I recommend playing with SpatiaLite to learn about the basic geometry operations. It's easier to set up and get going than PostGIS. They have a nice tutorial, too. Most of the functions are the same if only named differently.

Update. st_dwithin should be mush more efficient. than st_buffer
Source Link
Sean
  • 4.2k
  • 20
  • 24

You don't give any information about your tables. Assuming the point isn't in a table and venues has fields id, radius, geom...

select
   venue.id
from
   venue
where
   st_intersectsst_dwithin(venues.geom, 'POINT(0 0)'::geometry, st_buffer(venu.geom, venuevenues.radius) )

This goes through the venues table and

  • reads the point geometry stored for the venue in venues.geom,
  • draws a circle around that point with the radius stored in venues.radius,
  • and tests whether the POINT(0 0) intersects that circleis within venues.radius distance from the venue.

It returns the venue.id if they intersect.

I recommend playing with SpatiaLite to learn about the basic geometry operations. It's easier to set up and get going than PostGIS. They have a nice tutorial, too. Most of the functions are the same if only named differently.

You don't give any information about your tables. Assuming the point isn't in a table and venues has fields id, radius, geom...

select
   venue.id
from
   venue
where
   st_intersects( 'POINT(0 0)'::geometry, st_buffer(venu.geom, venue.radius) )

This goes through the venues table and

  • reads the point geometry stored for the venue in venues.geom,
  • draws a circle around that point with the radius stored in venues.radius,
  • and tests whether the POINT(0 0) intersects that circle.

It returns the venue.id if they intersect.

I recommend playing with SpatiaLite to learn about the basic geometry operations. It's easier to set up and get going than PostGIS. They have a nice tutorial, too. Most of the functions are the same if only named differently.

You don't give any information about your tables. Assuming the point isn't in a table and venues has fields id, radius, geom...

select
   venue.id
from
   venue
where
   st_dwithin(venues.geom, 'POINT(0 0)', venues.radius)

This goes through the venues table and

  • reads the point geometry stored for the venue in venues.geom,
  • and tests whether the POINT(0 0) is within venues.radius distance from the venue.

It returns the venue.id if they intersect.

I recommend playing with SpatiaLite to learn about the basic geometry operations. It's easier to set up and get going than PostGIS. They have a nice tutorial, too. Most of the functions are the same if only named differently.

added 307 characters in body
Source Link
Sean
  • 4.2k
  • 20
  • 24
Loading
added 307 characters in body
Source Link
Sean
  • 4.2k
  • 20
  • 24
Loading
Source Link
Sean
  • 4.2k
  • 20
  • 24
Loading