geetools.FeatureCollection.FeatureCollectionAccessor.toPolygons#

geetools.FeatureCollection.FeatureCollectionAccessor.toPolygons()#

Drop any geometry that is not a Polygon or a multipolygon.

This method is made to avoid errors when performing zonal statistics and/or other surfaces operations. These operations won’t work on geometries that are Lines or points. The methods remove these geometry types from GEometryCollections and rremove features that don’t have any polygon geometry

Returns:

The parsed collection with only polygon/MultiPolygon geometries

Return type:

ee.FeatureCollection

Example

import ee
import geetools

ee.Initialize()

point0 = ee.Geometry.Point([0,0], proj="EPSG:4326")
point1 = ee.Geometry.Point([0,1], proj="EPSG:4326")
poly0 = point0.buffer(1, proj="EPSG:4326")
poly1 = point1.buffer(1, proj="EPSG:4326").bounds(proj="EPSG:4326")
line = ee.Geometry.LineString([point1, point0], proj="EPSG:4326")
multiPoly = ee.Geometry.MultiPolygon([poly0, poly1], proj="EPSG:4326")
geometryCol = ee.Algorithms.GeometryConstructors.MultiGeometry([multiPoly, poly0, poly1, point0, line], crs="EPSG:4326", geodesic=True, maxError=1)

fc = ee.FeatureCollection([geometryCol])
fc = fc.geetools.toPolygons()
print(fc.getInfo())