Unity中读取OpenStreetMap数据中的<way>元素属性
在Unity中,可以使用OSMSharp库来读取和处理OpenStreetMap数据。您可以使用以下代码来读取<way>元素的属性:
using OsmSharp;
// 创建一个OsmGeo对象来表示<way>元素
OsmGeo way = new Way();
// 设置<way>元素的属性
way.Tags.Add('LMID', '-2653203');
way.Tags.Add('RSID', '28');
way.Tags.Add('geometry', 'POLYGON');
way.Tags.Add('obstacle', 'no');
way.Tags.Add('oneway', 'yes');
way.Tags.Add('type', 'PARK_V');
// 读取<way>元素的属性
string lmid = way.Tags.GetValue('LMID');
string rsid = way.Tags.GetValue('RSID');
string geometry = way.Tags.GetValue('geometry');
string obstacle = way.Tags.GetValue('obstacle');
string oneway = way.Tags.GetValue('oneway');
string type = way.Tags.GetValue('type');
// 打印属性值
Debug.Log('LMID: ' + lmid);
Debug.Log('RSID: ' + rsid);
Debug.Log('geometry: ' + geometry);
Debug.Log('obstacle: ' + obstacle);
Debug.Log('oneway: ' + oneway);
Debug.Log('type: ' + type);
这样就可以读取<way>元素的tag属性并将其打印出来。请确保在使用此代码之前,您已经导入了OSMSharp库。
原文地址: https://www.cveoy.top/t/topic/nMGJ 著作权归作者所有。请勿转载和采集!