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


版权声明:本文为weixin_39796363原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。