kml文件转成cvs_将KML坐标转换为CSV或XML

Is there a way to convert/parse a KML file''s coordinates into a format (CSV or XML) that I could later use to import into other programs.

I have polygons in KML files and I''m trying to reuse the coordinates with other programs in different formats.

In my KML file I have coordinates that look like this.

-86.36762,37.31916,0 -86.43890,37.31916,0 -88.96934,32.11572,0 -84.51434,32.68596,0 -82.87490,35.85792,0 -86.36762,37.31916,0

How do I search the KML file and convert the coordinates to a format like this

-86.36762,37.31916,0

-86.43890,37.31916,0

-88.96934,32.11572,0

-84.51434,32.68596,0

-82.87490,35.85792,0

-86.36762,37.31916,0

and save it in a CSV using C#?

Any help would be much appreciated. I''m able to find ways to convert CSV to KML no problem but what about the other way around.

Thanks

解决方案If the requirement is to break the set of coordinates into separate lines, then the Replace method of Regex class can be used to replace the spaces which are not preceded by or followed by a commaas shown below:

string kmlInput = @"-86.36762, 37.31916 , 0 -86.43890,37.31916,0 -88.96934,32.11572,0 -84.51434,32.68596,0 -82.87490,35.85792,0 -86.36762,37.31916,0 ";

string csvOutput = Regex.Replace(kmlInput,

@"(?<=[^,]+)\s+(?=[^,]+)","\n",

RegexOptions.CultureInvariant);

Console.WriteLine (csvOutput);

//csvOutput

//-86.36762, 37.31916 , 0

//-86.43890,37.31916,0

//-88.96934,32.11572,0

//-84.51434,32.68596,0

//-82.87490,35.85792,0

//-86.36762,37.31916,0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值