[Fwd: [Fwd: Re: [postgis-devel] Re: Patch for PostGis Envelope Bug]]

Charlie Savage cfis at savagexi.com
Fri Sep 21 21:46:48 PDT 2007


Ok - here is take #2.  This hopefully is much better - I should have 
done it this way to start.

Note that the 3 methods are now almost 100% identical (LWGEOM_envelope, 
BOX2DFLOAT4_to_LWGEOM, BOX3D_to_LWGEOM).  The only difference between 
them is how to get the bounding box (1 line of code at the top of each 
method) and then for envelope to set the SRID.  It would make sense to 
have just 1 method that does most of the work, and have the original 3 
wrap it.  Would you convert Box3d to Box2dfloat or the other way around?

Anyway, here are the examples again, plus a few more.  See how they look.


select asText(envelope('POINT(10 10)'::geometry)) AS G1,
        asText(envelope('MULTIPOINT((10 10))'::geometry)) AS G2,
        asText(envelope('MULTIPOINT((10 10), (10 10))'::geometry)) AS G3,
        asText(envelope('MULTIPOINT((10 10), (20 20))'::geometry)) AS G4,

        asText(envelope('LINESTRING(10 10, 10 50)'::geometry)) AS G5,
        asText(envelope('LINESTRING(10 50, 50 50)'::geometry)) AS G6,
        asText(envelope('LINESTRING(10 10, 50 50)'::geometry)) AS G7,

        asText(envelope('MULTILINESTRING((10 10, 50 50))'::geometry)) AS G8,
        asText(envelope('MULTILINESTRING((10 10, 50 50), (20 20, 70 
70))'::geometry)) AS G9,
        asText(envelope('MULTILINESTRING((10 10, 10 50), (10 20, 10 
70))'::geometry)) AS G10,

        asText(envelope('POLYGON((10 10, 50 50, 30 30, 20 20, 10 
10))'::geometry)) AS G11


g1 "POINT(10 10)";
g2 "POINT(10 10)";
g3 "POINT(10 10)";
g4 "POLYGON((10 10,10 20,20 20,20 10,10 10))";
g5 "LINESTRING(10 10,10 50)";
g6 "LINESTRING(10 50,50 50)";
g7 "POLYGON((10 10,10 50,50 50,50 10,10 10))";
g8 "POLYGON((10 10,10 50,50 50,50 10,10 10))";
g9 "POLYGON((10 10,10 70,70 70,70 10,10 10))";
g10 "LINESTRING(10 10,10 70)";
g11 "POLYGON((10 10,10 50,50 50,50 10,10 10))"


