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

Martin Davis mbdavis at refractions.net
Fri Sep 21 16:25:49 PDT 2007


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


-- 
-------------
Kevin Neufeld
Software Developer
Refractions Research Inc.
300-1207 Douglas St.
Victoria, B.C., V8W 2E7

Phone: (250) 383-3022
Email: kneufeld at refractions.net


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

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: file:///C:/DOCUME~1/KNEUFELD/LOCALS~1/TEMP/nsmail-2.txt
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20070921/8ff16e6c/attachment.txt>


More information about the postgis-devel mailing list