mapbox / geobuf

A compact binary encoding for geographic data.
ISC License
968 stars 84 forks source link

geojson convert to geobuf failed #74

Closed hoogw closed 7 years ago

hoogw commented 7 years ago

I use windows. in command line window, I type:

node \jh\other_map_geojson\node_modules\geobuf\bin\json2geobuf city_zoning.geojson > city_zoning.pbf

I got a 0 size pbf file. the error is:

C:\jh\other_map_geojson\Raw_geojson\CostaMesa>node \jh\other_map_geojson\node_mo dules\geobuf\bin\json2geobuf city_zoning.geojson > city_zoning.pbf

C:\jh\other_map_geojson\node_modules\geobuf\bin\json2geobuf:20 var buffer = Buffer.from(encode(geojson, new Pbf())); ^ TypeError: Object function Buffer(subject, encoding, offset) { if (!(this instanceof Buffer)) { return new Buffer(subject, encoding, offset); }

var type;

// Are we slicing? if (typeof offset === 'number') { if (!Buffer.isBuffer(subject)) { throw new TypeError('First argument must be a Buffer when slicing'); }

this.length = +encoding > 0 ? Math.ceil(encoding) : 0;
this.parent = subject.parent ? subject.parent : subject;
this.offset = offset;

} else { // Find the length switch (type = typeof subject) { case 'number': this.length = +subject > 0 ? Math.ceil(subject) : 0; break;

  case 'string':
    this.length = Buffer.byteLength(subject, encoding);
    break;

  case 'object': // Assume object is array-ish
    this.length = +subject.length > 0 ? Math.ceil(subject.length) : 0;
    break;

  default:
    throw new TypeError('First argument needs to be a number, ' +
                        'array or string.');
}

if (this.length > Buffer.poolSize) {
  // Big buffer, just alloc one.
  this.parent = new SlowBuffer(this.length);
  this.offset = 0;

} else if (this.length > 0) {
  // Small buffer.
  if (!pool || pool.length - pool.used < this.length) allocPool();
  this.parent = pool;
  this.offset = pool.used;
  // Align on 8 byte boundary to avoid alignment issues on ARM.
  pool.used = (pool.used + this.length + 7) & ~7;

} else {
  // Zero-length buffer
  this.parent = zeroBuffer;
  this.offset = 0;
}

// optimize by branching logic for new allocations
if (typeof subject !== 'number') {
  if (type === 'string') {
    // We are a string
    this.length = this.write(subject, 0, encoding);
  // if subject is buffer then use built-in copy method
  } else if (Buffer.isBuffer(subject)) {
    if (subject.parent)
      subject.parent.copy(this.parent,
                          this.offset,
                          subject.offset,
                          this.length + subject.offset);
    else
      subject.copy(this.parent, this.offset, 0, this.length);
  } else if (isArrayIsh(subject)) {
    for (var i = 0; i < this.length; i++)
      this.parent[i + this.offset] = subject[i];
  }
}

}

SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length); } has no method 'from' at C:\jh\other_map_geojson\node_modules\geobuf\bin\json2geobuf:20:25 at ConcatStream. (C:\jh\other_map_geojson\node_modules\geobuf\nod e_modules\concat-stream\index.js:36:43) at ConcatStream.emit (events.js:117:20) at finishMaybe (C:\jh\other_map_geojson\node_modules\geobuf\node_modules\con cat-stream\node_modules\readable-stream\lib_stream_writable.js:475:14) at endWritable (C:\jh\other_map_geojson\node_modules\geobuf\node_modules\con cat-stream\node_modules\readable-stream\lib_stream_writable.js:485:3) at ConcatStream.Writable.end (C:\jh\other_map_geojson\node_modules\geobuf\no de_modules\concat-stream\node_modules\readable-stream\lib_stream_writable.js:45 5:41) at ReadStream.onend (_stream_readable.js:502:10) at ReadStream.g (events.js:180:16) at ReadStream.emit (events.js:117:20) at _stream_readable.js:944:16

mourner commented 7 years ago

What Node version are you using? Can you try Node v4+?

hoogw commented 7 years ago

C:\jh\other_map_geojson>node -v v0.10.36

Good catch, my node version is too old. now I am update it to

C:\jh\other_map_geojson>node -v v6.9.1

I try: node \jh\other_map_geojson\node_modules\geobuf\bin\json2geobuf \jh\other_map_geojson\Raw_geojson\city_parcels.geojson > \jh\other_map_geojson\Raw_geojson\city_parcels.pbf

It works perfect!!!

Thank you so much, I stuck 8 hours didn't figure out it is version problem.