读取Azure函数上的形状文件

2024-09-27 19:30:49 发布

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

我使用python编写的Azure函数来读取来自Blob的shapefile。配置是

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "inputShp",
      "type": "blobTrigger",
      "direction": "in",
      "path": "uploads/shapefile/{name}.shp",
      "connection": "StorageConnectionString"
    }
  ]
}

以及__init__.py脚本

^{pr2}$

但这是一个错误

Exception: ShapefileException: Shapefile Reader requires a shapefile or file-like object.

我尝试使用reader = shapefile.Reader(io.BytesIO(inputShp.read()))来代替,这会导致错误

error: unpack requires a buffer of 4 bytes

Tags: 函数namepyinittype错误bindingsazure
2条回答

从一个流读取SeaFipe文件似乎是菲奥娜的内存文件(或者MeMyRyZip文件)让你做的。在

未经测试,但值得一试。在

https://fiona.readthedocs.io/en/latest/fiona.html#fiona.io.MemoryFile

您还可以使用关键字参数从任何类似Python文件的对象加载shapefile来指定这三个文件中的任何一个。这个特性非常强大,允许您从url、zip文件、序列化对象或某些情况下的数据库加载shapefile。在

下面是相同的样品

>>> myshp = open("shapefiles/blockgroups.shp", "rb")
>>> mydbf = open("shapefiles/blockgroups.dbf", "rb")
>>> r = shapefile.Reader(shp=myshp, dbf=mydbf)

使用“打开”而不是读。或者试试下面的例子

^{pr2}$

这也应该行得通。希望有帮助。在

相关问题 更多 >

    热门问题