WPDx_Toolset.pyt
def queryWPDx(zone):
    """Fetches all the water points from WPDx in given administrative area"""
    # First 2000 results, remove limit and get login if neccessary
    start = time.clock()
    client = Socrata("data.waterpointdata.org", None)
    # Set output fields (this only affects the Repair Priority tool)
    fields = 'adm1,adm2,country_id,country_name,created,data_lnk,fecal_coliform_presence,install_year,installer,photo_lnk,photo_lnk_description,report_date,source,status_id,subjective_quality,updated,water_source,water_tech,wpdx_id,lat_deg,lon_deg'

    zone1 = zone
    # it is better to change the'Admin' dataset to match what WPDx API is expecting,
    # but if you do want to allow multiple spellings of the same word, do it here.
    if zone1.lower() == 'tanzania':
        zone1 = 'Tanzania, United Republic of'
    # All admin areas in Swazliand must be in ALL CAPS

    if len(zone) > 2:
        response = client.get("gihr-buz6", adm1=zone1, limit=50000, select= fields)
        if len(response) > 1:
            query_type = 'Admin1'
        else:
            response = client.get("gihr-buz6", adm2=zone1, limit=50000, select= fields)
            if len(response) > 1:
                query_type = 'Name'
            else:
                response = client.get("gihr-buz6", country_name=zone1, limit=500000, select= fields)
                if len(response) > 1:
                    query_type = 'Country'
                else:
                    arcpy.AddError("ERROR: Administrative zone not recognized")
                    # Ambiguous error, this can also mean the zone is recognized
                    # but has no points in it
                    sys.exit(1)
    else:
        response = client.get("gihr-buz6", country_id=zone1, limit=500000, select= fields)
        if len(response) > 1:
            query_type = 'cc'
        else:
            arcpy.AddError("ERROR: Country Code not recognized")
            sys.exit(1)

    arcpy.AddMessage("Query took: {:.2f} seconds".format(time.clock() - start))
    arcpy.AddMessage("Found: {} points".format(len(response)))
    mask = setEnvironment(zone, query_type)
    return (response, mask)
Fetches all the water points from WPDx in given administrative area
Fetches all the water points from WPDx in given administrative area
Fetches all the water points from WPDx in given administrative area
def queryWPDx(zone):
    start = time.clock()
    client = Socrata("data.waterpointdata.org", None)
    fields = 'adm1,adm2,country_id,country_name,created,data_lnk,fecal_coliform_presence,install_year,installer,photo_lnk,photo_lnk_description,report_date,source,status_id,subjective_quality,updated,water_source,water_tech,wpdx_id,lat_deg,lon_deg'
    zone1 = zone
    if zone1.lower() == 'tanzania':
        zone1 = 'Tanzania, United Republic of'
    if len(zone) > 2:
        response = client.get("gihr-buz6", adm1=zone1, limit=50000, select= fields)
        if len(response) > 1:
            query_type = 'Admin1'
        else:
            response = client.get("gihr-buz6", adm2=zone1, limit=50000, select= fields)
            if len(response) > 1:
                query_type = 'Name'
            else:
                response = client.get("gihr-buz6", country_name=zone1, limit=500000, select= fields)
                if len(response) > 1:
                    query_type = 'Country'
                else:
                    arcpy.AddError("ERROR: Administrative zone not recognized")
                    sys.exit(1)
    else:
        response = client.get("gihr-buz6", country_id=zone1, limit=500000, select= fields)
        if len(response) > 1:
            query_type = 'cc'
        else:
            arcpy.AddError("ERROR: Country Code not recognized")
            sys.exit(1)
    arcpy.AddMessage("Query took: {:.2f} seconds".format(time.clock() - start))
    arcpy.AddMessage("Found: {} points".format(len(response)))
    mask = setEnvironment(zone, query_type)
    return (response, mask)
def queryWPDx ( zone ) : start = time . clock ( ) client = Socrata ( "data.waterpointdata.org" , None ) fields = 'adm1,adm2,country_id,country_name,created,data_lnk,fecal_coliform_presence,install_year,installer,photo_lnk,photo_lnk_description,report_date,source,status_id,subjective_quality,updated,water_source,water_tech,wpdx_id,lat_deg,lon_deg' zone1 = zone if zone1 . lower ( ) == 'tanzania' : zone1 = 'Tanzania, United Republic of' if len ( zone ) > 2 : response = client . get ( "gihr-buz6" , adm1 = zone1 , limit = 50000 , select = fields ) if len ( response ) > 1 : query_type = 'Admin1' else : response = client . get ( "gihr-buz6" , adm2 = zone1 , limit = 50000 , select = fields ) if len ( response ) > 1 : query_type = 'Name' else : response = client . get ( "gihr-buz6" , country_name = zone1 , limit = 500000 , select = fields ) if len ( response ) > 1 : query_type = 'Country' else : arcpy . AddError ( "ERROR: Administrative zone not recognized" ) sys . exit ( 1 ) else : response = client . get ( "gihr-buz6" , country_id = zone1 , limit = 500000 , select = fields ) if len ( response ) > 1 : query_type = 'cc' else : arcpy . AddError ( "ERROR: Country Code not recognized" ) sys . exit ( 1 ) arcpy . AddMessage ( "Query took: {:.2f} seconds" . format ( time . clock ( ) - start ) ) arcpy . AddMessage ( "Found: {} points" . format ( len ( response ) ) ) mask = setEnvironment ( zone , query_type ) return ( response , mask )
Fetches all the water points from WPDx in given administrative area
Fetches all the water points from WPDx in given administrative area
"""Fetches all the water points from WPDx in given administrative area""" # First 2000 results, remove limit and get login if neccessary # Set output fields (this only affects the Repair Priority tool) # it is better to change the'Admin' dataset to match what WPDx API is expecting, # but if you do want to allow multiple spellings of the same word, do it here. # All admin areas in Swazliand must be in ALL CAPS # Ambiguous error, this can also mean the zone is recognized # but has no points in it
zone