Martin Davis wrote:
> Charlie:
> 
> If the examples you give in the email below are actually what your 
> Envelope patch is doing, this is WRONG!
> 
> The envelope of non-horizontal/non-vertical linestrings will always be a 
> Polygon, not a Linestring.  Only exactly horizontal  or vertical 
> linestrings will have an envelope which is itself a LineString.
> 
> The way this should be implemented is to first compute the true extents 
> of the geometry.  Then check the X &Y extents and return the appropriate 
> geometry constructed from the extent ordinates.  The JTS code that does 
> this is:
> 
> 
>  public Geometry toGeometry(Envelope envelope)
>  {
>      // null envelope - return empty point geometry
>    if (envelope.isNull()) {
>      return createPoint((CoordinateSequence)null);
>    }
>      // point?
>    if (envelope.getMinX() == envelope.getMaxX() && envelope.getMinY() == 
> envelope.getMaxY()) {
>      return createPoint(new Coordinate(envelope.getMinX(), 
> envelope.getMinY()));
>    }
>      // vertical or horizontal line?
>    if (envelope.getMinX() == envelope.getMaxX()
>            || envelope.getMinY() == envelope.getMaxY()) {
>        return createLineString(new Coordinate[]{
>          new Coordinate(envelope.getMinX(), envelope.getMinY()),
>          new Coordinate(envelope.getMaxX(), envelope.getMaxY())
>          });
>    }
> 
>    return createPolygon(createLinearRing(new Coordinate[]{
>        new Coordinate(envelope.getMinX(), envelope.getMinY()),
>        new Coordinate(envelope.getMaxX(), envelope.getMinY()),
>        new Coordinate(envelope.getMaxX(), envelope.getMaxY()),
>        new Coordinate(envelope.getMinX(), envelope.getMaxY()),
>        new Coordinate(envelope.getMinX(), envelope.getMinY())
>        }), null);
>  }
> 
> 
> -------- Original Message --------
> Subject:     [Fwd: Re: [postgis-devel] Re: Patch for PostGis Envelope Bug]
> Date:     Fri, 21 Sep 2007 16:11:51 -0700
> From:     Kevin Neufeld <kneufeld at refractions.net>
> To:     martin Davis <mbdavis at refractions.net>
> 
> 
> 
> 
> 
> -------- Original Message --------
> Subject:     Re: [postgis-devel] Re: Patch for PostGis Envelope Bug
> Date:     Fri, 21 Sep 2007 15:05:54 -0600
> From:     Charlie Savage <cfis at savagexi.com>
> Reply-To:     PostGIS Development Discussion 
> <postgis-devel at postgis.refractions.net>
> To:     PostGIS Development Discussion 
> <postgis-devel at postgis.refractions.net>
> References:     <46E09936.5030008 at savagexi.com> 
> <9245.1189132424 at sss.pgh.pa.us> <46E0E199.40302 at savagexi.com> 
> <46E13929.5090400 at vadose.org> <46E1739D.6030800 at savagexi.com> 
> <46E181A2.6050309 at refractions.net> <46E18A30.2000002 at savagexi.com> 
> <46E18B76.4000508 at refractions.net> <46E39FDC.3040005 at savagexi.com> 
> <46F09E3B.4080209 at savagexi.com> 
> <7F743A6F-517E-498F-A3D7-23793727D60A at refractions.net> 
> <46F43097.4010503 at savagexi.com>
> 
> 
> 
> And here is an example of its use:
> 
> select asText(envelope('POINT(10 10)'::geometry)),
>        asText(envelope('MULTIPOINT((10 10))'::geometry)),
>        asText(envelope('MULTIPOINT((10 10), (20 20))'::geometry)),
> 
>        asText(envelope('LINESTRING(10 10, 50 50)'::geometry)),
>        asText(envelope('MULTILINESTRING((10 10, 50 50))'::geometry)),
>        asText(envelope('MULTILINESTRING((10 10, 50 50), (20 20, 70 
> 70))'::geometry)),
> 
>        asText(envelope('POLYGON((10 10, 50 50, 30 30, 20 20, 10 
> 10))'::geometry))
> 
> 
> "POINT(10 10)";
> "POINT(10 10)";
> "POLYGON((10 10,10 20,20 20,20 10,10 10))";
> "LINESTRING(10 10,50 50)";
> "LINESTRING(10 10,50 50)";
> "POLYGON((10 10,10 70,70 70,70 10,10 10))";
> "POLYGON((10 10,10 50,50 50,50 10,10 10))"
> 
> Charlie
> 
> 
> Charlie Savage wrote:
>> Hi Paul,
>>
>> Paul Ramsey wrote:
>>> Applied to trunk. I don't see any way it can do harm.
>>
>> Here is patch to the patch (thus it applies against the trunk).
>>
>> It adds in support for returning a LineString if envelope is called on 
>> a line string (thus making this similar to the  bbox to geom 
>> conversion routines).
>>
>> Also, it fixes a bug I introduced in the last version (not checking to 
>> see if the deserialized geom should be freed).
>>
>> Thanks,
>>
>> Charlie
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> postgis-devel mailing list
>> postgis-devel at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-devel
> 
> 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: postgis_envelope.patch
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20070921/ad863936/attachment.ksh>
-------------- 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-devel/attachments/20070921/ad863936/attachment.bin>


More information about the postgis-devel mailing list