2

I'm trying to automatically remove a self-intersection from a geojson file. Another stackexchange site suggested I use a package called turf.

I'm not quite familiar with how I should set up the IO. The file I am trying to fix is here:

I am trying this:

const fname="ks_kansas_zip_codes_geo.min.json";
const fout="fixed_kansas.json";
const turf = require('@turf/turf');
const fs = require('fs');
var tmp = fs.readFile(fname, function(err, x) {
   var fixed = turf.unkinkPolygon(turf.polygon(x));
   console.log(fixed);
   return(fixed)
  });
// fs.writeFileSync(fout, tmp);

The error I get is:

Error: coordinates is required
   at polygon (/home/username/node_modules/@turf/helpers/main.js:229:29)

The error I get is:

undefined
> { type: 'FeatureCollection', features: [] }

> tmp
undefined

Not really sure how to use this library to operate on a geojson file. I see a couple of other examples, but nothing end-to-end that would help me even load it so I can make what I'm looking for, which is more like:

node myscript.js ks_kansas_zip_codes_geo.min.json fixed_ks.json
Mittenchops
  • 18,633
  • 33
  • 128
  • 246

0 Answers0