[postgis-users] CIRCULARSTRING Syntax

Sandro Santilli strk at keybit.net
Mon Aug 19 02:10:47 PDT 2013


On Sun, Aug 18, 2013 at 05:26:50PM -0700, newjim wrote:

> I am trying to make a closed circle. I have my west lat/lng, north lat/lng,
> east lat/lng and south lat/lng but I'm not able to use any combination that
> produces a closed circle such that a call ST_WITHIN will select features.

ST_Within does not work with circles

> For example, my PHP code:
> ST_GeomFromText('SRID=4326;CIRCULARSTRING($westLng $westLat,$northLng
> $northLat, $eastLng $eastLat, $southLng $southLat, $westLng $westLat)')
> ...produces this query:
> Select *        
> FROM nepp_seminar
> WHERE ST_WITHIN(geometry,ST_GeomFromText('SRID=4326;CIRCULARSTRING(-123.1167
> 49.2650,-123.1098 49.2695, -123.1029 49.2650, -123.1098 49.2605, -123.1167
> 49.2650)'))
> ...but generates this message:
> Exception in LWGEOM2GEOS: curved geometry not supported

Exactly, that's where ST_Within does nto support circles...

What you can do is turn your circle into a line with ST_CurveToLine
before passing to ST_Within. By default ST_CurveToLine uses 32 segments
per quadrant (so 128 segments for a full circle) and you can ask it for
more.

You might still get false negative, so slightly enlarge your circle if you
prefer false positives.

By the way, are you really looking for ST_DWithin ?
http://postgis.net/docs/ST_DWithin.html

--strk;


More information about the postgis-users mailing list