0

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?

7

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.

| improve this answer | |

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