Read and write Shapefile SHP and SHX files within Node JS.
IMPORTANT: This is an ESM NodeJS only package.
A Shapefile is a selection of files grouped together into a ZIP file.
Each file contains different information that together is used to detail geographic map information.
It comes with a *.shp file that gives the vector data, a *.shx file that is an index of the vector data,
and a *.dbf file that is a dBase 3 database file containing attribute data about the different map areas.
This package is used to read and write the *.shp and *.shx data.
Each type of shape has its own class object, which allows you to create a Shapefile SHP object and have it written to a file (with the index).
The simplist method of loading in all the shapefile SHP data is to use the load function.
Here we are using the index file to quickly find the location of the third polygon and read it in.
Below are the different shape type objects that can be used. You will need to search for the shapefile file format to better understand how the information is used to create map information.
There are some static functions that can help you perform some quick tasks.
Load all the vector data from the shapefile SHP file into a ShapefileShp object.
A promise that resolves with a ShapefileShp object.
Save the ShapefileShp object to a shapefile SHP file.
This also creates the *.shx index file.
ShapefileShp object that contains all the shape information.
A promise.
This class is used to read in shapefile SHP data.
Open the shapefile SHP file.
A promise.
Close the already opened shapefile SHP file.
A promise.
Read in the next shape within the shapefile SHP file.
A promise resolving to a one of the available shape objects, or null if the end of the file is reached.
There are a number of different properties available.
After opening the file you can get the shapefile SHP header information.
After reading in a record you can get it's record number value, which starts at 1.
After reading in a record you can get the total content length (in bytes) that was read in.
After reading in the record you can get the offset of the record where it was located within the SHP file.
This class is used to create shapefile SHP data.
Open the shapefile SHP file to write to. This will remove any existing file.
A promise.
Close the shapefile SHP file.
A promise.
Write a shape object to the shapefile SHP file.
A promise.
Update the ShapefileSHP object header information in the shapefile SHP file.
As you write more and more shapes to the file, the overall file length will increase.
Also, the minimum and maximum ranges will also be updated.
After you have finished writing all the shapes to the file, you can update the properties within the ShapefileShp object and have it written to the file.
A promise.
There are a number of different properties available.
After writing a record you can get it's record number value, which starts at 1.
After writing a record you can get the total content length (in bytes) that was just written in.
After writing the record you can get the offset of the record where it is located within the SHP file.
This class is used to read in shapefile SHX index files.
Open the shapefile SHX file.
A promise.
Close the shapefile SHX file.
A promise.
Read in the next shape index within the shapefile SHX file.
A promise resolving to a ShapeIndex object or null if the end of the file is reached.
There are a number of different properties available.
After the file has been open you can get the ShapefileShx header object.
This class is used to create shapefile SHX index files.
Open the shapefile SHX index file to write to. This will remove any existing file.
A promise.
Close the shapefile SHX file.
A promise.
Write new index information to the shapefile SHX file.
A promise.
Update the ShapefileShx object header information in the shapefile SHX file.
As you write more and more indexes to the file, the overall file length will increase.
You may also need to update the minimum and maximum ranges.
After you have finished writing all the indexes, you will need to update the ShapefileShx object and have it written to the SHX file.
A promise.