Turf: valid

Created on 31 Dec 2013  路  15Comments  路  Source: Turfjs/turf

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

enhancement

Most helpful comment

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. https://github.com/Turfjs/turf/pull/1302 has been merged since a few months but package is still unpublished. What are the next steps ? :)

All 15 comments

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

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

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

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.

this is nice.

some sort of st_makevalid would be even nicer

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

How I can add in turf?

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?

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.

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

@morganherlocker That's a long tomorrow 馃ぃ

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.

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

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

@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

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. https://github.com/Turfjs/turf/pull/1302 has been merged since a few months but package is still unpublished. What are the next steps ? :)

Was this page helpful?
0 / 5 - 0 ratings