mapbox / geobuf

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

shp2geobuf TypeError: stream.on is not a function #105

Open andrewharvey opened 5 years ago

andrewharvey commented 5 years ago
/tmp/geobuf/node_modules/stream-source/index.node.js:8
  that._stream = stream.on("readable", read).on("end", end).on("close", end).on("error", error);
                        ^

TypeError: stream.on is not a function
    at new StreamSource (/tmp/geobuf/node_modules/stream-source/index.node.js:8:25)
    at module.exports (/tmp/geobuf/node_modules/stream-source/index.node.js:2:10)
    at open (/tmp/geobuf/node_modules/shapefile/dist/shapefile.node.js:310:14)
    at Object.read (/tmp/geobuf/node_modules/shapefile/dist/shapefile.node.js:358:10)
    at Object.<anonymous> (/tmp/geobuf/bin/shp2geobuf:7:11)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
metacollin commented 5 years ago

Hi @andrewharvey, I was having this issue as well, so I went ahead and fixed shp2geobuf by, uh, completely rewriting it. Use at your own risk, but it is working fine for me and in a production environment. I also added the ability to locate and include associated .dbf files automatically, or specify the path to one explicitly. A .dbf file is still optional of course.

Checkout the changes in my fork, metacollin/geobuf. If you are ok with risking it in your project (I make zero guarantees, I am not liable if it breaks your code, burns down your house, or murders your cat), you can install my fork:

npm install -g metacollin/geobuf
bwcastillo commented 4 years ago

@mourner that the issue is tagged as bug, does mean that this problem persist? If I use the lines: npm -install geobuf I get the same problem that @mourner (" stream.on is not a function), but if i use the @metacollin version I get "SyntaxError: missing ) after argument list.

I keep attent for any conclusion.

Regards!

bwcastillo commented 4 years ago

Now I have modified the Syntax in the last if (line 48) of @metacollin version: if(dbf_exists === true) { shapefile.read(shp_path, dbf_path).then(function(geojson){ var geobuf = encode(geojson, new Pbf()); var output_buffer = Buffer.allocUnsafe ? Buffer.from(geobuf) : new Buffer(geobuf); process.stdout.write(output_buffer); }); } else { shapefile.read(shp_path).then(function(geojson){ var geobuf = encode(geojson, new Pbf()); var output_buffer = Buffer.allocUnsafe ? Buffer.from(geobuf) : new Buffer(geobuf); process.stdout.write(output_buffer); })};

I get an output but when I try to open in QGIS this dont recognize the source. I opened the file in a text editor, and i found only weird characters. i.e:

ROUTE_NAME bbox"Êú¯ ’ ƒþ˜§‘ÏÜÄó‚üÞí­»Ë˜Ã¸Û¼Ð¦ýŠ낁¤ÛØ)ÛØè Ö‚Œ©²Š²² ±É¥9¬™ðvµý¦ÖäÇ ÃîêAú¨¢‹Ý»Î@–鵆ÏÅ©ºÖä1¹—“¤Ý‘7ÿîÞ’íü¿ÆߤÙà»Ø­г˜áÝÈÆÎÝ»¯iÄ˹«øüî©

I just recognize the first line "ROUTE_NAME"

kevinstadler commented 4 years ago

Got shp2geobuf to work by:

  1. installing metacollin's fork using npm install -g metacollin/geobuf and then
  2. (manually) applying the following patch: https://github.com/thomas-maschler/geobuf/commit/d46c39034348b1f075f89d8f045b3b36ba77656e