Dan Johnson | 8 Oct 02:12

Approximate union of polygons?

I have an application that keeps a database of video footprints, one 
quadrilateral per frame of video. I consolidate each 5 seconds of video 
footprints into a single multipolygon in order to speed up queries for 
video of a specified area. That's typically a union of 150 (30fps) 
polygons with 4-vertexes. I build this multipolygon with ST_GeomUnion, 
and it's acceptably fast. So far, so good.

I've been quite surprised by the variance in the number of vertices in 
the resulting multipolygon - sometimes it's as high as 1200. Usually 
it's lower than the equvalent set of frame footprints, but not always. 
This hasn't been a problem for database queries, but now it's time to 
build a user interface and of course the UI has problems displaying that 
many vertices. (Actually, the UI is getting the polygons via a SOAP 
message, and our web server's SOAP infrastructure often just dies when 
the result is so long.) Eyeballing these consolidated polygons, it looks 
like keeping only 20-30 vertices would provide an excellent 
approximation. (It's quite common for the camera to stare at a single 
point for a long time, in which case all the frames are in about the 
same location.) This seems like the sort of thing PostGIS would be able 
to do but I haven't been able to figure it out from the docs. Does 
anyone know if this is possible?

(I've been told the footprints have to consider every frame, so building 
the union with one frame per second or similar is out.)

Thanks,
Dan
Kevin Neufeld | 8 Oct 03:41
Favicon

Re: Approximate union of polygons?

Have you tried putting your resultant multipolygons through ST_Simplify 
or ST_SimplifyPreserveTopology?  Both use the Douglas-Peuker algorithm 
to weed out unwanted vertices.

Cheers,
Kevin

Dan Johnson wrote:
> I have an application that keeps a database of video footprints, one 
> quadrilateral per frame of video. I consolidate each 5 seconds of 
> video footprints into a single multipolygon in order to speed up 
> queries for video of a specified area. That's typically a union of 150 
> (30fps) polygons with 4-vertexes. I build this multipolygon with 
> ST_GeomUnion, and it's acceptably fast. So far, so good.
>
> I've been quite surprised by the variance in the number of vertices in 
> the resulting multipolygon - sometimes it's as high as 1200. Usually 
> it's lower than the equvalent set of frame footprints, but not always. 
> This hasn't been a problem for database queries, but now it's time to 
> build a user interface and of course the UI has problems displaying 
> that many vertices. (Actually, the UI is getting the polygons via a 
> SOAP message, and our web server's SOAP infrastructure often just dies 
> when the result is so long.) Eyeballing these consolidated polygons, 
> it looks like keeping only 20-30 vertices would provide an excellent 
> approximation. (It's quite common for the camera to stare at a single 
> point for a long time, in which case all the frames are in about the 
> same location.) This seems like the sort of thing PostGIS would be 
> able to do but I haven't been able to figure it out from the docs. 
> Does anyone know if this is possible?
>
(Continue reading)

Dan Johnson | 8 Oct 22:41

Re: Approximate union of polygons?

Thanks, Kevin, that's exactly what I want. I thought I'd scoured the 
documentation but somehow I missed ST_Simplify.

- Dan

Kevin Neufeld wrote:
> Have you tried putting your resultant multipolygons through 
> ST_Simplify or ST_SimplifyPreserveTopology?  Both use the 
> Douglas-Peuker algorithm to weed out unwanted vertices.
>
> Cheers,
> Kevin
>
> Dan Johnson wrote:
>> I have an application that keeps a database of video footprints, one 
>> quadrilateral per frame of video. I consolidate each 5 seconds of 
>> video footprints into a single multipolygon in order to speed up 
>> queries for video of a specified area. That's typically a union of 
>> 150 (30fps) polygons with 4-vertexes. I build this multipolygon with 
>> ST_GeomUnion, and it's acceptably fast. So far, so good.
>>
>> I've been quite surprised by the variance in the number of vertices 
>> in the resulting multipolygon - sometimes it's as high as 1200. 
>> Usually it's lower than the equvalent set of frame footprints, but 
>> not always. This hasn't been a problem for database queries, but now 
>> it's time to build a user interface and of course the UI has problems 
>> displaying that many vertices. (Actually, the UI is getting the 
>> polygons via a SOAP message, and our web server's SOAP infrastructure 
>> often just dies when the result is so long.) Eyeballing these 
>> consolidated polygons, it looks like keeping only 20-30 vertices 
(Continue reading)


Gmane