1

I'm trying to query PostGIS and find some object features that intersect with a circular buffer created by the user using OpenLayers, JavaScript and PHP.

I use the following code for creating the circle:

var circle = OpenLayers.Geometry.Polygon.createRegularPolygon(
    new OpenLayers.Geometry.Point(X, Y),
    1,
    30
);

and then I'm planning to use the following SELECT Query in my php code:

SELECT b.geom
FROM buildings AS b
WHERE ST_WITHIN (b.geom, ST_MAKEPOLYGON(circle, srid));

Q1: how can I pass the geometry created for the circle from my .JS file to .php file? can I pass it as an object? can I do something like below??:

http://mydomain.com/page.php?buffer=circle

Q2: Is my SELECT query correct? Am I using the correct function ST_MAKEPOLYGON?

Any suggestions/help would be highly appreciated.

4

Since your search region is circular, it is perhaps best not to consider it to be a polygon, but as a point with a radius and to use the ST_DWithin() function:

ST_DWithin — Returns true if the geometries are within the specified distance of one another.

It should save you and the processor a lot of effort.

  • Thank you. What about the ST_MAKEPOLYGON function, will it do what I'm looking for? and by the way, do you have any opinion about how to pass the circle to the php code? – Catlover Feb 26 '14 at 12:23
  • I mean, I can imagine that another way could be to use ST_Buffer function. In this way the Where clause for SELECT statement would be something like below: – Catlover Feb 26 '14 at 13:07
  • WHERE ST_DWithin (b.geom, ST_Buffer(ST_MakePoint(lat,long)::geography, radius)); – Catlover Feb 26 '14 at 13:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.