Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to convert Spatial layer data by csv in GIS Development

Shulou Source: shulou.com Published: 2022-06-01 12:30:48 09月16日 Update

In this issue, the editor will bring you about how csv converts spatial layer data in GIS development. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

In arcmap, excel or csv data can be processed into spatial point data, and nodejs language is used to convert csv files into geojson spatial layer data.

The specific implementation code is as follows:

/ / excel file can be saved as csv file

Const fs = require ('fs')

/ / npm install csv, import the development package of csv

Const csv = require ('csv')

/ / define the dataset node of geojson

Let geojsondata = {

Type: "FeatureCollection"

Features: []

}

/ / read csv file

Fs.readFile ('csv file path', {

Encoding: 'utf-8'

}, (err, res) = > {

Csv.parse (res, {

/ / sets the delimiter of the csv file

Delimiter:',

}, (err, records, info) = > {

/ / construct point feature according to the order of coordinate points in each record

For (let _ idx = 1; _ idx

< info.records; _idx++) { try { let _coordx = parseFloat(records[_idx][3]); let _coordy = parseFloat(records[_idx][4]); //构建点feature,空间类型为点数据 let pointfeature = { type: "Feature", geometry: { type: "point", coordinates: [_coordx, _coordy], }, //属性根据需求进行添加 properties: { id: String(new Date().getTime()), prop1: records[_idx][0], prop2: records[_idx][1] }, }; //将feature加入到集合中 geojsondata.features.push(pointfeature); } catch (error) { console.log(_idx); } } //将geojson的结果输出到文件 fs.writeFile("geojson文件输出", JSON.stringify(geojsondata), () =>

{

});

});

});

In addition, information such as coordinate system (crs) can be added in the root file of geojson.

Test the output geojson file in qgis to see if it is displayed correctly. This is how csv converts spatial layer data in GIS development shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Files data space development output content analysis specialty small and medium code information rich content delimiters coordinates coordinate systems namely attributes development packages data processing articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MariaDB Shulou Information macOS Shulou Technology