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

Martin Davis mbdavis at refractions.net
Wed Sep 19 17:44:30 PDT 2007


Well, I'm slightly embarassed to admit that for the case of an envelope 
for a horizontal or vertical line, JTS actually returns an invalid 
polygon.  (For point envelopes however it does return a Point geometry).

There's a couple of reasons for this.  One is that the OGC SFS seems to 
imply that when returning envelopes as a Geometry, a Polygon should be 
returned.  The other is simply that the original JTS behaviour was to 
always return a Polygon, and when the code was enhanced to return Points 
for zero-area envelopes, the linear case was omitted.

In its defence I'll point out that in my experience working with JTS it 
is *very* rare to need to obtain a Geometry as an envelope.  Usually 
when doing "Envelopey" kinds of things it is much faster, simpler, and 
more robust to simply work with actual Envelope objects. 

Charlie Savage wrote:
> Paul,
>>
>> Hmmm... for an linear envelope would returning a linestring not make 
>> more sense?
>
> That does raise another question.
>
> select astext(envelope('LINESTRING(0 0, 0 10)'))
>
> "POLYGON((0 0,0 10,0 10,0 0,0 0))"
>
> select valid(envelope('LINESTRING(0 0, 0 10)'))
>
> false
>
> Should envelope should do the same?  What does JTS/GEOS do in this case?
>
> Charlie
> ------------------------------------------------------------------------
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>   

-- 
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022




More information about the postgis-users mailing list