[postgis-users] Finding if a polygons is fully covered by others
Martin Davis
mbdavis at refractions.net
Mon Jan 18 11:43:12 PST 2010
Good point, Nicklas. Instead of using difference in the 3rd step, the
Covers predicate could be used. This is likely to be more performant
than difference, as well.
The union step is definitely needed, however, since Covers can't work
with the collection of the bounding boxes - they need to be unioned to
form a valid MultiPolygon.
Nicklas Avén wrote:
> Yes, sorry, I see I missunderstood you in my last answer.
>
> I was confused, because:
> Is the area-solution working at all. If there is many overlapping
> bbox-polygons in the table isn't that going to give a too big area. If
> I'm not still on wrong trac I guess you can easily get negative
> answers from your query.
>
> and Martin, why is difference better here than CoveredBy or something
> like that to compare your unioned box with the query-polygon. Is
> difference a faster solution?
>
> /Nicklas
>
> 2010-01-18 Martin Davis wrote:
>
> The way I'd look at doing this is:
> >
> >- find all bounding boxes which intersect the query polygon
> >- union the boxes
> >- compute the difference between the box union and the query poly
> >- If the difference is non-empty, the boxes do not cover the polygon.
> >
> >This should be a bit more accurate than simply using the areas. It could
> >be more performance as well, given the new fast-union functions.
> >
> >Nicolas Gillet - MARKET-IP wrote:
> >>
> >> Hello,
> >>
> >> I am looking for some help in optimizing a query.
> >>
> >> I have a table with bounding boxes and sometimes I need to find if a
> >> new given polygon can be fully covered by existing bounding boxes of
> >> my table.
> >>
> >> Right now I can find it out by summing the areas of intersections
> >> between my polygon and those in my table and comparing this computed
> >> area with my polygon area.
> >>
> >> Here’s the query :
> >>
> >> SELECT ST_area(ST_GeometryFromText('POLYGON((-1 0, -1 1, 1 1, 1 0, -1
> >> 0))', 4326) ) -
> >>
> >> (SELECT SUM(st_area(st_intersection(the_geom,
> >> ST_GeometryFromText('POLYGON((-1 0, -1 1, 1 1, 1 0, -1 0))', 4326) ) ))
> >>
> >> FROM tests WHERE the_geom && ST_GeometryFromText('POLYGON((-1 0, -1 1,
> >> 1 1, 1 0, -1 0))', 4326) )
> >>
> >> => if query returns 0 then my polygon can be fully covered if != 0
> >> then it can’t.
> >>
> >> But I was wondering if there couldn’t be an easier way to do this.
> >>
> >> Thank you.
> >>
> >> Nicolas.
> >>
> >>
> ------------------------------------------------------------------------
> >>
> >> _______________________________________________
> >> 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
> >
> >_______________________________________________
> >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
>
--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022
More information about the postgis-users
mailing list