-
Notifications
You must be signed in to change notification settings - Fork 270
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
Calculate distance metrics for line features #93
Conversation
🎉!!! It looks like there may be a few bugs in this (or this may be related to the caveat you mentioned) — for example, with this feature at z12, the lower tile (where the feature starts) has Here's a debug page with that route — https://bl.ocks.org/lbud/fc5790798b951516ad0d01965a9f282f#13.9/38.88334/-77.03918 I'm not totally sure I understand the caveat you mentioned in practice, but the other consequence of using relative distances rather than any absolute distance is that in the line bucket we have to iterate over the entire feature one extra time in order to precalculate the total distance in tile units of the sliced feature before creating any vertices, so that we can calculate the scale factor of a tile unit on this tile and the correctly scale absolute tile distances to relative units. Here's the commit (branched off |
🎉🎉🎉 Note that this would also probably solve this issue. I recommend a paper maybe helpful about this: http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0176387. |
@lbud oops, there was indeed a couple of bugs there. Thanks for the quick turnaround and setting up the debug page — this allowed me to track them down quickly. Looks legit now (even with buffers! 🎉): @jingsam great point! We should definitely look into this too. One issue is that we'd have to add the line metrics feature to our server-side stack to be able to explore a proper fix for the core styles, which should be much more inolved that in |
Here's my clunky shot at an illustration: So basically both partial and total distances change after simplification, but since we calculate those before it, this can lead to a mismatch across tiles in case of a non-uniformly detailed line. E.g. in this case, if we use absolute distances, we'll render the left line part up till e.g. ~35m but the second tile will start at 70m.
I think this is fine — we can still avoid that for non- |
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.
🎉 looks great to me!
Some potential clarifications that helped me understand clipLines
better: #94
src/clip.js
Outdated
if (a < k1) { | ||
// ---|--> | | ||
if (b >= k1) intersect(slice, ax, ay, bx, by, k1); | ||
if (b >= k1) { | ||
var t = intersect(slice, ax, ay, bx, by, k1); |
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.
Declare t at top of function?
@lbud this is ready to merge. The only thing I'm worried about is the choice of properties — |
Capturing from chat:
@1ec5 also suggested we prefix with something more specific:
|
@lbud How do you like |
@mourner 👌 sounds good to me! |
Actually, sorry, I want to push back on that one more time — we should probably at least try to run an analysis on mapbox.com user tilesets before going with |
I'm with @lbud: I think we should prefix these properties (and I'd lean towards something like |
Could we change the logic so that it only hits in when |
I don't like the prefix I think fields like |
Please let me know if you need this in Tippecanoe too. I do hope that we can establish first-class support soon in the vector tile format for rejoining geometries across tile boundaries instead of relying on magic attributes like this. |
I have a idea that put
These two fields can be referenced with |
Not only to |
I miss typed
So existing vector tile encoding tools would not be affected. I think this way is more elegant than the way to add magic fields and pollute user's |
@jingsam I'm strongly against this approach. For consistency, would we add any potential calculated properties across our tools (see mapbox/vector-tile-spec#102) to the scheme, and update all our vector tile encoders accordingly? Would we have to do this every time we add a new calculated property? This would place a lot of maintenance overhead and pollute the spec with tons of noise. Given that those properties are behind a flag, I see no harm in having them as user properties, especially given how unlikely collision is with these names. |
@mourner I think However, Tools-generated properties such as So, |
@jingsam if you think those should be in the vector-tile-spec, you should submit a proposal to the vector-tile-spec repo. However, releasing a new version of the spec and getting all VT producers up to date will take a very long time. Since we want to ship this experimental feature now, it makes more sense to do it within the limits of the existing spec — I see no disadvantages to this approach since those properties are only used internally, and we can always change it after a VT spec revision. |
@mourner I agree with you. So let's make this feature work at first, and improve it later. |
Great, so I think we should prefix these properties regardless to indicate that they're special generated properties. Maybe we go with |
For the sake of moving this forward, I chose |
@lbud released as v3.1.0. |
🙌 🎉 🎂 thanks @mourner! |
This patch enables line metrics tracking for LineString/MultiLineString features. See mapbox/geojson-vt#93 for details. Based on patch from @lbud (Lauren Budorick).
This patch enables line metrics tracking for LineString/MultiLineString features. See mapbox/geojson-vt#93 for details. Based on patch from @lbud (Lauren Budorick).
This patch enables line metrics tracking for LineString/MultiLineString features. See mapbox/geojson-vt#93 for details. Based on patch from @lbud (Lauren Budorick).
This patch enables line metrics tracking for LineString/MultiLineString features. See mapbox/geojson-vt#93 for details. Based on patch from @lbud (Lauren Budorick).
This patch enables line metrics tracking for LineString/MultiLineString features. See mapbox/geojson-vt#93 for details. Based on patch from @lbud (Lauren Budorick).
This patch enables line metrics tracking for LineString/MultiLineString features. See mapbox/geojson-vt#93 for details. Based on patch from @lbud (Lauren Budorick).
If
lineMetrics: true
option is specified,geojson-vt
slices lines into tiles while keeping track of which part of the line each slice represents. This may allow us to do some new line rendering tricks in Mapbox GL in future (e.g. line gradients).Line features get the following special properties:
clip_start
marks the start of the line relative to its full length;0
if it matches the start of the original, unclipped lineclip_end
marks the end of the line relative to its full length;1
if it matches the end of the original lineThe option also explodes
MultiLineString
features into multipleLineString
ones to be able to add different properties to each.One big caveat is that metrics are calculated before final tile simplification (because they happen during the clipping stage). This means that actual distances on screen for these lines won't be perfectly proportional to those in the calculated properties, so if the tiles have buffers, rendering that relies on these properties may have visible seams. I'm not sure how bad this would be in practice, but let's test it out. This caveat is also the reason I opted for relative metrics rather than absolute distances (e.g.
distance_total
) — this way, if the buffers are 0, rendering will be seamless, even if slightly non-uniform.maybe force zero buffer whenseems to work OK with bigger bufferslineMetrics
istrue
?cc @lbud @kkaefer