#NEWLINE# def transform( func , geom ) : #NEWLINE# #INDENT# "Applies `func` to all coordinates of `geom` and returns a new\n    geometry of the same type from the transformed coordinates.\n\n    `func` maps x, y, and optionally z to output xp, yp, zp. The input\n    parameters may iterable types like lists or arrays or single values.\n    The output shall be of the same type. Scalars in, scalars out.\n    Lists in, lists out.\n\n    For example, here is an identity function applicable to both types\n    of input.\n\n      def id_func(x, y, z=None):\n          return tuple(filter(None, [x, y, z]))\n\n      g2 = transform(id_func, g1)\n\n    A partially applied transform function from pyproj satisfies the\n    requirements for `func`.\n\n      from functools import partial\n      import pyproj\n\n      project = partial(\n          pyproj.transform,\n          pyproj.Proj(init='epsg:4326'),\n          pyproj.Proj(init='epsg:26913'))\n\n      g2 = transform(project, g1)\n\n    Lambda expressions such as the one in\n\n      g2 = transform(lambda x, y, z=None: (x+1.0, y+1.0), g1)\n\n    also satisfy the requirements for `func`.\n    " #NEWLINE# if geom . is_empty : #NEWLINE# #INDENT# return geom #NEWLINE# #UNINDENT# if ( geom . type in ( 'Point' , 'LineString' , 'LinearRing' , 'Polygon' ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( geom . type in ( 'Point' , 'LineString' , 'LinearRing' ) ) : #NEWLINE# #INDENT# return type ( geom ) ( zip ( * func ( * izip ( * geom . coords ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( geom . type == 'Polygon' ) : #NEWLINE# #INDENT# shell = type ( geom . exterior ) ( zip ( * func ( * izip ( * geom . exterior . coords ) ) ) ) #NEWLINE# holes = list ( ( type ( ring ) ( zip ( * func ( * izip ( * ring . coords ) ) ) ) for ring in geom . interiors ) ) #NEWLINE# return type ( geom ) ( shell , holes ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# if ( geom . type in ( 'Point' , 'LineString' , 'LinearRing' ) ) : #NEWLINE# #INDENT# return type ( geom ) ( [ func ( * c ) for c in geom . coords ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( geom . type == 'Polygon' ) : #NEWLINE# #INDENT# shell = type ( geom . exterior ) ( [ func ( * c ) for c in geom . exterior . coords ] ) #NEWLINE# holes = list ( ( type ( ring ) ( [ func ( * c ) for c in ring . coords ] ) for ring in geom . interiors ) ) #NEWLINE# return type ( geom ) ( shell , holes ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( geom . type . startswith ( 'Multi' ) or ( shell . type == 'GeometryCollection' ) ) : #NEWLINE# #INDENT# return type ( geom ) ( [ transform ( func , part ) for part in geom . geoms ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'Type %r not recognized' % geom . type ) )