keepType#
- geetools.GeometryAccessor.keepType(type)#
Only keep the geometries of the given type from a GeometryCollection.
- Parameters:
type (str) – The type of geometries to keep. Can be one of: Point, LineString, LineRing Polygon.
- Returns:
The geometries of the given type.
- Return type:
Examples
import ee, geetools from geetools.utils import initialize_documentation initialize_documentation() # generate multiple geometries of different types 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") # create a geometry collection from them geometryColllection = ee.Algorithms.GeometryConstructors.MultiGeometry( [multiPoly, poly0, poly1, point0, line], crs="EPSG:4326", geodesic=True, maxError=1 ) # extract only the LineString geometries from the collection geom = geometryColllection.geetools.keepType('LineString') geom.getInfo()
{'type': 'MultiLineString', 'coordinates': [[[0, 1], [0, 0]]]}