-
Notifications
You must be signed in to change notification settings - Fork 1
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
287 improve osm maps with tag metadata #294
Conversation
…h large osm fixture
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.
Great stuff Rich. Just a few small comments on this
style_kwds: dict = { | ||
"color": "#3f5277", | ||
"fill": True, | ||
"fillOpacity": 0.3, | ||
"fillColor": "#3f5277", | ||
"weight": 4, | ||
}, |
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.
is this the correct approach? it assumes that a user wants to specify all of these features.
In theory, a user might only want to change e.g., the colour, however to do this they would have to specify all the other keywords themselves since style_kwds would be overwritten.
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.
@@ -719,6 +873,7 @@ def plot_ids( | |||
_type_defence(ids, "ids", list) | |||
_type_defence(feature_type, "feature_type", str) | |||
_type_defence(crs, "crs", (str, int)) | |||
_type_defence(include_tags, "include_tags", bool) |
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.
Can you also add defences for the remainder of the new params?
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.
agree. good shout.
@@ -37,6 +39,12 @@ | |||
# ---------utilities----------- | |||
|
|||
|
|||
class PerformanceWarning(UserWarning): |
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.
Do you think inheriting from Warning
would be better than UserWarning
here?
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.
agree
@@ -541,6 +549,16 @@ def __init__( | |||
_is_expected_filetype( | |||
osm_pth, "osm_pth", check_existing=True, exp_ext=".pbf" | |||
) | |||
self.large_file_thresh = 50000 # 50 KB |
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.
Very small thing that doesn't really matter.
Do you think this needs to be defined as an attribute of the class? This should be a one time use in the initial size check therefore it can simply be assigned to a local variable.
The only downfall of having it as a class attribute is that a user could potentially view it as something they can alter.
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.
agree with your point. I used name mangling and updated the docstring.
osm_size = os.path.getsize(osm_pth) | ||
if osm_size > self.large_file_thresh: | ||
warnings.warn( | ||
f"PBF file is {osm_size} bytes. Tag operations are expensive." | ||
" Consider filtering the pbf file smaller than" | ||
f" {self.large_file_thresh} bytes", | ||
PerformanceWarning, | ||
) |
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.
A very small technicality, but the error message provokes the user to reduce file size < 50000, however an error isn't raised if file size is 50000.
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.
It'll still work for sizes greater than 50 KB, it just gets slow on init. It's hoped this would nudge the user to think about the size of the files prior to using FindTags as it's the slowest of all the osm flavoured classes.
for d in [dict1, dict2]: | ||
if not isinstance(d, dict): | ||
raise TypeError(f"Expected dict but found {type(d)}: {d}") | ||
for id_, tags in dict1.items(): # child_tags is nested | ||
# find duplicated keys and prepend parent keys | ||
if dupes := set(tags.keys()).intersection(dict2.keys()): | ||
for key in dupes: | ||
dict2[f"{prepend_pattern}{key}"] = dict2.pop(key) | ||
# merge parent and child tag collections | ||
tags_out[id_] = tags | dict2 | ||
return tags_out |
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.
A very good way of doing this.
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.
It's neat now, but it took a lot of wiggling to get there!
docs/tutorials/osm/index.qmd
Outdated
@@ -353,6 +353,14 @@ To read more on `osmosis` filtering strategies, refer to the `completeWays` and | |||
`completeRelations` flag descriptions in the | |||
[Osmosis detailed usage documentation](https://wiki.openstreetmap.org/wiki/Osmosis/Detailed_Usage_0.48). | |||
|
|||
|
|||
Note that additional metadata can be added to the map by setting `include_tags=True`. Adding this rich contextual data to the map can be useful but is also expensive. This operation should be avoided for large osm files, for example anything over 500 KB. |
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.
'computationally expensive' rather than 'expensive' here would be a better description, in my opinion, as it provides greater context to the reader.
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.
Agree
f3491a1
to
3004a81
Compare
Hey @CBROWN-ONS , I've just implemented your suggestions and pushed the diff to the PR. Thanks for your review on this, some good catches in there. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #294 +/- ##
=======================================
Coverage 98.13% 98.13%
=======================================
Files 21 21
Lines 1927 1983 +56
=======================================
+ Hits 1891 1946 +55
- Misses 36 37 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thanks for the changes @r-leyshon . All good, will merge this now. |
Description
Fixes #287
Type of change
How Has This Been Tested?
Test configuration details:
Advice for reviewer
Checklist:
Additional comments