The library offers comprehensive functionalities to process geographic information files, parsing them into a structured JSON format. By invoking the provided methods, users can easily navigate through the geographical and attribute data associated with each geofile contained within a designated folder.
Install the package via npm:
npm install @lbdudc/gp-geographic-info-reader
This library simplifies the reading and processing of geographic information files. To utilize its functionalities:
-
Input: Refer to the "Input" section to understand the supported file formats and their requirements.
-
Initialization: Create an instance of the Processor class, configuring it with the desired options.
-
Path Specification: Provide the path to the folder containing the geographic information files to the Processor instance.
-
Output: Check the "Output" section for details on the generated output structure and file formats.
Once initialized and provided with the necessary inputs, the Processor will generate a comprehensive JSON representation. This representation includes both geographical and attribute data associated with each geographic info file.
import Processor from "@lbdudc/gp-geographic-info-reader";
// Define the path to the folder containing the geographic information files
const inputPath = "./examples/shpfiles";
const outputPath = "./examples"; // By default, the output path is the same as the inputPath appended with '/output'
// Create a new Processor instance with customizable options
const processor = new Processor({
encoding: "utf-8", // Set the file encoding: 'auto' (default), 'ascii', 'utf8', 'utf-8', 'latin1', 'binary', 'base64', 'hex'
geographicInfo: false, // Include geographic information in the output (default: true)
outputPath: outputPath, // Optional: designate a specific folder for processed geographic info files
});
// Process the folder containing the geographic info files
processor.processFolder(inputPath).then((content) => {
// Returns an array of objects, each representing a file
// Refer to the Output JSON section for more information
console.log(content);
});
This library supports processing geographic data stored in different geographic information files format. It accepts:
- Individual files with extensions:
.shp
,.cpg
,.dbf
,.prj
,.qpj
,.shx
. - Compressed data with Geographic information in a
.zip
file.
The library efficiently handles these inputs for easy manipulation and analysis of geographic data.
Note: Ensure associated files share the same base name for the file. Failure to do so may result in processing errors or incomplete data.
The output folder will contain the geographic information files zipped by their respective names.
Suppose you have a set of Shapefile files named:
example.shp
example.cpg
example.dbf
example.prj
example.qpj
example.shx
When processed using this library, the output folder will include a zip file named example.zip
, containing all these associated files.
The object returned by the processFolder method is an array of objects, one for each geographic info file. Each object contains the following properties:
[
{
"name": "01_shapefile",
"fileName": "01_shapefile.shp",
"schema": [
{
"name": "name",
"type": "Number || String || Boolean || Geometry ...",
"length": "Number"
}
],
"geographicInfo": {
"done": false,
"value": {
"type": "Feature",
"properties": {
"GEOID": 516864,
"FASE": "2000"
},
"geometry": {
"type": "MultiPoint",
"coordinates": [[568244.3307745245, 4782578.271440068]]
}
}
}
}
]
Explore additional examples in the examples folder:
npm run example
- jschardet: 3.0.0
- jszip: ^3.10.1
- shapefile: ^0.6.6
- @vitest/coverage-istanbul: ^0.32.2
- vitest: ^0.32.0
Victor Lamas Email: victor.lamas@udc.es
This project is licensed under the MIT License - see the LICENSE.md file for details