Comments (2)
Seems reasonable. I feel like this would work, too:
export default class ShapefileStream extends Readable {
constructor(shapeFilePath) {
super({objectMode: true});
this.source = shapefile.open(shapeFilePath);
}
_read() {
this.source.then(source => {
source.read().then(result => {
this.push(result.done ? null : result.value);
});
});
}
}
from shapefile.
I came up with this solution:
// ShapefileStream.js
import { Readable } from 'stream';
const shapefile = require('shapefile'); // undefined when use `import`?
export default class ShapefileStream extends Readable {
constructor(shapeFilePath) {
super({objectMode: true});
this.shapeFilePath = shapeFilePath;
this.source = null;
}
async readStream() {
if (!this.source) {
this.source = await shapefile.open(this.shapeFilePath);
}
return await this.source.read();
}
_read() {
this.readStream().then((result) => {
if (result.done) {
this.push(null);
} else {
this.push(result.value);
}
})
}
}
and then..
import ShapefileStream from './ShapefileStream';
const readStream = new ShapeReadStream('./my/shapefile/path.shp');
readStream.pipe(myTransformStream)
.pipe(myTransformStream2)
.pipe(myWritableStream);
readStream.on('end', () => {
console.log('read complete');
})
from shapefile.
Related Issues (20)
- It does not support uppercase SHP extention HOT 1
- Reading from File / Blob? HOT 7
- unable to convert shp to topojson and plot in d3 HOT 2
- Properties of shapefile is null when convert big shapefile HOT 1
- Reproject output to EPSG:4326 by default. HOT 1
- text-encoding has been marked with a warning
- GeoJson is malformed when using #openShp HOT 1
- 不兼容IE,报错:TextDecoder未定义
- Support retrieving z values HOT 1
- Holes stick to outside area are not read accordingly HOT 3
- Differing results between shapefile and mapshaper conversion HOT 4
- Error: error in unzip: code 9 HOT 6
- MultiGeometry Shape
- Can’t fetch URLs that don’t have .shp/.dbf extensions. HOT 2
- Support other winding conventions (cw, ccw, spherical, etc.) HOT 3
- Using with React native.
- shapefile RangeError: Offset is outside the bounds of the DataView HOT 7
- Numeric column coming in as NULL property
- Parsing dbf file returns unexpected null values HOT 3
- NodeJS 18 Error Reading Files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shapefile.