示例#1
0
def update_mesonet_sites(url=config.mesonet_site_url,
                         database=config.mesonet_database,
                         collection=config.mesonet_collection):
    """ Update mesonet sites """
    db = Connection(config.mesonet_mongo_host)
    reader = csv.reader(urllib2.urlopen(url))
    data = []
    now = datetime.now()
    collection_backup = "%s_%s" % (collection, now.strftime("%Y_%m_%d_%H%M%S"))
    db[database][collection].rename(collection_backup)
    polydata = []
    for itm in db.ows.watersheds.find():
        polydata.append(itm)
    aquifer_poly = []
    for itm in db.ows.aquifers.find():
        aquifer_poly.append(itm)
    for row in reader:
        if reader.line_num == 1:
            headers = row[1:]
        else:
            row_data = dict(zip(headers, row[1:]))
            if row_data['nlat'] != '':
                #set watershed values
                for poly in polydata:
                    s = poly['geometry']
                    if gis_tools.intersect_point(s, row_data['nlat'],
                                                 row_data['elon']):
                        if 'HUC_4' in poly['properties']:
                            #print 'HUC 4: ' + poly['properties']['HUC_4']
                            row_data["huc_4"] = poly['properties']['HUC_4']
                        if 'HUC_8' in poly['properties']:
                            #print 'HUC 8: ' + poly['properties']['HUC_8']
                            row_data["huc_8"] = poly['properties']['HUC_8']
                #set aquifer data
                for poly in aquifer_poly:
                    s = poly['geometry']
                    if gis_tools.intersect_point(s, row_data['nlat'],
                                                 row_data['elon']):
                        row_data["aquifer"] = poly['properties']['NAME']
                        print poly['properties']['NAME']
                        break
                #set status
                date_decom = datetime.strptime(row_data["datd"], "%Y%m%d")
                if date_decom <= now:
                    row_data["status"] = "Inactive"
                else:
                    row_data["status"] = "Active"
                #save data to database
                data.append(row_data)
                db[database][collection].save(row_data)
    return True
示例#2
0
def update_mesonet_sites(url=config.mesonet_site_url,database=config.mesonet_database,collection=config.mesonet_collection):
    """ Update mesonet sites """
    db=Connection(config.mesonet_mongo_host)
    reader = csv.reader(urllib2.urlopen(url))
    data=[]
    now = datetime.now()
    collection_backup = "%s_%s" % (collection, now.strftime("%Y_%m_%d_%H%M%S") )
    db[database][collection].rename(collection_backup)
    polydata=[]
    for itm in db.ows.watersheds.find():
        polydata.append(itm)
    aquifer_poly=[]
    for itm in db.ows.aquifers.find():
        aquifer_poly.append(itm)
    for row in reader:
        if reader.line_num == 1:
            headers = row[1:]
        else:
            row_data=dict(zip(headers, row[1:]))
            if row_data['nlat'] != '':
                #set watershed values
                for poly in polydata:
                    s= poly['geometry']
                    if gis_tools.intersect_point(s,row_data['nlat'],row_data['elon']):
                        if 'HUC_4' in poly['properties']:
                            #print 'HUC 4: ' + poly['properties']['HUC_4']
                            row_data["huc_4"]=poly['properties']['HUC_4']
                        if 'HUC_8' in poly['properties']:
                            #print 'HUC 8: ' + poly['properties']['HUC_8']
                            row_data["huc_8"]=poly['properties']['HUC_8']
                #set aquifer data
                for poly in aquifer_poly:
                    s= poly['geometry']
                    if gis_tools.intersect_point(s,row_data['nlat'],row_data['elon']):
                        row_data["aquifer"]=poly['properties']['NAME']
                        print poly['properties']['NAME']
                        break
                #set status
                date_decom = datetime.strptime(row_data["datd"], "%Y%m%d")
                if date_decom <= now:
                    row_data["status"]="Inactive"
                else:
                    row_data["status"]="Active"
                #save data to database
                data.append(row_data)
                db[database][collection].save(row_data)
    return True
示例#3
0
def owrb_well_logs_portal(rowid, database=config.owrb_database, collection=config.owrb_welllog_collection, **kwargs):
    global watershed, aquifer
    db = Connection(config.mongo_host)
    #set watershed and aquifer geodata
    if watershed:
        polydata = watershed
    else:
        polydata = []
        for itm in db.ows.watersheds.find():
            polydata.append(itm)
        watershed = polydata
    if aquifer:
        aquifer_poly = aquifer
    else:
        aquifer_poly = []
        for itm in db.ows.aquifers.find():
            aquifer_poly.append(itm)
        aquifer = aquifer_poly
    row_data = db[database][collection].find_one({'_id': rowid})
    row_data["huc_4"] = ''
    row_data["huc_8"] = ''
    for poly in polydata:
        s = poly['geometry']
        if gis_tools.intersect_point(s, row_data['LATITUDE'], row_data['LONGITUDE']):
            if 'HUC_4' in poly['properties']:
                row_data["huc_4"] = poly['properties']['HUC_4']
            if 'HUC_8' in poly['properties']:
                row_data["huc_8"] = poly['properties']['HUC_8']
    #set aquifer data
    row_data["aquifer"] = ''
    for poly in aquifer_poly:
        s = poly['geometry']
        if gis_tools.intersect_point(s, row_data['LATITUDE'], row_data['LONGITUDE']):
            row_data["aquifer"] = poly['properties']['NAME']
            break
    db[database][collection].save(row_data)
    return 1