[英]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.