#NEWLINE# def shapefile_extents( shp ) : #NEWLINE# #INDENT# "\n    Determine the extents of a shapefile\n\n    Parameters\n    ----------\n    shp : string\n        Name of the shapefile to convert to a PatchCollection.\n\n    Returns\n    -------\n    extents : tuple\n        tuple with xmin, xmax, ymin, ymax from shapefile.\n\n    Examples\n    --------\n\n    >>> import flopy\n    >>> fshp = 'myshapefile'\n    >>> extent = flopy.plot.plotutil.shapefile_extents(fshp)\n\n    " #NEWLINE# try : #NEWLINE# #INDENT# import shapefile #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# s = 'Could not import shapefile.  Must install pyshp in order to plot shapefiles.' #NEWLINE# raise Exception ( s ) #NEWLINE# #UNINDENT# sf = shapefile . Reader ( shp ) #NEWLINE# shapes = sf . shapes ( ) #NEWLINE# nshp = len ( shapes ) #NEWLINE# ( xmin , xmax , ymin , ymax ) = ( 1e+20 , ( - 1e+20 ) , 1e+20 , ( - 1e+20 ) ) #NEWLINE# ptchs = [ ] #NEWLINE# for n in range ( nshp ) : #NEWLINE# #INDENT# for p in shapes [ n ] . points : #NEWLINE# #INDENT# ( xmin , xmax ) = ( min ( xmin , p [ 0 ] ) , max ( xmax , p [ 0 ] ) ) #NEWLINE# ( ymin , ymax ) = ( min ( ymin , p [ 1 ] ) , max ( ymax , p [ 1 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# return ( xmin , xmax , ymin , ymax )