WPDx_Toolset.pyt
def calcPriority(self, pnts_buff, pop_grid):
        """Uses zonal statistics to calculate population served by each point"""

        # create list of non-functioning points
        pnts = list()
        with arcpy.da.SearchCursor(pnts_buff, 'wpdx_id', "status_id='no'") as cursor:
            for row in cursor:
                pnts.append(row[0])

        # create dictionary with population served by each point
        start = time.clock()
        pop_dict = dict()

        # Code is commented out bc ZonalStatisticsAsTable doesn't currently work with overlapping polygons
        # incr_pop = arcpy.gp.ZonalStatisticsAsTable_sa(pnts_nonfunc, 'wpdx_id',
        #                                              pop_grid,
        #                                                  r"in_memory\pop",
        #                                                   'DATA', 'SUM')
        #
        # with arcpy.da.SearchCursor(incr_pop, ['wpdx_id', 'SUM' ]) as cursor:
        #    for row in cursor:
        #        pop_dict[row[0]] = row[1]

        # Bellow is a workaround. Delete once bug from line 353 is fixed
        ####################################################################
        # why does this take 100 s more than same code in old toolbox?
        for pnt in pnts:
            pnt_id = pnt.split('-')[1]
            point = arcpy.MakeFeatureLayer_management(pnts_buff, pnt,
                                                      "wpdx_id='{}'".format(pnt))
            incr_pop = arcpy.gp.ZonalStatisticsAsTable_sa(point, 'wpdx_id',
                                                          pop_grid,
                                                          r"in_memory\pop{}".format(pnt_id),
                                                          'DATA', 'SUM')
            with arcpy.da.SearchCursor(incr_pop, ['wpdx_id', 'SUM']) as cursor:
                for row in cursor:
                    pop_dict[row[0]] = row[1]
        #############################################################################

        arcpy.AddMessage("Zonal Stats took: {:.2f} seconds".format(time.clock() - start))
        return pop_dict
Uses zonal statistics to calculate population served by each point
Uses zonal statistics to calculate population served by each point
Uses zonal statistics to calculate population served by each point
def calcPriority(self, pnts_buff, pop_grid):
        pnts = list()
        with arcpy.da.SearchCursor(pnts_buff, 'wpdx_id', "status_id='no'") as cursor:
            for row in cursor:
                pnts.append(row[0])
        start = time.clock()
        pop_dict = dict()
         with arcpy.da.SearchCursor(incr_pop, ['wpdx_id', 'SUM' ]) as cursor:
            for row in cursor:
                pop_dict[row[0]] = row[1]
         Bellow is a workaround. Delete once bug from line 353 is fixed
         why does this take 100 s more than same code in old toolbox?
        for pnt in pnts:
            pnt_id = pnt.split('-')[1]
            point = arcpy.MakeFeatureLayer_management(pnts_buff, pnt,
                                                      "wpdx_id='{}'".format(pnt))
            incr_pop = arcpy.gp.ZonalStatisticsAsTable_sa(point, 'wpdx_id',
                                                          pop_grid,
                                                          r"in_memory\pop{}".format(pnt_id),
                                                          'DATA', 'SUM')
            with arcpy.da.SearchCursor(incr_pop, ['wpdx_id', 'SUM']) as cursor:
                for row in cursor:
                    pop_dict[row[0]] = row[1]
        arcpy.AddMessage("Zonal Stats took: {:.2f} seconds".format(time.clock() - start))
        return pop_dict
def calcPriority ( self , pnts_buff , pop_grid ) : pnts = list ( ) with arcpy . da . SearchCursor ( pnts_buff , 'wpdx_id' , "status_id='no'" ) as cursor : for row in cursor : pnts . append ( row [ 0 ] ) start = time . clock ( ) pop_dict = dict ( ) for pnt in pnts : pnt_id = pnt . split ( '-' ) [ 1 ] point = arcpy . MakeFeatureLayer_management ( pnts_buff , pnt , "wpdx_id='{}'" . format ( pnt ) ) incr_pop = arcpy . gp . ZonalStatisticsAsTable_sa ( point , 'wpdx_id' , pop_grid , r"in_memory\pop{}" . format ( pnt_id ) , 'DATA' , 'SUM' ) with arcpy . da . SearchCursor ( incr_pop , [ 'wpdx_id' , 'SUM' ] ) as cursor : for row in cursor : pop_dict [ row [ 0 ] ] = row [ 1 ] arcpy . AddMessage ( "Zonal Stats took: {:.2f} seconds" . format ( time . clock ( ) - start ) ) return pop_dict
Uses zonal statistics to calculate population served by each point
Uses zonal statistics to calculate population served by each point
"""Uses zonal statistics to calculate population served by each point""" # create list of non-functioning points # create dictionary with population served by each point # Code is commented out bc ZonalStatisticsAsTable doesn't currently work with overlapping polygons # incr_pop = arcpy.gp.ZonalStatisticsAsTable_sa(pnts_nonfunc, 'wpdx_id', #                                              pop_grid, #                                                  r"in_memory\pop", #                                                   'DATA', 'SUM') # # with arcpy.da.SearchCursor(incr_pop, ['wpdx_id', 'SUM' ]) as cursor: #    for row in cursor: #        pop_dict[row[0]] = row[1] # Bellow is a workaround. Delete once bug from line 353 is fixed #################################################################### # why does this take 100 s more than same code in old toolbox? #############################################################################
self
pnts_buff
pop_grid