Networkx无法读取我的gml文件:输入不是AScienceODED

2024-06-07 04:26:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用networkx读取我的gml文件

import networkx as nx
G = nx.read_gml('test.gml')

但我总是犯同样的错误:

networkx.exception.NetworkXError: input is not ASCII-encoded

我已经尝试将networkx降级到1.9.1版,但仍然不起作用

这里是我的gml文件的开头:

<?xml version="1.0" encoding="UTF-8"?>
<PlanCorpsRueSimplifie xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns="http://cnig.gouv.fr/pcrs" gml:id="PlanCorpsRueSimplifie.1" version="2.0" xsi:schemaLocation="http://cnig.gouv.fr/pcrs CNIG_PCRS_v2.0.xsd">
    <gml:boundedBy>
        <gml:Envelope srsName="EPSG:3944">
            <gml:lowerCorner>1784316.1423000023 3210973.5976999998</gml:lowerCorner>
            <gml:upperCorner>1790225.4457999989 3217946.2347000018</gml:upperCorner>
        </gml:Envelope>
    </gml:boundedBy>
    <featureMember>

Tags: 文件orgnetworkxhttpversionwwwfrxlink
1条回答
网友
1楼 · 发布于 2024-06-07 04:26:22

通过阅读文档networkx.read_gml()

The GML specification says that files should be ASCII encoded, with any extended ASCII characters (iso8859-1) appearing as HTML character entities.

尝试使用类似于以下代码的方法重新绘制图形,但要使用您的数据

g = nx.DiGraph()
g.add_nodes_from([1, 2, 3, 4, 5, 6, 7, 8, 9])
g.add_edges_from([(1,2), (2, 1),
                  (1, 3),(3, 1),
                  (3, 4), (4, 3),
                  (4, 5), (5, 4),
                  (4, 6), (6, 4),
                  (6, 7), (7, 6),
                  (7, 8), (8, 7),
                  (1, 9), (2, 9),(3, 9), (4, 9),(5, 9), (6, 9),
                          (7, 9), (8, 9),
                  ])
nx.write_gml(, 'test.gml')

相关问题 更多 >