小编use*_*726的帖子

Ruby Nokogiri将KML转换为CSV

我正在尝试从KML文件中提取两个不同的元素,然后将它们转换为CSV。我从这里的好网站开始:http : //ckdake.com/content/2012/highgroove-hack-night-kml-heatmaps.html,它会生成一个csv的坐标。我现在要做的就是将名称标签添加到每一行的开头。我是ruby / nokogiri n00b,所以我可以粘贴这段代码,在其中获得a)所有名称的列表,然后b)所有坐标的列表。但是,再次-我希望他们在同一行。

require 'rubygems'
require 'nokogiri' # gem install nokogiri

@doc = Nokogiri::XML(File.open("WashingtonDC2013-01-04 12h09m01s.kml"))

@doc.css('name').each do |name|  
  puts name.content
end

@doc.css('coordinates').each do |coordinates|
  coordinates.text.split(' ').each do |coordinate|
    (lat,lon,elevation) = coordinate.split(',')
    puts "#{lat},#{lon}\n"
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby csv kml nokogiri

4
推荐指数
1
解决办法
1453
查看次数

尝试使用 Python 请求将 xml 文件发送到 OpenStreetMap Overpass API

我有一个 .xml 请求,可以成功地从 OpenStreetMap Overpass API 检索数据。

<?xml version="1.0" encoding="UTF-8"?>
<osm-script>
<query type="node">
    <has-kv k="name" v="Bethesda"/>
    <has-kv k="network" v="Washington Metro"/>
</query>
<query type="way">
    <around radius="800"/>
    <has-kv k="building"/>
</query>
<union>
    <item/>
    <recurse type="down"/>
</union>
<print/>
</osm-script>
Run Code Online (Sandbox Code Playgroud)

我现在尝试(但失败)要做的就是通过 Python 请求库发送这个 xml(我对其他 Python 解决方案持开放态度)。我发送以下请求:

files = {'file': ('Bethesda.xml', open('Bethesda.xml', 'rb'))}
r = requests.post('http://overpass-api.de/api/interpreter', data=files)
print r.text
Run Code Online (Sandbox Code Playgroud)

但收到以下错误消息:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" lang="en"/>
  <title>OSM3S Response</title>
</head>
<body>

<p>The …
Run Code Online (Sandbox Code Playgroud)

python openstreetmap

1
推荐指数
1
解决办法
3511
查看次数

标签 统计

csv ×1

kml ×1

nokogiri ×1

openstreetmap ×1

python ×1

ruby ×1