Skip to content
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

Introduce distance expression #10616

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

Introduce distance expression #10616

wants to merge 11 commits into from

Conversation

zmiao
Copy link
Contributor

@zmiao zmiao commented Apr 26, 2021

This pr introduces a new expression distance, which will return the shortest distance in Meters between the feature and the input geometry data.

['distnace', geoJSON]

distance support all geometry types, i.e. Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon.

Basic evaluation rules for finding the distance:

(1) The distance between two points is the straight line between them.
(2) The distance between a point and a line segment is the perpendicular or the closest line endpoint to the point.
(3) The distance between two line segments is either the perpendicular from one endpoint of a line segment to the other line segment or the distance between the two closest endpoints from each line segment.

Special cases to consider:

  • The distance between 2 geometry sets is always the same regardless of the geometry being evaluated to (input geometry), and the one being evaluated from (feature geometry).

  • The distance between 2 geometry sets is zero, whenever one geometry set contains or is within the other geometry set.

  • This distance between 2 geometry sets is zero when these two geometry sets intersect, overlap, collide with each other.

  • The distance evaluation for polygon geometry is based on the boundary of the polygon, instead of the centroid.

  • The distance would always be positive or zero.

Steps to find the distance between different geometry combination cases:

  1. Point to Point: use rule (1)
  2. Point to LineString: use rule (2) to calculate each distance between the Point to each line segment of the LineString. Choose the smallest distance.
  3. Point to Polygon: Polygon can be taken as the closet ring of a LineString, use case 2 to calculate the distance. In case Point is within or on the boundary of the polygon, the distance is zero.
  4. LineString to LineString: use rule (2) to calculate the distance between each line segment of the LineString to the other one. Choose the smallest distance. In case two line segment are intersecting with each other, the distance is zero.
  5. LineString to Polygon: use case 4 to calculate the distance between the line segments, choose the smallest distance. In case LineString is crossing, intersecting or within Polygon, the distance is zero.
  6. Polygon to Polygon: use case 4 to calculate the distance between the line segments, choose the smallest distance. In case one Polygon is intersecting or within the other Polygon, the distance is zero.
  7. Multi*/ Single* geometry to Multi*/Single* geometry: choose the smallest distance of each single to single geometry set distance.

One example of using an expression with filter would have the following effects :

'filter': ['<', ['distance','userPosition'], 200]

Screen Shot 2020-03-24 at 5 50 39 PM


Follow-up:

  • Current impl has already introduced a big size burden, so I decided to postpone porting distance expression perf improvements from gl-native.

Launch Checklist

  • briefly describe the changes in this PR
  • include before/after visuals or gifs if this PR includes visual changes
  • write tests for all new functionality
  • document any changes to public APIs
  • post benchmark scores
  • manually test the debug page
  • tagged @mapbox/map-design-team @mapbox/static-apis if this PR includes style spec API or visual changes
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Introduce 'distance' expression. </changelog>

@zmiao zmiao self-assigned this Apr 26, 2021
@zmiao zmiao force-pushed the zmiao-distance-expression branch 3 times, most recently from 7470240 to 3fb60e5 Compare June 2, 2021 11:11
@zmiao zmiao marked this pull request as ready for review June 2, 2021 12:44
@zmiao zmiao marked this pull request as draft June 2, 2021 18:57
@zmiao zmiao removed their assignment Jun 21, 2021
@asheemmamoowala asheemmamoowala removed their request for review June 28, 2021 16:58
@enersis-pst
Copy link
Contributor

i really love and need this feature. Is there any progress on review?

@zmiao
Copy link
Contributor Author

zmiao commented Sep 28, 2021

@enersis-pst thank you for your feedback and the reason why we are putting this feature on hold is that the current implementation brings a significant bundle size increase, which is something we want to address before merging it.
Screen Shot 2021-09-28 at 9 48 43 PM

@enersis-pst
Copy link
Contributor

@enersis-pst thank you for your feedback and the reason why we are putting this feature on hold is that the current implementation brings a significant bundle size increase, which is something we want to address before merging it. Screen Shot 2021-09-28 at 9 48 43 PM

@zmiao thanks for the info. Then i will wait :-)

@awulkan
Copy link

awulkan commented Jan 14, 2022

@enersis-pst thank you for your feedback and the reason why we are putting this feature on hold is that the current implementation brings a significant bundle size increase, which is something we want to address before merging it. Screen Shot 2021-09-28 at 9 48 43 PM

Does anyone have any ideas for how to address this problem?

@1ec5 1ec5 linked an issue Jan 20, 2022 that may be closed by this pull request
@markusand
Copy link

Has it been any advance on this request? It's been inactive for a year now.

@Rhipeus
Copy link

Rhipeus commented Jun 6, 2023

Can someone reconsider the decision to exclude this PR because of a substantial size increase? In the 2 years since a 1% increase in size was a concern for this PR, MapBox has grown ~15% in size. This feature would be so very helpful.

Plus, it would now be a <1% increase in size. 😉

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.

Distance expression operator
5 participants