Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert Spatial layer data by csv in GIS Development

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report