最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

GIS開發(fā):mysql空間數(shù)據(jù)導(dǎo)出geojson

2022-07-06 09:07 作者:地理信息技術(shù)雜談  | 我要投稿

使用nodejs,實(shí)現(xiàn)將mysql數(shù)據(jù)庫中的空間數(shù)據(jù)表,導(dǎo)出成geojson的矢量圖層文件,保存。

安裝fs、wellknow和mysql三個(gè)nodejs類庫:

let?fs?=?require("fs");

let?parset?=?require('wellknown');

let?mysql?=?require('mysql');?

//創(chuàng)建mysql的數(shù)據(jù)庫連接

let?connection?=?mysql.createConnection({

?//主機(jī)地址?(

host?????:?'localhost',

//用戶名

user?????:?'root',

//密碼

password?:?'******',

//在mysql中創(chuàng)建的數(shù)據(jù)庫名

database?:?'database'

});

//連接到數(shù)據(jù)庫

connection.connect();

//?var?tabletype;

let?tabledata?=?[];

//查詢空間坐標(biāo)的數(shù)據(jù),并保存

?const?sqlb="select?st_ASTEXT(geometry)?AS?geo?from?dbname";

connection.query(sqlb,?function?(error,?results,?fields)?{

????for(let?k=0;k<results.length;k++){

? ? ??let?tst={};

??????tst?=parset(results[k].geo);

??????tabledata.push(tst);

????}?

});

//查詢空間數(shù)據(jù)表中的其他屬性字段數(shù)據(jù),并保存

let?sql="select?*?from?dbname";

connection.query(sql?,?function?(error,?results,?fields)?{

????let?dataJson??=?results;

? ??let?features=[];

? ??let?name?=[];

? ??let?n?=0;?

????for(let?t?in?dataJson[0]?)?{

????????n++;

????????name[n]?=t;

????}

????//將數(shù)據(jù)庫中的數(shù)據(jù),拼接成geojson的格式

????for(let?i=0;i<dataJson.length;i++){

? ? ? ??let?fdata?=?{};

? ? ? ??let?pdata?=?{};

????????fdata["type"]="Feature";

????????fdata["properties"]?=pdata;

????????for(let?j=1;j<name.length-1;j++){

?????????pdata[name[j]]?=dataJson[i][name[j]];

????????}

????????fdata["geometry"]?=tabledata[i];

????????features.push(fdata);

????}

?//添加geojson的數(shù)據(jù)頭信息

???var?road?=?[]?;

???var?roaddata?={};

???roaddata["type"]?="FeatureCollection";

???roaddata["name"]?="roadcenter";

???roaddata["crs"]?=?{?"type":?"name",?"properties":?{?"name":?"urn:ogc:def:crs:OGC:1.3:CRS84"?}?};

???roaddata["features"]?=features;

???road.push(roaddata);

//保存geojson文件

???var?roadjson?=JSON.stringify(roaddata);

???fs.writeFileSync('filepath',roadjson);

});


GIS開發(fā):mysql空間數(shù)據(jù)導(dǎo)出geojson的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
顺义区| 浦县| 麟游县| 大足县| 迁西县| 东丰县| 永城市| 双辽市| 辽宁省| 鹿邑县| 武夷山市| 乌鲁木齐市| 临汾市| 成都市| 千阳县| 渭南市| 资源县| 鄂托克旗| 宜黄县| 清丰县| 思茅市| 东光县| 来凤县| 独山县| 黄陵县| 桂平市| 筠连县| 江永县| 大城县| 水城县| 大关县| 台山市| 红安县| 资兴市| 高邮市| 福建省| 浙江省| 南京市| 杭锦旗| 丹寨县| 平陆县|