Skip to content

Support 'height', 'weight', 'width' road attributes - #936

Merged
karussell merged 9 commits into
graphhopper:masterfrom
Transtech:road_attributes
Jan 31, 2017
Merged

karussell merged 9 commits into
graphhopper:masterfrom
Transtech:road_attributes

Conversation

@tmnguyen-swin

Copy link
Copy Markdown
Contributor

Unrecognized values will be logged and ignored.

@karussell karussell mentioned this pull request Jan 16, 2017

@boldtrn boldtrn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the nice commit!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might even make sense to put this to ReaderElement? Not sure about the implications.

Also if two several keys exist, only the last one is returned. Not sure if this is an issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let us keep it here for now

Also if two several keys exist, only the last one is returned. Not sure if this is an issue

I think this is not a problem yet. (BTW: the first vs. last?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first available value will be picked up. The intention is to have the list of semantically equivalent tags in descending order of preferences.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider other measurement units, like kg?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wiki says it is tons ... but here is the real fun with units in OSM ;)

We can contribute our slightly more complex parsing methods from the commercial version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be really nice if you can contribute the commercial version here!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the Wiki these vales might also happen: metre, metres, meter, meters. Couldn't find them via Taginfo, so not sure if this is relevant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if we could make the number of encoders configureable. Maybe if we pass a heightlimit of 0 via the Configmap to the DataflagEncoder, we don't register the heigthEncoder. WDYT?

@karussell karussell Jan 17, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this would be indeed great.

The real problem is that we are currently limited to 64 bit, where have an idea to make this kind of 'unbounded', but no time :/ ... see the edge.getData(int) idea here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry guys, didn't get the point here. What do you suggest in terms of configurable number of encoders? I understand the current limit of 32 bit or 64 bit for flags.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is that in some use cases one might not need to disable this feature in order to save bits. But something like this might be interesting for other encoded values too and a different issue could be more appropriated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it now. I've just finished a commit that makes encoders for road attributes configurable. Will merge with Peter's change before push.

@karussell karussell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks & looks good.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you use getHints().putAll or something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spot on. I actually had the same thought yesterday :) Will remove this method.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to expose this :) ? I would like to hide it as long as possible as the API for the blocked areas is not really stable and e.g. the String could change to a domain object etc to be more accessible. Also as this is not related to this PR we should move this to another issue?

@tmnguyen-swin tmnguyen-swin Jan 18, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need access to 'blockedRectangularAreas' in my subclass of GraphHopper. But I agree with you, this is not related to this PR. Will cancel this change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wiki says it is tons ... but here is the real fun with units in OSM ;)

We can contribute our slightly more complex parsing methods from the commercial version.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let us keep it here for now

Also if two several keys exist, only the last one is returned. Not sure if this is an issue

