turf icon indicating copy to clipboard operation
turf copied to clipboard

Provide utility for geometry validation via bundled JSTS according to OGC rules

Open jayarjo opened this issue 4 years ago • 4 comments

Since TurfJS contains refactored JSTS anyway (quite outdated btw), why not use JSTS utilities for geometry validation? @turf/boolean-valid is nice small utility, but is not fully OGC compliant (although it is tagged with ogc in NPM repository - probably to attract attention) and frequently gives an opposite result to what JSTS validator would provide.

jayarjo avatar Oct 05 '21 15:10 jayarjo

As it stands we are actively trying to remove JSTS from turf. Currently we only use the buffer operation in @turf/buffer - where we would like to rewrite to avoid using JSTS.

Unfortunately although JSTS is fantastic, it produces enormous bundles (100s of kbs) for end users. This can be prohibitive for a lot of people.

@turf/boolean-valid does need a bit of love but I'm not sure using JSTS is the best way to approach that. Hope that makes sense!

JamesLMilner avatar Oct 05 '21 19:10 JamesLMilner

I see. Can't you do some tree-shaking on parts of JSTS that you do not use?

I was looking to somehow improve @turf/boolean-valid and drop JSTS for exactly same reason. Do you maybe know how JTS tests validity of its validation utilities maybe? We could potentially use the same set of tests and geometries to put @turf/boolean-valid straight finally.

jayarjo avatar Oct 06 '21 05:10 jayarjo

So JSTS is already tree-shaken via turf-jsts but unfortunately that still produces very large bundles - 350kb for @turf/buffer - https://bundlephobia.com/package/@turf/buffer. It would probably require figuring out the validation paths you are interested in and replicating the tests in Turf. Do you know the functions in JTS that you would look at using for validation?

JamesLMilner avatar Oct 06 '21 08:10 JamesLMilner

From what I see it all boils down to IsValidOp package and class. And I think I've located tests and resources that they use for those tests.

By the way ability to report reason and location for invalidity is also immensely useful.

jayarjo avatar Oct 07 '21 08:10 jayarjo