[postgis-users] Equality operator for type box2d

Kuien Liu kliu at pivotal.io
Wed Apr 22 01:26:23 PDT 2015


Yup, if you really want to support DISTINCT on box2d implicitly, I think,
you may need to create below by yourself:

CREATE FUNCTION box2d_lt (b1 box2d, b2 box2d) ...
CREATE FUNCTION box2d_gt (b1 box2d, b2 box2d) ...
CREATE FUNCTION box2d_eq (b1 box2d, b2 box2d) ...
CREATE FUNCTION box2d_ge (b1 box2d, b2 box2d) ...
CREATE FUNCTION box2d_le (b1 box2d, b2 box2d) ...
CREATE FUNCTION box2d_cmp (b1 box2d, b2 box2d) ...

CREATE OPERATOR < ( leftarg = box2d, rightarg = box2d, procedure =
box2d_lt, commutator = '>', negator = '>=' ....)
CREATE OPERATOR > ( leftarg = box2d, rightarg = box2d, procedure =
box2d_lt, commutator = '<', negator = '<=' ....)
...

CREATE OPERATOR CLASS box2d_ops ... OPERATOR 1 <, OPERATOR 2 >, ....;


Then you can DISTINCT, ORDER BY, GROUP BY on box2d.

PS: casting box2d to geometry before calling DISTINCT seems a doable way to
bypass this issue. Right?

Cheers,
Kuien Liu

On Wed, Apr 22, 2015 at 1:26 PM, Nick Ves <vesnikos at gmail.com> wrote:

> Ah yes thank you for clearing that up. The = Operator is valid for those
> type.
>
> Strange thing is that box2d type DOES support the = Operator while
> st_box2d does not.
>
> A quick search in gis.SE forums gives a post [0] from a user stating
> that st_box2d is deprecated? Is that the case?
>
> [0] http://gis.stackexchange.com/questions/56818/st-box2d-in-postgis-2-0
>
> On Tue, Apr 21, 2015 at 1:24 PM, Kuien Liu <kliu at pivotal.io> wrote:
> > thanks, got it. Surely you may meet this issue, distinct cannot find the
> > 'OPERATOR =' for data type 'box2d'.
> >
> > PostGIS only supports 3 kinds of OPERATOR =, i.e.,
> >
> > OPERATOR =  (geometry,geometry)
> > OPERATOR =  (geography,geography)
> > OPERATOR =  (raster,raster)
> >
> > Maybe we can try these ways:
> >
> > cast box2d to geometry: select distinct st_extent(the_geom)::geometry
> from
> > test;
> > create ordering operator for box2d.
> >
> >
> > Cheers,
> > Kuien Liu
> >
> > On Tue, Apr 21, 2015 at 6:06 PM, Nick Ves <vesnikos at gmail.com> wrote:
> >>
> >> On Tue, Apr 21, 2015 at 12:50 PM, Kuien Liu <kliu at pivotal.io> wrote:
> >> > I'm not sure I understand what your query really looks like, but I can
> >> > run
> >> > query below.
> >>
> >> try this one:
> >>
> >> select distinct st_extent(the_geom) over () from test;
> >>
> >>
> >> > gis=# SELECT ST_GeometryType(ST_Extent(the_geom))='ST_Polygon' FROM
> test
> >> > WHERE num < 10;
> >> >  ?column?
> >> > ----------
> >> >  true
> >> > (1 row)
> >> >
> >> > where the table 'test' contains 50,000 points.
> >> >
> >> > Wish this helps to you.
> >> >
> >> > Cheers,
> >> > Kuien Liu
> >> >
> >> > On Tue, Apr 21, 2015 at 4:58 PM, Nick Ves <vesnikos at gmail.com> wrote:
> >> >>
> >> >> I was playing with the ST_Extent today and I wanted to try a query
> like
> >> >> this:
> >> >>
> >> >> select distinct ST_Extent(geom)  over () box from parcels_test
> >> >>
> >> >> where the geom is Type ST_Polygon but I got this error instead:
> >> >>
> >> >>   ERROR:  could not identify an equality operator for type box2d
> >> >>
> >> >> The aim was to get the BBox from a set of polygons that might or
> might
> >> >> not be adjutant. Ofc you can get the same results by limit the result
> >> >> to 1 but, it hitted me strange box2d type not having an equal
> operator
> >> >>
> >> >> using "POSTGIS="2.1.4 r12966" GEOS="3.4.2-CAPI-1.8.2 r3921"
> PROJ="Rel.
> >> >> 4.8.0, 6 March 2012" GDAL="GDAL 1.11.1, released 2014/09/24"
> >> >> LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER"
> >> >> _______________________________________________
> >> >> postgis-users mailing list
> >> >> postgis-users at lists.osgeo.org
> >> >> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
> >> >
> >> >
> >> >
> >> > _______________________________________________
> >> > postgis-users mailing list
> >> > postgis-users at lists.osgeo.org
> >> > http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
> >> _______________________________________________
> >> postgis-users mailing list
> >> postgis-users at lists.osgeo.org
> >> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
> >
> >
> >
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users at lists.osgeo.org
> > http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20150422/4a86d694/attachment.html>


More information about the postgis-users mailing list