WPDx_Toolset.pyt
def execute(self, parameters, messages):
        """The source code of the tool."""

        # Get Parameters
        global scratch
        scratch = tempfile.mkdtemp()
        zone = parameters[0].valueAsText
        buff_dist = parameters[1].valueAsText
        pop_grid = parameters[2].value
        out_path = parameters[3].value

        # Calculate incremental population that could be served by each broken water point
        query_response, mask = queryWPDx(zone)
        pnts = getWaterPoints(query_response)

        start = time.clock()
        pnts_buff = arcpy.Buffer_analysis(pnts, r"in_memory\buffer", "{} Meters".format(buff_dist))
        if mask == "Error":
            arcpy.env.extent = arcpy.Describe(pnts_buff).extent
        arcpy.AddMessage("Buffer took: {:.2f} seconds".format(time.clock() - start))
        pnts_buff_func = arcpy.MakeFeatureLayer_management(pnts_buff, 'Functioning',
                                                           "status_id='yes'")
        pop_not_served = getPopNotServed(pnts_buff_func, pop_grid)

        # Add population served to water points as an attribute
        pop_dict = self.calcPriority(pnts_buff, pop_not_served)
        arcpy.AddField_management(pnts, "Pop_Served", "FLOAT")
        pnts_nonfunc = arcpy.MakeFeatureLayer_management(pnts, 'NonFunctioning',
                                                         "status_id='no'")
        with arcpy.da.UpdateCursor(pnts_nonfunc, ['wpdx_id', 'Pop_Served']) as cursor:
            for row in cursor:
                try:
                    row[1] = pop_dict[row[0]]
                    cursor.updateRow(row)
                except KeyError:
                    pass

        output = arcpy.CopyFeatures_management(pnts_nonfunc, out_path)

        parameters[3] = output
        parameters[4].value = self.outputCSV(zone, query_response, pop_dict)
The source code of the tool.
The source code of the tool.
The source code of the tool .
def execute(self, parameters, messages):
        global scratch
        scratch = tempfile.mkdtemp()
        zone = parameters[0].valueAsText
        buff_dist = parameters[1].valueAsText
        pop_grid = parameters[2].value
        out_path = parameters[3].value
        query_response, mask = queryWPDx(zone)
        pnts = getWaterPoints(query_response)
        start = time.clock()
        pnts_buff = arcpy.Buffer_analysis(pnts, r"in_memory\buffer", "{} Meters".format(buff_dist))
        if mask == "Error":
            arcpy.env.extent = arcpy.Describe(pnts_buff).extent
        arcpy.AddMessage("Buffer took: {:.2f} seconds".format(time.clock() - start))
        pnts_buff_func = arcpy.MakeFeatureLayer_management(pnts_buff, 'Functioning',
                                                           "status_id='yes'")
        pop_not_served = getPopNotServed(pnts_buff_func, pop_grid)
        pop_dict = self.calcPriority(pnts_buff, pop_not_served)
        arcpy.AddField_management(pnts, "Pop_Served", "FLOAT")
        pnts_nonfunc = arcpy.MakeFeatureLayer_management(pnts, 'NonFunctioning',
                                                         "status_id='no'")
        with arcpy.da.UpdateCursor(pnts_nonfunc, ['wpdx_id', 'Pop_Served']) as cursor:
            for row in cursor:
                try:
                    row[1] = pop_dict[row[0]]
                    cursor.updateRow(row)
                except KeyError:
                    pass
        output = arcpy.CopyFeatures_management(pnts_nonfunc, out_path)
        parameters[3] = output
        parameters[4].value = self.outputCSV(zone, query_response, pop_dict)
def execute ( self , parameters , messages ) : global scratch scratch = tempfile . mkdtemp ( ) zone = parameters [ 0 ] . valueAsText buff_dist = parameters [ 1 ] . valueAsText pop_grid = parameters [ 2 ] . value out_path = parameters [ 3 ] . value query_response , mask = queryWPDx ( zone ) pnts = getWaterPoints ( query_response ) start = time . clock ( ) pnts_buff = arcpy . Buffer_analysis ( pnts , r"in_memory\buffer" , "{} Meters" . format ( buff_dist ) ) if mask == "Error" : arcpy . env . extent = arcpy . Describe ( pnts_buff ) . extent arcpy . AddMessage ( "Buffer took: {:.2f} seconds" . format ( time . clock ( ) - start ) ) pnts_buff_func = arcpy . MakeFeatureLayer_management ( pnts_buff , 'Functioning' , "status_id='yes'" ) pop_not_served = getPopNotServed ( pnts_buff_func , pop_grid ) pop_dict = self . calcPriority ( pnts_buff , pop_not_served ) arcpy . AddField_management ( pnts , "Pop_Served" , "FLOAT" ) pnts_nonfunc = arcpy . MakeFeatureLayer_management ( pnts , 'NonFunctioning' , "status_id='no'" ) with arcpy . da . UpdateCursor ( pnts_nonfunc , [ 'wpdx_id' , 'Pop_Served' ] ) as cursor : for row in cursor : try : row [ 1 ] = pop_dict [ row [ 0 ] ] cursor . updateRow ( row ) except KeyError : pass output = arcpy . CopyFeatures_management ( pnts_nonfunc , out_path ) parameters [ 3 ] = output parameters [ 4 ] . value = self . outputCSV ( zone , query_response , pop_dict )
The source code of the tool.
The source code of the tool .
"""The source code of the tool.""" # Get Parameters # Calculate incremental population that could be served by each broken water point # Add population served to water points as an attribute
self
parameters
messages