Account Options

  1. Sign in
Google Groups Home
« Groups Home
alternatives to simplify() for reducing points in polygons
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steve Howell  
View profile  
 More options Jun 8 2009, 7:51 pm
From: Steve Howell <showel...@yahoo.com>
Date: Mon, 8 Jun 2009 16:51:04 -0700 (PDT)
Local: Mon, Jun 8 2009 7:51 pm
Subject: alternatives to simplify() for reducing points in polygons
Hi, I have some shape files from the census site that have far more
granularity than I really need for my application, and I want to
reduce the number of points in the polygons to save storage, make
queries more efficient, etc.

The simplify() method seems to fit the bill for me, but instead of
specifying a distance epsilon, I just want to set a maximum number of
points in the polygon that I keep.

The underlying algorithm looks straightforward enough, so I'm thinking
of writing my own variation in Python, and I'm just wondering if
anybody has already done the same thing and wouldn't mind sharing the
code.  Basically, the idea is to do something like this:

  1) Find all points' orthogonal distances from segment defined by
neighbors.
  2) Discard the point that is closest to its neighbors' segment.
  3) Recalculate the two neighbors' distance values.
  4) Repeat steps 2 and 3.
  5) Stop when I'm down to the number of points that I desire to keep.

Another approach that I've though of:

1) Figure out a good way to calibrate the initial epsilon, such as by
taking the diagonal of the extent of the polygon and applying a
percentage.
2) Keep bumping up the epsilon until I get to a desired number of
points.

Any advice will be appreciated.

Also, I am wondering if anybody has ever calibrated the algorithm to
look at relative distances instead of absolute distances.  For
example, it seems like a point that is 100 feet from the rest of the
polygon adds more value if the closest segment is only 1000 feet vs.
the scenario where the closest segment is maybe a mile long.

Also, it seems like you might want to grant immunity to any point that
is not "between" its neighbors, but I'm wondering if that really comes
up in the real world, and if so, how you would define "between" in a
rigorous manner.

One final question--does anybody have a handy online link to the code
for simplify()?

Cheers,

Steve


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Livni  
View profile  
 More options Jun 8 2009, 8:09 pm
From: Josh Livni <j...@umbrellaconsulting.com>
Date: Mon, 8 Jun 2009 17:09:23 -0700
Local: Mon, Jun 8 2009 8:09 pm
Subject: Re: alternatives to simplify() for reducing points in polygons

