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

TurfsJoins pointsWithinPolygon => Need more informations #1311

Open
Bjmn7 opened this issue Oct 27, 2021 · 0 comments
Open

TurfsJoins pointsWithinPolygon => Need more informations #1311

Bjmn7 opened this issue Oct 27, 2021 · 0 comments

Comments

@Bjmn7
Copy link

Bjmn7 commented Oct 27, 2021

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)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant