我有一个shapefile,我正在将其转换为一个.xml
文件,以便在MATSim中使用。文件结构如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE network SYSTEM "http://www.matsim.org/files/dtd/network_v1.dtd">
<network name="VISUM export national network 2007-11-28">
<!-- ====================================================================== -->
<nodes>
<node id="1000" x="730065.3125" y="220415.9531" type="2" origid="1000" />
<node id="1001" x="731010.5" y="220146.2969" type="2" origid="1001" />
.....
</nodes>
<!-- ====================================================================== -->
<links capperiod="01:00:00" effectivecellsize="7.5" effectivelanewidth="3.75">
<link id="100365" from="226" to="227" length="921.0" freespeed="33.3333333333333" capacity="5600.0" permlanes="2.0" oneway="1" modes="car" origid="183" type="10" />
...
</links>
<!-- ====================================================================== -->
</network>
我使用NetworkX Python库来完成这项工作,它可以将shapefile作为一个图形读取,并将图形导出为GEXF
对象。这段代码(本质上)输出的内容与网络规范非常接近,但还不够接近。在
<gexf version="1.1" xmlns="http://www.gexf.net/1.1draft" xmlns:viz="http://www.gexf.net/1.1draft/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance">
<graph defaultedgetype="undirected" mode="static">
<attributes class="node" mode="static">
<attribute id="0" title="y" type="double" />
<attribute id="1" title="x" type="double" />
</attributes>
<nodes>
<node id="0" label="0">
<attvalues>
<attvalue for="0" value="1389860.27495" />
<attvalue for="1" value="2237913.99085" />
</attvalues>
</node>
除此之外,GEXL使用节点和边,但MATSim词汇表要求节点和链接。我正试图决定是调整NetworkX中的write_gexf
函数,还是手动写出XML,例如使用ElementTree API。有什么提示吗?在
Short:如果这是一个一次性项目,请调整NetworkX中的
write_gexf
函数。在长:
对于MATSim,你需要一个有向图。Gexf允许
defaultedgetype="directed"
。您可以为边缘添加更多属性,例如通行能力、车道。。。在由于已经有了gexf,最后一步是一对一的转换。Gexf节点直接转换为MATSim节点,而边缘在MATSim术语中是链接。但是,您需要向MATSim提供网络的属性。在
节点只需要x,y坐标
对于链接,您可能需要添加链接的实际长度(而不是欧几里得距离)。此外,还需要最大允许速度(自由速度)、通行能力(通常以每小时PCU表示)和车道数。在
注意容量取决于上限,即
capperiod="01:00:00"
表示有效期为一小时。在另外,你也可以看看the gexf package,在那里你可以找到一些gexf帮助类,主要用于将MATSim网络转换成gexf,例如,在Gephi中分析它们。在
相关问题 更多 >
编程相关推荐