geodataframe.to_file无效的字段类型<class'bytes'=“”>

时间:2019-03-18 19:34:16

标签: python geopandas fiona

我正在处理shp文件,但在将地理数据框保存到shp文件时遇到问题。

import pandas as pd
import numpy as np
import os
import geopandas
location = '/home/braulio/Documents/example.shp'
datos = geopandas.read_file(location, encoding='UTF-8')

我在处理数据时没有问题,但是当我尝试保存时

A.to_file(r"/home/braulio/Documents/example2.shp")

并返回错误:

ValueError                                Traceback (most recent call last)
<ipython-input-23-6a842789b4b4> in <module>
----> 1 A.to_file(r"/home/braulio/Documents/example2.shp")

~/anaconda3/envs/braulio/lib/python3.7/site-   packages/geopandas/geodataframe.py in to_file(self, filename, driver,   schema, **kwargs)
411         """
412         from geopandas.io.file import to_file
--> 413         to_file(self, filename, driver, schema, **kwargs)
414 
415     def to_crs(self, crs=None, epsg=None, inplace=False):

~/anaconda3/envs/braulio/lib/python3.7/site-packages/geopandas/io/file.py in to_file(df, filename, driver, schema,**kwargs)
109         with fiona.open(filename, 'w', driver=driver, crs=df.crs,
110                         schema=schema, **kwargs) as colxn:
--> 111             colxn.writerecords(df.iterfeatures())
112 
113 

~/anaconda3/envs/braulio/lib/python3.7/site-packages/fiona/collection.py in writerecords(self, records)
347         if self.mode not in ('a', 'w'):
348             raise IOError("collection not open for writing")
--> 349         self.session.writerecs(records, self)
350         self._len = self.session.get_length()
351         self._bounds = self.session.get_extent()

fiona/ogrext.pyx in fiona.ogrext.WritingSession.writerecs()

fiona/ogrext.pyx in fiona.ogrext.OGRFeatureBuilder.build()

ValueError: Invalid field type <class 'bytes'>

2 个答案:

答案 0 :(得分:0)

shapefile不支持

'bytes'和其他一些类型,例如'list'。这是讨论问题的github问题的link

我建议删除具有“字节”类型对象的列,然后保存shapefile。

如果该列确实很重要,请将值更改为“字符串”类型,然后保存shapefile。

答案 1 :(得分:0)

我解决了在开始时将编码更改为latin-1的问题

await axios(url,
  {
    method: 'PUT',
    data: file,
    headers: {
      'content-type': 'png'
    }
  }
)