(self)
Handle input shapefile, create grid (output) shapefile, do
        summary calculations.
Handle input shapefile, create grid (output) shapefile, do
        summary calculations.
Handle input shapefile create grid ( output ) shapefile do summary calculations .
def main(self):
        """
        Handle input shapefile, create grid (output) shapefile, do
        summary calculations.
        """
        driver = ogr.GetDriverByName('ESRI Shapefile')
        in_shapefile = driver.Open(self.args.infile, GA_ReadOnly)
        if in_shapefile is None:
            print('Could not open shapefile for read: %s' % self.args.infile)
            sys.exit(1)

        in_layer = in_shapefile.GetLayer()
        if not in_layer.GetGeomType() == ogr.wkbPoint \
                and not self.args.ignore_type:
            print('Input shapefile does not contain a point layer.')
            print('To force computation, use the --ignore-type option.')
            sys.exit(2)

        # If outfile exists and `--overwrite` is set, delete it first
        if os.path.exists(self.args.outfile):
            if not self.args.overwrite:
                print('Output file exists. To overwrite, use the --overwrite \
option.')
                sys.exit(3)
            driver.DeleteDataSource(self.args.outfile)

        out_shapefile = driver.CreateDataSource(self.args.outfile)
        out_layer = out_shapefile.CreateLayer('grid', geom_type=ogr.wkbPolygon)
        field_defn = ogr.FieldDefn('COUNT', ogr.OFTInteger)
        out_layer.CreateField(field_defn)

        # Write .prj file for output shapefile
        spatial_ref = in_layer.GetSpatialRef()
        with open(self.args.outfile[:-4] + '.prj', 'w') as proj_file:
            proj_file.write(spatial_ref.ExportToWkt())

        if self.args.extent:
          extent = self.args.extent
        else:
          extent = in_layer.GetExtent()

        self.grid.create_grid(out_layer, extent,
                num_across=self.args.num_across)
        self.count_intersections(out_layer, in_layer)

        if self.args.exclude_empty:
            self.remove_empty_shapes(out_layer)

        in_shapefile.Destroy()
        out_shapefile.Destroy()
def main ( self ) : driver = ogr . GetDriverByName ( 'ESRI Shapefile' ) in_shapefile = driver . Open ( self . args . infile , GA_ReadOnly ) if in_shapefile is None : print ( 'Could not open shapefile for read: %s' % self . args . infile ) sys . exit ( 1 ) in_layer = in_shapefile . GetLayer ( ) if not in_layer . GetGeomType ( ) == ogr . wkbPoint and not self . args . ignore_type : print ( 'Input shapefile does not contain a point layer.' ) print ( 'To force computation, use the --ignore-type option.' ) sys . exit ( 2 ) # If outfile exists and `--overwrite` is set, delete it first if os . path . exists ( self . args . outfile ) : if not self . args . overwrite : print ( 'Output file exists. To overwrite, use the --overwrite \
option.' ) sys . exit ( 3 ) driver . DeleteDataSource ( self . args . outfile ) out_shapefile = driver . CreateDataSource ( self . args . outfile ) out_layer = out_shapefile . CreateLayer ( 'grid' , geom_type = ogr . wkbPolygon ) field_defn = ogr . FieldDefn ( 'COUNT' , ogr . OFTInteger ) out_layer . CreateField ( field_defn ) # Write .prj file for output shapefile spatial_ref = in_layer . GetSpatialRef ( ) with open ( self . args . outfile [ : - 4 ] + '.prj' , 'w' ) as proj_file : proj_file . write ( spatial_ref . ExportToWkt ( ) ) if self . args . extent : extent = self . args . extent else : extent = in_layer . GetExtent ( ) self . grid . create_grid ( out_layer , extent , num_across = self . args . num_across ) self . count_intersections ( out_layer , in_layer ) if self . args . exclude_empty : self . remove_empty_shapes ( out_layer ) in_shapefile . Destroy ( ) out_shapefile . Destroy ( )