Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript

Home Page:https://turfjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to check if loop is closed using turf booleanValid in TypeScript?

karimfayed opened this issue · comments

I use TypeScript and currently I wish to validate a Geometry object.
I use booleanValid from turf package to ensure that the object is valid.(I currently use "@turf/boolean-valid": "^6.5.0")

const isGeometryValid: boolean = booleanValid(geometry as unknown as Geometry);

After testing I found out that the booleanValid only checks the Right-Hand Rule and doesn't check if the loop is closed.
The following array returned true even though the loop is not closed just because it satisfies the Right-Hand Rule:

[ [ [0,0], [10,0], [10,10], [0,10], [0,8] ] ]

I need a way to check all the validations for Geometry and not just one or some of them

There is some history to the booleanValid package that may give some context about why it is not listed in the documentation: #1918

I personally would say in it's current state not to rely on booleanValid for comprehensive GeoJSON validation. You could potentially look at packages such as https://github.com/placemark/check-geojson and https://github.com/mapbox/geojsonhint which may offer similar alternatives depending on your requirements.

@JamesLMilner

Thank you for your swift reply and sorry for mine being late.

I would like to ask if there is one of these you use or prefer and if there are other alternatives as both options you suggested don't have a high score on snykAdvisor.

I need to validate geometry objects before saving them into the database so if you wished to do the same which package would you use?