Hi Steve,
There are a number of different polyline simplification algorithms, but the
one used by st_simplify in postgis uses douglas-peucker (
http://postgis.refractions.net/documentation/manual-svn/ST_Simplify.html).
Here's some python code for that algorithm (courtesy of Schuyler Erle) which
should get you started  http://mappinghacks.com/code/dp.py.txt

Mapshaper.org, I think, does a really nice job showing some different
algorithms which you might find interesting.

<http://mappinghacks.com/code/dp.py.txt>
 -Josh


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options Jun 8 2009, 9:37 pm
From: Steve Howell <showel...@yahoo.com>
Date: Mon, 8 Jun 2009 18:37:56 -0700 (PDT)
Local: Mon, Jun 8 2009 9:37 pm
Subject: Re: alternatives to simplify() for reducing points in polygons

--- On Mon, 6/8/09, Josh Livni <j...@umbrellaconsulting.com> wrote:

> Here's some python code for that algorithm
> (courtesy of Schuyler Erle) which should get you started
>  http://mappinghacks.com/code/dp.py.txt

> Mapshaper.org, I think, does a really nice job
> showing some different algorithms which you might find
> interesting.

Thanks, all good stuff.  I am leaning toward the VW algorithm now.

So now for a more basic question--are there examples anywhere of how to instantiate a MultiPolygonField from a simple list of points?   I am guessing it has a MultiPolygon class as its back end, but how do I tell whether it's the one from gdal.geometries or geos.collections?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options Jun 9 2009, 4:43 pm
From: Steve Howell <showel...@yahoo.com>
Date: Tue, 9 Jun 2009 13:43:08 -0700 (PDT)
Local: Tues, Jun 9 2009 4:43 pm
Subject: Re: alternatives to simplify() for reducing points in polygons

Hi, just to follow up on my own recent posting, folks may find this snippet useful as an alternative to the batteries-included simplify():

http://www.djangosnippets.org/snippets/1559/

Thanks to Josh Livni for helpful pointers.

Comments are welcome, of course, either here or on the snippets page.

Thanks,

Steve


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dane Springmeyer  
View profile  
 More options Jun 10 2009, 12:13 am
From: Dane Springmeyer <dane.springme...@gmail.com>
Date: Tue, 9 Jun 2009 21:13:39 -0700
Local: Wed, Jun 10 2009 12:13 am
Subject: Re: alternatives to simplify() for reducing points in polygons

On Jun 8, 2009, at 6:37 PM, Steve Howell wrote:

> Thanks, all good stuff.  I am leaning toward the VW algorithm now.

VW rocks. I'd love to see that implemented in python.

http://users.cs.cf.ac.uk/C.B.Jones/Zhou_JonesSDH04.pdf

Dane


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options Jun 10 2009, 12:40 pm
From: Steve Howell <showel...@yahoo.com>
Date: Wed, 10 Jun 2009 09:40:16 -0700 (PDT)
Local: Wed, Jun 10 2009 12:40 pm
Subject: Re: alternatives to simplify() for reducing points in polygons

--- On Tue, 6/9/09, Dane Springmeyer <dane.springme...@gmail.com> wrote:

> VW rocks. I'd love to see that implemented in python.

> http://users.cs.cf.ac.uk/C.B.Jones/Zhou_JonesSDH04.pdf

I didn't read the paper carefully, but this Python code at least captures some of the concepts.

http://www.djangosnippets.org/snippets/1559/

The code removes vertices by area, and recalculates triangles as vertices are removed.  It does a straight area calculation, though, i.e. there is no tuning for flatness, convexity, etc.

Also, I didn't quite understand the section about removing all points and then restoring them in order, so I may be missing something, but my interpretation of the gist of the algorithm seemed to produce good results on our dataset.

If anybody gets a chance to play with the code I posted above, please let us know how you modified it.

Thanks,

Steve


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Livni  
View profile  
 More options Jun 10 2009, 12:56 pm
From: Josh Livni <j...@umbrellaconsulting.com>
Date: Wed, 10 Jun 2009 09:56:24 -0700
Local: Wed, Jun 10 2009 12:56 pm
Subject: Re: alternatives to simplify() for reducing points in polygons

I only skimmed the paper -- but I think the bit about restoring points after
the calculation is the key to the overall VW method:  after calculating the
'importance' of a vertex (using whatever method), you don't remove it from
future calculations just because it's 'unimportant' -- when you calculate
the next vertex, the potentially unimportant one you previously calculated
will still be there (because you put it back).    So their method is
something like: 1) give every single vertex an 'importance' (eg based on
effective area of triangle)
 2) after doing that for every vertex, only then choose which ones to remove
(eg the least important 40%)

whereas I assume your code (which I haven't even looked at) does something
like
 1) walk along the line, removing 'unimportant' vertices as you go along, so
perhaps previously removed vertices are not included in current calculations
about what to remove ...

One advantage of their method, as I see it, is once the original calculation
is done you don't need to recalculate importance for new simplification, you
just display those vertices where importance > x.

But then again I only skimmed it, so I could be wrong.

 -Josh


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options Jun 10 2009, 2:20 pm
From: Steve Howell <showel...@yahoo.com>
Date: Wed, 10 Jun 2009 11:20:19 -0700 (PDT)
Local: Wed, Jun 10 2009 2:20 pm
Subject: Re: alternatives to simplify() for reducing points in polygons

--- On Wed, 6/10/09, Josh Livni <j...@umbrellaconsulting.com> wrote:

> whereas I assume your code (which I haven't
> even looked at) does something like 1) walk
> along the line, removing 'unimportant' vertices as
> you go along, so perhaps previously removed vertices are not
> included in current calculations about what to remove

Just to be clear, after I remove any point, I do recalculate the effective areas for its neighbors, as you tend to want to keep a point more after its neighbor has been removed.  So the algorithm is smart that way.  But it *is* greedy, i.e. every iteration removes the least effective point, and there is no "restore" process.

Here is the main piece of code.

  def simplify_points(points, max, id, name):
    tups = []
    for i, point in enumerate(points):
        if i == 0 or i == len(points) - 1:
            benefit = None
        else:
            benefit = benefit_function(point, points[i-1], points[i+1])
        tups.append((point, benefit))
    removals = 0
    while len(tups) > max + 1:
        min_benefit = tups[1][1]
        min_i = 1
        for i, (point, benefit) in enumerate(tups):
            # print i, benefit
            if benefit and benefit < min_benefit:
                min_benefit = benefit
                min_i = i
        del tups[min_i]
        removals += 1
        for i in [min_i-1, min_i]:
            point = tups[i][0]
            if i == 0 or i == len(tups) - 1:
                benefit = None
            else:
                benefit = benefit_function(point, tups[i-1][0], tups[i+1][0])
            tups[i] = (point, benefit)

    points = [point for point, benefit in tups]
    return points


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »