コード例 #1
0
ファイル: DataProcessor.py プロジェクト: jlgjunior/gps_etl
 def processSingleDataPoint(self, latitude, longitude):
     location = Location(latitude, longitude)
     try:
         data = self._gmaps.reverse_geocode(
             (location.latitude, location.longitude))
         for addressItem in data[0]['address_components']:
             if 'street_number' in addressItem['types']:
                 location.number = addressItem['long_name']
             elif 'sublocality_level_1' in addressItem['types']:
                 location.district = addressItem['long_name']
             elif 'administrative_area_level_2' in addressItem['types']:
                 location.city = addressItem['long_name']
             elif 'country' in addressItem['types']:
                 country = Country(addressItem['long_name'])
             elif 'administrative_area_level_1' in addressItem['types']:
                 state = State(addressItem['long_name'],
                               addressItem['short_name'])
             elif 'postal_code' in addressItem['types']:
                 location.zipcode = addressItem['long_name']
             elif 'route' in addressItem['types']:
                 location.address = addressItem['long_name']
         state.country = country
         location.state = state
         return location
     except Exception as e:
         print(e)
         return []
コード例 #2
0
def process_locs_inputs(wb_name):
    locs = []
    input_wb = xl.load_workbook(filename=wb_name)
    input_wb_main_ws = input_wb.active
    state = ["error", "error", "NSW", "VIC", "QLD", "SA", "WA", "TAS", "NT"]
    print(input_wb_main_ws.max_row)
    for i in range(2, input_wb_main_ws.max_row + 1):
        loc = Location()
        if input_wb_main_ws.cell(row=i, column=1).value == None:
            loc.loc_ID = i - 1
        else:
            loc.loc_ID = str(input_wb_main_ws.cell(row=i, column=1).value)
        loc.address = str(input_wb_main_ws.cell(row=i, column=2).value)
        loc.postcode = str(input_wb_main_ws.cell(row=i, column=3).value)
        #add co ordinates from bing maps if needed
        if input_wb_main_ws.cell(
                row=i, column=4).value == None or input_wb_main_ws.cell(
                    row=i, column=5).value == None:
            if loc.address == "None":
                continue
                print("please provide address or lat/long")
            loc.get_coordinates()
            input_wb_main_ws.cell(row=i, column=4).value = loc.lat
            input_wb_main_ws.cell(row=i, column=5).value = loc.long
        else:
            loc.lat = float(input_wb_main_ws.cell(row=i, column=4).value)
            loc.long = float(input_wb_main_ws.cell(row=i, column=5).value)
        #add address from bing maps if needed
        if loc.address == "None":
            print(i)
            print(loc.address)
            loc.get_address()
            input_wb_main_ws.cell(row=i, column=2).value = loc.address
        loc.SAM_ID = str(input_wb_main_ws.cell(row=i, column=6).value)
        loc.status = str(input_wb_main_ws.cell(row=i, column=8).value)
        loc.MRQ = str(input_wb_main_ws.cell(row=i, column=7).value)
        if loc.SAM_ID != "None":
            loc.state = state[int(loc.SAM_ID[0])]
        else:
            loc.state = "None"
        loc.ID = i - 1
        dup = False
        for loc_base in locs:
            if loc_base.loc_ID == loc.loc_ID:
                dup = True
                break
        if dup == False:
            locs.append(loc)
    #wb_name[-5]="1"
    #print("input saving as: " + wb_name)
    #input_wb.save(wb_name)
    input_wb.close()
    return locs