[postgis-users] How to get the centroid of an bounding box using st_extent

Charlie Savage cfis at savagexi.com
Tue Sep 18 22:07:06 PDT 2007


Hi Paul,

> Well, clearly there's a bug to be fixed.
> In the meanwhile, since these are just boxes,
> 
> makepoint((minx+maxx)/2, (miny+maxy)/2)

Right, makes sense.  Except I couldn't find an api that actually lets 
you get at the information in the Box2D.

But I just looked again, and in fact there is one I missed:

select xmax(extent('POINT(10 10)'))
select xmin(extent('POINT(10 10)'))

So cool - that will do the trick.  Thanks.

As an aside, its not obvious to me how to actually fix this bug. 
Somehow the conversion from Box2D/Box3D to geometry needs to figure out 
if the bbox has 0 width and/or 0 height and if so create a Point instead 
of a Polygon.  Would a check for xmin=xmax work - it seems dubious since 
these are floating point numbers.  Does the precision stuff in Geos help 
with this somehow (except this is in PostGis not Geos)?  Anyway, just 
curious.  I'll file a bug report.

Thanks,

Charlie


> 
> P.
> 
> On 18-Sep-07, at 8:56 PM, Charlie Savage wrote:
> 
>> It turns out that st_extent is hundreds of times faster than Envelope. 
>> But I run into a problem when using it:
>>
>> select st_extent('POINT(10 10)')
>> "BOX(10 10,10 10)"
>>
>> But if you do this:
>>
>> select asText(centroid(st_extent('POINT(10 10)')))
>> "GEOMETRYCOLLECTION EMPTY"
>>
>>
>> Which is the same issue I mentioned a couple weeks ago where 
>> Envelope('POINT(10 10)') doesn't return a point like it should.
>>
>> So I'd like to use st_extent, but a need a way to get a valid point 
>> that represents the center of the bounds instead of an empty 
>> collection.  How?
>>
>> Charlie
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070918/10e415d8/attachment.bin>


More information about the postgis-users mailing list