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

Marker outside oddly shaped target area #4965

Open
tobiasgradl opened this issue Apr 22, 2023 · 6 comments
Open

Marker outside oddly shaped target area #4965

tobiasgradl opened this issue Apr 22, 2023 · 6 comments
Labels
bug help wanted help by contributors is appreciated; might be a good first contribution for first-timers

Comments

@tobiasgradl
Copy link

image

For the "J"-shaped forest area in the above screenshot, Street Complete asks for forest's the leaf type. The marker for the questions is located on a meadow outside the area (probably at its geometrical center).

How to Reproduce
Go to N 51,0356643, E 7,3105947 in the StreetComplete app

Expected Behavior
The question's map marker is located inside the corresponding area.

Versions affected
Android, v52.0.

@rhhsm
Copy link

rhhsm commented Apr 22, 2023

I've seen this a few times, afaik always for the leaf type quest, but it didn't bother me because it was clear enough (so far) which oddly shaped forest it was asked about.

@westnordost
Copy link
Member

westnordost commented Apr 22, 2023

The code to calculate the center of a polygon is here:

fun List<LatLon>.centerPointOfPolygon(): LatLon {
require(isNotEmpty()) { "positions list is empty" }
var lon = 0.0
var lat = 0.0
var area = 0.0
val origin = first()
asSequenceOfPairs().forEach { (first, second) ->
// calculating with offsets to avoid rounding imprecision and 180th meridian problem
val dx1 = normalizeLongitude(first.longitude - origin.longitude)
val dy1 = first.latitude - origin.latitude
val dx2 = normalizeLongitude(second.longitude - origin.longitude)
val dy2 = second.latitude - origin.latitude
val f = dx1 * dy2 - dx2 * dy1
lon += (dx1 + dx2) * f
lat += (dy1 + dy2) * f
area += f
}
area *= 3.0
return if (area == 0.0) origin else LatLon(
lat / area + origin.latitude,
normalizeLongitude(lon / area + origin.longitude)
)
}

so, currently the center of the polygon is used, not the centroid. There is no particular reason for that. Maybe using the center of the polygon can be calculated faster, not sure. In any case, the centroid algorithm would need to be added in a PR, we do not use a geo-math-library for such calculations

@tobiasgradl
Copy link
Author

It's a minor issue. I spotted it for the first time. It got aggravated in this rare case by the area being very narrow, i.e., hardly visible on the map. In most other cases the user can probably guess which area the question belongs to.

Thanks for providing a pointer to the current algorithm! Maybe I'll find time to create a PR.

@westnordost
Copy link
Member

I'll release a new minor update in a week or so, so now is a good timeframe to implement this when you want to see this change live quickly. If you are not interested anymore in implementing this, I will mark this as "help wanted".

@tobiasgradl
Copy link
Author

Unfortunately, I'm not able to spend time on this issue, at the moment. Feel free to mark it as "help wanted"!

@matkoniecz matkoniecz added the help wanted help by contributors is appreciated; might be a good first contribution for first-timers label Jun 19, 2023
@westnordost
Copy link
Member

westnordost commented Jun 20, 2023

Correction: "centroid" is by definition not necessarily within the boundary of the polygon.

MapBox implemented an algorithm finding the polygon pole of inaccessibility, the most distant internal point from the polygon outline in JavaScript: https://github.com/mapbox/polylabel

There is not one port of it to Java, ... but three??

I am reluctant to add a Java dependency for this. Mabye someone would like to port this to platform independent Kotlin code (Kotlin multiplatform)?

It is about 200 lines of code (production code, not counting unit tests).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted help by contributors is appreciated; might be a good first contribution for first-timers
Projects
None yet
Development

No branches or pull requests

4 participants