-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
base: main
Are you sure you want to change the base?
Conversation
7470240
to
3fb60e5
Compare
Change cheap-rute type declaration, avoid unncessary geometry cloning
3fb60e5
to
c1a18e1
Compare
i really love and need this feature. Is there any progress on review? |
@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. |
@zmiao thanks for the info. Then i will wait :-) |
Does anyone have any ideas for how to address this problem? |
Has it been any advance on this request? It's been inactive for a year now. |
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. 😉 |
This pr introduces a new expression
distance
, which will return the shortest distance in Meters between the feature and the input geometry data.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:
Point to Point
: use rule (1)Point to LineString
: use rule (2) to calculate each distance between the Point to each line segment of the LineString. Choose the smallest distance.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.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.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.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.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 :Follow-up:
distance
expression perf improvements from gl-native.Launch Checklist
mapbox-gl-js
changelog:<changelog>Introduce 'distance' expression. </changelog>