mapbox / mapbox/mapbox-java

TurfsJoins pointsWithinPolygon => Need more informations

Open
#1,311 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
438
Forks
117
PR merge metrics
No merged PRs in 30d

Description

Hello !
First of all, thank you for your work!

I have a service that transforms data into geojson.
I have points and polygons. I want to check if the points are in the polygons. For this, I use "TurfJoins.pointsWithinPolygon()".
But when I pass my two FeatureCollections as parameters, it returns an empty list. Maybe I forgot something?
After several hours of searching, I decide to turn to you. I thank you in advance for your help. I code in Kotlin

class PointWithinPolygonService @Autowired constructor (val tblPolygonRepository: TblPolygonRepository, val pointsService: PointsService) {
     fun withinPolygon(): FeatureCollection {
        val polygons = tblPolygonRepository.findAll()
        val points = pointsService.getPoints()

        val pointsFeatureCollection = FeatureCollection
                .fromFeatures(points
                .filter { it.gpsLongitude != null }
                .map { Feature.fromGeometry(Point.fromLngLat(BigDecimal(it.gpsLongitude!!).setScale(4, RoundingMode.CEILING).toDouble(), BigDecimal(it.gpsLatitude!!).setScale(4, RoundingMode.CEILING).toDouble()))
        })
         
         val polygonsFeatureCollection = FeatureCollection
             .fromFeature(Feature
                 .fromGeometry(Polygon
                     .fromLngLats(polygons
                         .map {it.getListCoordinates()?.map { it -> Point.fromLngLat(it.longitude, it.latitude) } }))
             )
        return TurfJoins.pointsWithinPolygon(pointsFeatureCollection, polygonsFeatureCollection)
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at TurfJoins.pointsWithinPolygon and compare the supplied FeatureCollection construction with the method's expected polygon coordinates; inspect the Kotlin service code shown, especially filtering and coordinate order. Reproduce the empty result with the same points and polygons, and consider the issue done when the cause is identified and the method returns the expected points or the required input correction is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.