I think this is not a problem yet. (BTW: the first vs. last?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used and why protected access?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a custom FlagEncoder in my project that subclasses DataFlagEncoder. I needed this method there, so make it 'protected'. The method is actually not used at all in DataFlagEncoder (didn't realize this). Will move the method to my subclass.

@karussell karussell Jan 17, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this would be indeed great.

The real problem is that we are currently limited to 64 bit, where have an idea to make this kind of 'unbounded', but no time :/ ... see the edge.getData(int) idea here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here (maybe in a later version) we could do kind some kind of a compression: i.e. assign

  • 2.5m to index 0
  • 3.0m to index 1
  • 3.1m to index 2

... so we could make it more precise with less bits and for the ones that do not fit we would still round. For this taginfo is useful: http://taginfo.openstreetmap.org/keys/height#values ... it seems 2m is very important for the world wide case. (Or even more sophisticated and area dependent and create statistics in the first parse run and then pick the best compression automatically)

@tmnguyen-swin tmnguyen-swin Jan 18, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the current implementation is quite simple and is based on the value set for the particular area that I have. The value set was obtained from a source independent of OSM that I managed to incorporate into OSM using an internal data ingestion pipeline. As such, the value format is very good (as it is under my control :). I hope we can have more sophisticated implementation which is applicable to world wide data in later version.

For this PR, what I can do is investigating the value range that I can obtain from taginfo (Thanks for the reference - a great website). And see if we need more bits for the encoder and if I can enhance the parsing logic.

@tmnguyen-swin tmnguyen-swin Jan 18, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...The issue with taginfo data is we don't know which values are for road attributes, as opposed to, for instance, building height or height of the road in relation to the underlying river :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I leave the current encoders for road attributes as-is, with only one minor improvement in the latest commit. If the value is too big for the encoder, we just log & ignore, and continue parsing the OSM data.

Given this change, I was able to parse Australian OSM with only few exceptions of "too large value".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we just log & ignore, and continue parsing the OSM data.

If it is bigger than the accepted range we could ignore but maybe it is safer to still include it.

If it is smaller we have to throw an exception or warn the user and include it as a restriction (even it is wider)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For instance, a bridge section over a river has 'height' attribute set to 60m.

Does it have a height or maxheight of 60m? Height would be correctly mapped. Maxheight would be wrong. If it is maxheight, we could report an error to OSM.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting question. Let's me have a look at the detailed log file. The error message above ignored the actually tag being used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this. I reported an issue for both ways. Both are very small ways, so probably this is just a mapping issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karussell karussell added this to the 0.9 milestone Jan 17, 2017
@karussell

karussell commented Jan 19, 2017 •

Copy link
Copy Markdown
Member

The OSM related parsing and converting should be done in the OSM reader module not in the encoder. But when I move it there we have to convert regardless if it is enabled or not (e.g. using dataflagencoder or not). Hmmh, interesting ;)

@karussell

Copy link
Copy Markdown
Member

But this is worth a separate issue #939

@karussell

karussell commented Jan 19, 2017 •

Copy link
Copy Markdown
Member

Interesting. I was able to push to the road_attributes branch of Transtech/graphhopper (without explicit grant of permission I guess) ... even a force push. Seems that github has improved this to work together with different repos on the same pull request, nice. Please have a look - I hope I didn't messed up something!

private long extractTons(ReaderWay way, long flags, EncodedDoubleValue valueEncoder, List<String> keys) {
String value = extractRoadAttribute(way, keys);

String value = way.getFirstPriorityTag(keys);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the same functionality (do we have a test covering a change like this?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. OSMReaderTest#testRoadAttributes should do the job.

}

double stringToMeter(String value) {
public static double stringToMeter(String value) {

@karussell karussell Jan 19, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it public to reuse it elsewhere which is not really nice ... before I thought putting it into OSMTagParser is better, but this does not work, see #939

@tmnguyen-swin

tmnguyen-swin commented Jan 20, 2017 •

Copy link
Copy Markdown
Contributor Author

Guys, I have committed a new change that makes road attribute encoders configurable. Merging fine with master. Let me know if there is anything else you would like me to change.

Btw, I have resolved some conflicts when merging Peter's changes. Hopefully I didn't miss out anything :)

@karussell

karussell commented Jan 20, 2017 •

Copy link
Copy Markdown
Member

Thanks, this looks good.

Let us (shortly) discuss if we need three configurations or if one e.g. "store_truck_attributes":true is simpler (are there meaningful use cases where one would just need e.g. the weight?). Also the name is important, I prefer something with 'store_xy' and how the weighting interprets this value is up to the weighting.

Furthermore the boolean methods should be setXY instead of enableXY

Btw, I have resolved some conflicts when merging Peter's changes. Hopefully I didn't miss out anything :)

Sorry, I feared that. Force push is never a good idea if one works on the same branch with others :(. So instead I should have made my changes and the rebase/squash should have been done as the last step. Lesson learned ...

@karussell

Copy link
Copy Markdown
Member

Would you mind to just rename the methods? We do not need to debate on configuring and should just change it afterwards when necessary (?)

@tmnguyen-swin

Copy link
Copy Markdown
Contributor Author

I have renamed the methods and variables as requested. This naming convention makes more sense to me now. Please review and advise.

In relation to choosing single configuration field vs multiple configuration fields for road attributes, IMHO, I would go with multiple fields. That would make it more flexible as you would be able to select the attributes of interest, rather than all or nothing. This is especially true when we are still limited to 64 bit length of the flag & the cost of having all fields is expensive.

@karussell

Copy link
Copy Markdown
Member

This looks good now - thanks again!

This is especially true when we are still limited to 64 bit length of the flag & the cost of having all fields is expensive.

Yeah, this is ugly and needs a fix (better sooner than later :))

@karussell
karussell merged commit 06fe335 into graphhopper:master Jan 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants