#NEWLINE# def geos_multipolygon_from_polygons( arg ) : #NEWLINE# #INDENT# '\n    ob must be either a MultiPolygon, sequence or array of sequences \n    or arrays.\n    \n    ' #NEWLINE# if isinstance ( arg , MultiPolygon ) : #NEWLINE# #INDENT# return geos_geom_from_py ( arg ) #NEWLINE# #UNINDENT# obs = getattr ( arg , 'geoms' , arg ) #NEWLINE# obs = [ ob for ob in obs if ( ob and ( not ( isinstance ( ob , polygon . Polygon ) and ob . is_empty ) ) ) ] #NEWLINE# L = len ( obs ) #NEWLINE# if ( L <= 0 ) : #NEWLINE# #INDENT# return ( lgeos . GEOSGeom_createEmptyCollection ( 6 ) , 3 ) #NEWLINE# #UNINDENT# exemplar = obs [ 0 ] #NEWLINE# try : #NEWLINE# #INDENT# N = len ( exemplar [ 0 ] [ 0 ] ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# N = exemplar . _ndim #NEWLINE# #UNINDENT# assert ( ( N == 2 ) or ( N == 3 ) ) #NEWLINE# subs = ( c_void_p * L ) ( ) #NEWLINE# for ( i , ob ) in enumerate ( obs ) : #NEWLINE# #INDENT# if isinstance ( ob , polygon . Polygon ) : #NEWLINE# #INDENT# shell = ob . exterior #NEWLINE# holes = ob . interiors #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# shell = ob [ 0 ] #NEWLINE# holes = ob [ 1 ] #NEWLINE# #UNINDENT# ( geom , ndims ) = polygon . geos_polygon_from_py ( shell , obs ) #NEWLINE# subs [ i ] = cast ( geom , c_void_p ) #NEWLINE# #UNINDENT# return ( lgeos . GEOSGeom_createCollection ( 6 , subs , L ) , N )