-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a function to pick important features by grid #2001
Changes from 1 commit
19f7184
ba251f3
99a5944
88a232f
17b4184
d6d3980
9635901
49a13cd
2a05f60
f86f5be
58a831b
44a3d80
514a549
a4291c7
23786bf
d8b7dbe
ab0d108
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3120,9 +3120,10 @@ def keep_n_features_gridded(ctx): | |
pairs in `items_matching` into a grid, then keep the | ||
first `max_items` features in each grid cell. | ||
|
||
The grid is created by dividing the width and height | ||
of the tile into `grid_size` buckets (so you end up | ||
with grid_size*grid_size buckets total). | ||
The grid is created by dividing the tile into buckets. | ||
You can specify the `grid_width` and `grid_height` to | ||
get grid_width*grid_height buckets or just `grid_width` | ||
to get grid_width*grid_width buckets. | ||
|
||
NOTE: This only works with point features and will | ||
pass through non-point features untouched. | ||
|
@@ -3139,15 +3140,17 @@ def keep_n_features_gridded(ctx): | |
end_zoom = ctx.params.get('end_zoom') | ||
items_matching = ctx.params.get('items_matching') | ||
max_items = ctx.params.get('max_items') | ||
grid_size = ctx.params.get('grid_size') | ||
grid_width = ctx.params.get('grid_width') | ||
# if grid_height is not specified, use grid_width for grid_height | ||
grid_height = ctx.params.get('grid_height') or grid_width | ||
sorting_keys = ctx.params.get('sorting_keys') | ||
|
||
# leaving items_matching, grid_size, or max_items as None (or zero) | ||
# would mean that this filter would do nothing, so assume | ||
# that this is really a configuration error. | ||
assert items_matching, 'keep_n_features_gridded: missing or empty item match dict' | ||
assert max_items, 'keep_n_features_gridded: missing or zero max number of items' | ||
assert grid_size, 'keep_n_features_gridded: missing or zero grid size' | ||
assert grid_width, 'keep_n_features_gridded: missing or zero grid width' | ||
assert sorting_keys, 'keep_n_features_gridded: missing sorting keys' | ||
assert isinstance(sorting_keys, list), 'keep_n_features_gridded: sorting keys should be a list' | ||
|
||
|
@@ -3166,8 +3169,8 @@ def keep_n_features_gridded(ctx): | |
return None | ||
|
||
minx, miny, maxx, maxy = ctx.unpadded_bounds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By here do we know if we're in a 256 or 512 px tile and can adjust a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, there's no concept of pixel size here as far as I know. It's just processing a bounding box of vector data. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wacky (future) idea: seems like you could even compute the features to keep in for multiple tile sizes and tag them as such. We could include this stuff in our layer output but then weed it out in tilequeue where we know what size we're cutting. |
||
bucket_width = (maxx - minx) / grid_size | ||
bucket_height = (maxy - miny) / grid_size | ||
bucket_width = (maxx - minx) / grid_width | ||
bucket_height = (maxy - miny) / grid_height | ||
|
||
# Sort the features into buckets | ||
buckets = defaultdict(list) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it all these values for grid width and start/end zoom were arrived at experimentally? Did you try anything like reducing the width but increasing max_items to get a more organic look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I did a bit of experimentation based on the suggestions Nathaniel made above and these values seemed to look best. At least in the really dense area around Tokyo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't try more than one item per bucket. That and wider-than-taller buckets (since labels are wider than taller) are two things we could try in the future I think.