告诉geojson将数据另存为UTF8?

时间:2018-08-29 10:22:48

标签: python geojson

我不知道为什么geojson以这种格式(UTF16?)保存数据,以便在调用geojson.dump()将数据保存回磁盘时,“François”最终以“ Fran \ u00e7ois”结尾。

有什么主意吗?

# curl --insecure -v "10.43.11.128:3333/"
*   Trying 10.43.11.128...
* TCP_NODELAY set
* Connected to 10.43.11.128 (10.43.11.128) port 3333 (#0)
> GET / HTTP/1.1
> Host: 10.43.11.128:3333
> User-Agent: curl/7.52.1
> Accept: */*
> 
* Curl_http_done: called premature == 0
* Empty reply from server
* Connection #0 to host 10.43.11.128 left intact
curl: (52) Empty reply from server

谢谢。

-

编辑:

我遵循了另一个线程,并尝试了几种方法,但是仍然无法保持原始文本。

import geojson
from geojson import LineString, Point, Feature, FeatureCollection, dump
from geopy.geocoders import Nominatim

with open('input.geojson', encoding='utf-8') as f:
    gj = geojson.load(f)

for track in gj['features']:
    #NO DIFF with open(track['properties']['name'][0] + '.geojson', 'a+', encoding='utf-8') as f:
    with open(track['properties']['name'][0] + '.geojson', 'a+') as f:
        dump(track, f, indent=2)

        #UnicodeEncodeError: 'charmap' codec can't encode character '\u2194' in position 7: character maps to <undefined>
        #dump(track, f, indent=2, ensure_ascii=False)

        #NOT DEFINED
        #dumps(track, f, indent=2)

        #AttributeError: encode
        #dump(track.encode("utf-8"), f, indent=2, ensure_ascii=False)

0 个答案:

没有答案