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

valid #64

Closed
morganherlocker opened this issue Dec 31, 2013 · 20 comments
Closed

valid #64

morganherlocker opened this issue Dec 31, 2013 · 20 comments
Milestone

Comments

@morganherlocker
Copy link
Member

function for checking if a given geojson object is valid. This might be possible with jsts, or with some sort of linter module.

@ghost ghost assigned morganherlocker Dec 31, 2013
@derrickpelletier
Copy link

+1 for this
I currently use QGIS for this and find it quite a hassle.

@morganherlocker
Copy link
Member Author

I will give this a crack tomorrow. I will probably plug into geojsonhint.

@derrickpelletier
Copy link

Ah, I may have read into it too much in my excitement. I thought you were meaning validity in terms of polys—i.e. having no intersections or duplicate points or whatnot.

@morganherlocker
Copy link
Member Author

mapshaper does this, which I think is integrated into topojson (which is already a dependency of turf), so the features you are looking for may actually be pretty easy to implement. I will add another feature issue called "fix", which will identify and fix issues like you are describing here.

@morganherlocker
Copy link
Member Author

Here is the new issue:

#87

@morganherlocker morganherlocker modified the milestone: 1.0 features Dec 9, 2014
@vlasvlasvlas
Copy link

this is nice.

some sort of st_makevalid would be even nicer

@blackrez
Copy link

blackrez commented Dec 7, 2015

Hello, I implemented the ST_isvalid of postgis : https://github.com/blackrez/turf-isvalid.

How I can add in turf?

@stebogit
Copy link
Collaborator

Is this geojson validator still of interest @morganherlocker ?
I know jsts is a goner, so we might want to implement this with geojsonhint instead.

@DenisCarriere @rowanwins is this material for booleans?

@rowanwins
Copy link
Member

It's still interesting from my perspective @stebogit

I think this module probably requires more than geojsonhint and yep would probably fit in the booleans collection.

Off the top of my head it's probably a combination of

  • geojsonhint
  • @turf/kinks for id'ing self-intersections
  • check for duplicate points
  • plus a bunch of other checks!

Some good background reading here from the postgis world.

@DenisCarriere
Copy link
Member

I will give this a crack tomorrow. I will probably plug into geojsonhint.

@morganherlocker That's a long tomorrow 🤣

@DenisCarriere
Copy link
Member

DenisCarriere commented Aug 11, 2017

is this material for booleans? (@stebogit)

It could be... 🤔 this would simply be a module which would throw an error (or return a Boolean true/false) if the GeoJSON is valid or not.

@DenisCarriere
Copy link
Member

I know jsts is a goner

Yes, however it might be worth looking into how jsts handles it's isValid method. Or at least add it to the test.js cases (same as shapely).

@rowanwins
Copy link
Member

rowanwins commented Mar 3, 2018

FYI I've made a good start on this. Basically I'm looking at using the OGC simple feature spec.

I do however have a question about the most helpful API. So here are my options

  1. I could do it as a boolean style module (eg simply return true or false for a feature validity).
  2. I could add properties to a feature showing which validity checks have passed or failed. This is obviously more useful in providing info (eg did the poly fail because start and end points weren't the same or because the polygon hole touched the exterior ring twice).
  3. I could throw an error on the first error encountered with the details, downside to this is that a single geometry might have multiple issues and but by throwing an error we'd only report on the first one encountered.

Any other ideas on this one @DenisCarriere , @stebogit , @morganherlocker

@stebogit
Copy link
Collaborator

stebogit commented Mar 4, 2018

@rowanwins although you wouldn't be able to use a clean

if (turf.valid(geojson) {
// ...
}

I think throwing an error would be the best way to have an informative message about why the feature is invalid. I'm not sure we want a breaking behavior, but it might make sense since Turf is only supposed to work on valid GeoJSON

@fbnfgc
Copy link

fbnfgc commented Nov 16, 2018

Hi there and thanks to all contributors, turf is a great project.

I am looking to a way to validate GeoJSON to avoid side effects when using Polygon and MultiPolygon transformations. #1302 has been merged since a few months but package is still unpublished. What are the next steps ? :)

@florinvirdol
Copy link

Hi,
Any updates on this one?
Thanks!

@twelch
Copy link
Collaborator

twelch commented Jan 1, 2022

I've been piecing together the status of this for my own awareness and thought I'd give an update.

turf-boolean-valid is available as an individual package (https://www.npmjs.com/package/@turf/boolean-valid) for folks to use, but is not yet included in the top-level turf library or part of the docs because it wasn't seen as ready. More detail in the PR that was merged (#1302).

One suggestion is to narrow the scope of this long running ticket to getting boolean-valid to minimum usefulness and save the rest for add-on issues. Currently it has a few types of geometry validation and that's it - https://github.com/Turfjs/turf/blob/master/packages/turf-boolean-valid/index.ts

Suggested tasks:

  • Better validation to the geojson spec
  • Deeper geometry validation.
  • Add boolean-valid in the top-level turf library.
  • Make sure the docs are in order.

Optional or create as add-on tickets:

  • Returning individual error reason strings. Might be out of scope (it is a boolean method after all). It could be a separate function like PostGIS's ST_isValidReason.
  • Break down the overall validation function (default export) into pieces, and offer additional functions as named exports e.g. isValidGeometry, isValidPolygon. Consider doing this in a way that will minimize breaking changes in the future.

@twelch twelch added this to the 7.0.0 milestone Jan 1, 2022
@stebogit
Copy link
Collaborator

stebogit commented Jan 4, 2022

Thanks @twelch for the update.
My 2c: I think a boolean validator is not very useful if it does not help you understanding why the feature is not valid (so you can fix/handle the error). So I'd refactor the module to throw with an error message - or even better an error code so you can programmatically handle it - in case of failure and make that a main task in the suggested list.
Finally, to make it more flexible and easier to maintain, as additional main task I'd suggest to convert this to an equivalent to the @turf/helpers package but for validation (i.e. @turf/validation) with several functions (like the mentioned isValidGeometry, isValidPolygon, etc., all throwing errors) the use can selectively decide to use. We could still have a comprehensive isValid as one of those functions though.
Finally, check-geojson seems very interesting, however it also looks like it is very new and the API is likely to change so I would probably wait a bit before including it as dependency - even though at the time this issue will get resolved the API might be super stable 😅.

@smallsaucepan
Copy link
Member

Quick update for this 10 year old issue 🎂 🎉

Wondering what we should do with this one. Per @stebogit 's comment above users probably want better feedback on what went wrong. Perhaps we leave turf-boolean-valid as is and refer users to check-geojson or geojsonhint if they need more detail?

@smallsaucepan
Copy link
Member

No new discussion on this idea for several months. Closing.

@smallsaucepan smallsaucepan closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests