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

Massive polygon throws an error from turf #14

Open
derrickpelletier opened this issue Mar 20, 2015 · 6 comments
Open

Massive polygon throws an error from turf #14

derrickpelletier opened this issue Mar 20, 2015 · 6 comments

Comments

@derrickpelletier
Copy link
Owner

Error: Each LinearRing of a Polygon must have 4 or more Positions.

When attempting to run the streaming example on the massive polygon.

@phatal
Copy link

phatal commented Aug 28, 2016

same problem (

@derrickpelletier
Copy link
Owner Author

@phatal This repo hasn't been updated in a while, but you might try changing the dependency for turf to some of the more recent versions to see if they've corrected what might have caused the issues.

@phatal
Copy link

phatal commented Aug 28, 2016

@derrickpelletier Actually I found solution :) stringify coordinates array before sending them from parsed *.geojson. That helped me.

@derrickpelletier
Copy link
Owner Author

Oh interesting, so the coordinates array is actually a string? When i try that with the examples/streaming.js file, and change the massive poly to massive = JSON.stringify(massive) i continue to get the same error.

@phatal
Copy link

phatal commented Aug 28, 2016

@derrickpelletier Code that almost worked for me. At least it's accept my coordinates array. Look strange why we need stringify and then parse it again, but it work ))
`var hasher = require('../index'),
async = require('async'),
through2 = require('through2'),
ngeohash = require('ngeohash'),
queue = require('queue-async'),
fs = require('fs');

var currDir = process.cwd();
var inputDir = 'input';
var outputDir = 'output';
var fileName = 'world_level2_test.geojson';
var inputFilePath = currDir+'/'+inputDir+'/'+fileName;

var worldData = JSON.parse(fs.readFileSync(inputFilePath));

var n = worldData.features.length;
var i = 0;
var q = queue();

function convertMe(polygonArray){
var toWrite = '';

var polygon = JSON.parse(polygonArray);
var isFirst = true;
var printFeature = function (name, poly) {
  var out = {
    "type": "Feature",
    "properties": {
      'name': name,
    },
    "geometry": {
      "type": "Polygon",
      "coordinates": poly
    }
  };
  out = JSON.stringify(out);
  if(!isFirst) {
    out = ',' + out
  }
  isFirst = false;

  toWrite = toWrite + out;
}
toWrite = toWrite + '{"type": "FeatureCollection","features": [';
async.mapSeries([polygon], function (poly, cb) {

  var options = {
    coords: poly,
    precision: 6,
    rowMode: true,
    hashMode: 'extent',
    //threshold: 0.2
  };
  printFeature('shape', poly);
  var rowStream = hasher.stream(options),
    a = 0;

  rowStream
    .on('end', cb)
    .pipe(through2.obj(function (arr, enc, callback) {
      for(var i = 0; i < arr.length; i++) {
        var bb = ngeohash.decode_bbox(arr[i]);
        printFeature(arr[i], [
              [
                [bb[1], bb[2]],
                [bb[3], bb[2]],
                [bb[3], bb[0]],
                [bb[1], bb[0]],
                [bb[1], bb[2]]
              ]]);
      }
      callback();
      toWrite = toWrite + ']}';

    }));
}, function () {

  return toWrite;
});

};

worldData.features.forEach(function(feature){
q.defer(function(done){
var dataToConvert = JSON.stringify(feature.geometry.coordinates);
console.log('Start');
console.log(convertMe(dataToConvert));
fs.writeFileSync(currDir+'/'+outputDir+'/'+'cell_'+i+'.s2', dataToWrite);
i++;
done();
console.log('Finish');
});
});`

But I have problem with asynchronous call in foreach =/ convertMe(dataToConvert) always return undefined, i know that asynchronous call, but dunno how to fix it to get it work.

@ararog
Copy link

ararog commented Jan 4, 2017

I used multiPolygon and my polygon worked as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants