簡體   English   中英

Errno 32:使用 getMapId() 時 pipe 損壞

[英]Errno 32: Broken pipe when using getMapId()

我正在閱讀一個包含數千座建築物足跡的大型 geojson 文件。 該文件如下所示:

{
  "type":"FeatureCollection",
  "features":
  [
    {"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-97.208203,50.90649],[-97.208203,50.906568],[-97.208367,50.906568],[-97.208367,50.90649],[-97.208203,50.90649]]]},"properties":{}},
    {"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-97.138545,50.91915],[-97.1387,50.919146],[-97.138692,50.919018],[-97.138537,50.919022],[-97.138545,50.91915]]]},"properties":{}},
    {"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-97.106312,50.949822],[-97.106178,50.949845],[-97.106255,50.950025],[-97.106389,50.950002],[-97.106312,50.949822]]]},"properties":{}},
.
.
.
  ]
}

我正在閱讀此文件並將其加載到ee.FeatureCollection()中:

import json

# Open file to parse
with open('/content/drive/My Drive/Earthengine/buildings.geojson') as f:
  data = json.load(f)

# Parse each of the polygons to features
polygons = []
for feat in data['features']:
  polygons.append(ee.Feature(feat))

# Create the feature collection
buildings = ee.FeatureCollection(polygons)

但是,當我嘗試將這些建築物展示為 folium 時:

polyImage = ee.Image(0).byte().paint(buildings, 1)
polyImage = polyImage.updateMask(polyImage)

mapid = polyImage.getMapId()
map = folium.Map(location=[38., -100.], zoom_start=5)
folium.TileLayer(
    tiles=EE_TILES.format(**mapid),
    attr='Google Earth Engine',
    overlay=True,
    name='training polygons',
  ).add_to(map)
map.add_child(folium.LayerControl())
map

我收到以下錯誤:

---------------------------------------------------------------------------
BrokenPipeError                           Traceback (most recent call last)
<ipython-input-7-3c769c73ff13> in <module>()
      2 polyImage = polyImage.updateMask(polyImage)
      3 
----> 4 mapid = polyImage.getMapId()
      5 map = folium.Map(location=[38., -100.], zoom_start=5)
      6 folium.TileLayer(

15 frames
/usr/lib/python3.6/ssl.py in write(self, data)
    640         The 'data' argument must support the buffer interface.
    641         """
--> 642         return self._sslobj.write(data)
    643 
    644     def getpeercert(self, binary_form=False):

BrokenPipeError: [Errno 32] Broken pipe

會不會因為文件太大而發生這種情況? 有辦法解決這個問題嗎?

我很確定這正在發生,因為 Earth Engine 仍在計算,並且在未收到響應后連接在客戶端關閉。 有關 Broken Pipe 的更多信息,請參閱此答案

假設您有很多多邊形,Earth Engine 必須構建多邊形然后將它們柵格化,這可能不需要大量計算但可能需要一些時間,因此損壞的 pipe。 解決此問題的一種方法是將建築物多邊形保存為資產,然后將資產直接加載到 map。

您可以使用以下語法導出 featureCollection:

task = ee.batch.Export.table.toAsset(
  collection=buildings,
  description='my-buildings', 
  assetId='users/myusername/buildings'
)
task.start()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM