Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
The shapefile npm package is used for reading and parsing shapefiles, which are a popular geospatial vector data format for geographic information system (GIS) software. This package allows you to read shapefiles and convert them into GeoJSON format, making it easier to work with geospatial data in JavaScript applications.
Reading Shapefiles
This feature allows you to read a shapefile and log its contents. The code opens a shapefile, reads its records, and logs each record to the console.
const shapefile = require('shapefile');
shapefile.open("path/to/shapefile.shp")
.then(source => source.read()
.then(function log(result) {
if (result.done) return;
console.log(result.value);
return source.read().then(log);
}))
.catch(error => console.error(error));
Converting Shapefiles to GeoJSON
This feature allows you to convert a shapefile directly to GeoJSON format. The code reads a shapefile and converts its contents to GeoJSON, which is then logged to the console.
const shapefile = require('shapefile');
shapefile.read("path/to/shapefile.shp")
.then(geojson => console.log(JSON.stringify(geojson)))
.catch(error => console.error(error));
shpjs is a JavaScript library for reading shapefiles in the browser. It can read both .shp and .dbf files and convert them to GeoJSON. Compared to shapefile, shpjs is more focused on client-side usage and is suitable for web applications that need to handle shapefiles directly in the browser.
Terraformer is a modular toolkit for working with geographic data in JavaScript. It includes tools for reading and writing GeoJSON, as well as converting between different geospatial formats. While it does not specifically focus on shapefiles, it provides a broader set of tools for geospatial data manipulation compared to shapefile.
gdal (Geospatial Data Abstraction Library) is a powerful library for reading and writing raster and vector geospatial data formats. The gdal npm package provides bindings to the GDAL library, allowing you to work with a wide range of geospatial data formats, including shapefiles. It is more comprehensive and feature-rich compared to shapefile, but also more complex to use.
Based on the ESRI Shapefile Technical Description and dBASE Table File Format.
Caveat emptor: this library is a work in progress and does not currently support all shapefile geometry types (see shp.js for details). It also only supports dBASE III and has no error checking. Please contribute if you want to help!
# shapefile.read(filename[, options], callback)
A convenience API for reading an entire shapefile in one go. Use this method if you don’t mind putting the whole shapefile in memory; use reader instead if you want to process records individually. The specified callback with two arguments:
The collection has a bbox
property containing representing the bounding box of all records in this shapefile. The bounding box is specified as [xmin, ymin, xmax, ymax], where x and y represent longitude and latitude in spherical coordinates.
# shapefile.reader(filename[, options])
The main API for reading a shapefile. The supported options are:
This method returns a reader object.
# reader.readHeader(callback)
Reads the shapefile header, invoking the specified callback with two arguments:
The header object is simply an object with a bbox
property representing the bounding box of all records in this shapefile. The bounding box is specified as [xmin, ymin, xmax, ymax], where x and y represent longitude and latitude in spherical coordinates.
# reader.readRecord(callback)
Reads the next shapefile record, invoking the specified callback with two arguments:
The record object is a GeoJSON feature. (GeoJSON objects are the standard representation of geometry in JavaScript, and they are convenient. If you want to access the shapefile primitives directly, use the private shp and dbf classes instead.)
If there are no more records in this shapefile, the record is the special value shapefile.end.
# reader.close(callback)
Closes the underlying files for this reader. You should call this when you are done reading. If an error occurs during readHeader or readRecord, the reader will be closed automatically.
# shapefile.end
A sentinel value used readRecord to indicate that the end of the file has been reached, and no more records are available. (Note that if the end of file is reached when readHeader is called, this is considered an error because the header is required by the shapefile format.)
FAQs
An implementation of the shapefile (.shp) spatial data format.
The npm package shapefile receives a total of 149,873 weekly downloads. As such, shapefile popularity was classified as popular.
We found that shapefile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.