Let's say I have a geofence polygon with the following coordinates

POLYGON((-36.861986 174.726745,-36.859241 174.730442,-36.859821 174.730976,-36.862321 174.728156,-36.861986 174.726745))

I'd like to be able to generate another set of polygon points from this that is within a 100 metre radius. Is there any formula to achieve this?

My use case is that if I have an existing geofence polygon, I want to create another geofence polygon surrounding it in a distance of 100 metres.

I'm using the following query to insert data into my table. The columns 'geofence' and 'geofence_buffer' are of type geography. The column with the name 'geography' is of type text. I just use that for a quick reference.

insert into site(name,status,client_id,geofence_type,geography_drawn,geofence,geofence_buffer)
values('Fanshawe','Active',1,1,'POLYGON((-36.849530 174.760984,-36.839295 174.763729,-36.841696 174.779093,-36.854061 174.774291,-36.849530 174.760984))',
      'SRID=4267;POLYGON((-36.849530 174.760984,-36.839295 174.763729,-36.841696 174.779093,-36.854061 174.774291,-36.849530 174.760984))',
      (select ST_Buffer(ST_GeographyFromText('SRID=4267;POLYGON((-36.849530 174.760984,-36.839295 174.763729,-36.841696 174.779093,-36.854061 174.774291,-36.849530 174.760984))'),100)));

Data gets inserted just fine but when I run the following query to find if a point exists within a geofence_buffer, I get the error below.

NOTICE:  Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY
LINE 1: ...ect * from site where ST_DWithin(geofence_buffer, 'SRID=4267...
ERROR:  Operation on mixed SRID geometries
SQL state: XX000

The query I use is

select * from site where ST_DWithin(geofence_buffer, 'SRID=4267;POINT(-36.848362 174.764417)',0.0,false);

However, if I query within a geofence like this, then everything works fine.

select * from site where ST_DWithin(geofence, 'SRID=4267;POINT(-36.848362 174.764417)',0.0,false);
  • 1
    In your query, the second argument to ST_DWithin is a string. It should be a geometry or geography. postgis.net/docs/ST_DWithin.html You also say that geofence is a string, which means that in the final query there, you're doing ST_DWithin(string, string). Unless it does some type conversions, that's meaningless. A string is not a geometry or a geography. – alphabetasoup Jun 19 '19 at 4:00
  • Question already asked and answered stackoverflow.com/questions/56643814/… – JGH Jun 19 '19 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.