简体   繁体   中英

Errno 32: Broken pipe when using getMapId()

I am reading a large geojson file containing the footprints of thousands of buildings. This file looks like this:

{
  "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":{}},
.
.
.
  ]
}

I am reading this file and loading it into a ee.FeatureCollection() with:

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)

But when I try to show these buildings into folium with:

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

I get the following error:

---------------------------------------------------------------------------
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

Could this happen because the file is too large? Any way around this problem?

I am pretty sure this is happening because Earth Engine is still computing and the connection is closed on the client side after not receiving a response. See this answer for more information on Broken Pipe.

Assuming that you have a lot of polygons, Earth Engine has to construct the polygons and then rasterize them which may not take a lot of compute but can take some time, hence the broken pipe. One way around this would be to save the buildings polygons as an asset and then load the asset to the map directly.

You can export the featureCollection using this syntax:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM