示例#1
0
 def get_typical_species(self):
     session = Session()
     try:
         habitat_species_links = session.query(HabitatTypesSpecies).filter(
             HabitatTypesSpecies.type_id == self.type_id).all()
         species_ids = [lnk.species_id for lnk in habitat_species_links]
         species = session.query(Species).filter(
             Species.species_id.in_(species_ids)).all()
     except:
         species = None
     finally:
         session.close()
     return species
示例#2
0
 def get_associated_habitat_types(self):
     session = Session()
     try:
         species_habitat_links = session.query(HabitatTypesSpecies).filter(
             HabitatTypesSpecies.species_id == self.species_id).all()
         type_ids = [lnk.type_id for lnk in species_habitat_links]
         habitat_types = session.query(HabitatType).filter(
             HabitatType.type_id.in_(type_ids)).all()
     except:
         habitat_types = None
     finally:
         session.close()
     return habitat_types
示例#3
0
文件: n2k.py 项目: leaffan/geo
 def get_associated_habitat_types(self):
     session = Session()
     try:
         species_habitat_links = session.query(HabitatTypesSpecies).filter(
             HabitatTypesSpecies.species_id == self.species_id
         ).all()
         type_ids = [lnk.type_id for lnk in species_habitat_links]
         habitat_types = session.query(HabitatType).filter(
             HabitatType.type_id.in_(type_ids)
             ).all()
     except:
         habitat_types = None
     finally:
         session.close()
     return habitat_types
示例#4
0
文件: n2k.py 项目: leaffan/geo
 def get_typical_species(self):
     session = Session()
     try:
         habitat_species_links = session.query(HabitatTypesSpecies).filter(
             HabitatTypesSpecies.type_id == self.type_id
         ).all()
         species_ids = [lnk.species_id for lnk in habitat_species_links]
         species = session.query(Species).filter(
             Species.species_id.in_(species_ids)
             ).all()
     except:
         species = None
     finally:
         session.close()
     return species
示例#5
0
文件: db_n2k.py 项目: leaffan/geo
 def get_species(self):
     session = Session()
     try:
         species = session.query(DbSpecies).filter(
             DbSpecies.species_id == self.species_id).one()
     except:
         species = None
     finally:
         session.close()
     return species
示例#6
0
文件: db_n2k.py 项目: leaffan/geo
 def find(self, species_name):
     session = Session()
     try:
         species = session.query(DbSpecies).filter(
             DbSpecies.name == species_name).one()
     except:
         species = None
     finally:
         session.close()
     return species
示例#7
0
 def find_by_id(self, type_id):
     session = Session()
     try:
         habitat_type = session.query(HabitatType).filter(
             HabitatType.type_id == type_id).one()
     except:
         habitat_type = None
     finally:
         session.close()
     return habitat_type
示例#8
0
文件: db_n2k.py 项目: leaffan/geo
 def find(self, species_name):
     session = Session()
     try:
         species = session.query(DbSpecies).filter(
             DbSpecies.name == species_name
             ).one()
     except:
         species = None
     finally:
         session.close()
     return species
示例#9
0
文件: db_n2k.py 项目: leaffan/geo
 def get_species(self):
     session = Session()
     try:
         species = session.query(DbSpecies).filter(
             DbSpecies.species_id == self.species_id
             ).one()
     except:
         species = None
     finally:
         session.close()
     return species
示例#10
0
文件: n2k.py 项目: leaffan/geo
 def find_by_id(self, type_id):
     session = Session()
     try:
         habitat_type = session.query(HabitatType).filter(
             HabitatType.type_id == type_id
             ).one()
     except:
         habitat_type = None
     finally:
         session.close()
     return habitat_type
示例#11
0
 def find_by_name(self, name):
     session = Session()
     try:
         species = session.query(Species).filter(Species.name == name).one()
     except:
         # finding species
         spf = SpeciesFinder(name)
         sp_name, sp_url, sp_info = spf.find_species()
         # creating new species
         species = Species(sp_name, sp_url, sp_info)
         # adding species to database
         session.merge(species)
         session.commit()
     finally:
         session.close()
     return species
示例#12
0
文件: n2k.py 项目: leaffan/geo
 def find_by_name(self, name):
     session = Session()
     try:
         species = session.query(Species).filter(
             Species.name == name
             ).one()
     except:
         # finding species
         spf = SpeciesFinder(name)
         sp_name, sp_url, sp_info = spf.find_species()
         # creating new species
         species = Species(sp_name, sp_url, sp_info)
         # adding species to database
         session.merge(species)
         session.commit()
     finally:
         session.close()
     return species
示例#13
0
文件: db_n2k.py 项目: leaffan/geo
    __autoload__ = True
    __table_args__ = {'autoload_with': Engine}

    def __init__(self):
        pass
    
if __name__ == '__main__':
    
    from operator import attrgetter
    
    habitat_type = '9120'

    session = Session()
    
    # retrieving all sites with the current habitat type
    sites_with_habitat_type = session.query(DbSitesHabitatTypes).filter(
        DbSitesHabitatTypes.type_id == habitat_type).all()
    # retrieving typical species for current habitat type
    typical_species = session.query(DbHabitatTypesSpecies).filter(
        DbHabitatTypesSpecies.type_id == habitat_type).all()

    # reducing sites to site ids
    f = attrgetter('site_id')
    site_ids = [f(site) for site in sites_with_habitat_type]
    # reducing species to species ids
    f = attrgetter('species_id')
    species_ids = [f(typical_sp) for typical_sp in typical_species]

    # retrieving all map tiles that intersect with the previously retrieved sites
    map_ids = session.query(DbSiteOnQuadTile).filter(
        DbSiteOnQuadTile.site_id.in_(site_ids)).all()
示例#14
0
from common import Session

from first import Domain_ as FirstDomain
from second import Domain_ as SecondDomain


if __name__ == '__main__':
    session = Session()
    print session.query(SecondDomain).one()
    print session.query(FirstDomain).one()
示例#15
0
文件: n2k.py 项目: leaffan/geo
    #    new_species = Species(sp_name, sp_url, sp_info)
    #    session.merge(new_species)
    #    session.commit()
    #    print "Done"

    from sqlalchemy import and_
    
    tgt = r"D:\work\ms.monina\wp4\florkart_2012_occurrences_eunis_characteristic_species_n2k_areas_germany.txt"
    
    habitat_type = '9120'
    
    output = list()

    session = Session()
    
    habitat_types = session.query(HabitatType).all()
    
    for ht in habitat_types[:]:
    
        habitat_type = ht.type_id
    
        # retrieving all sites with the current habitat type
        sites_with_habitat_type = session.query(SitesHabitatTypes).filter(
            SitesHabitatTypes.type_id == habitat_type).all()
        
        # bailing out if no sites were found
        if not len(sites_with_habitat_type):
            continue

        print "Working on habitat type %s (%s)..." % (habitat_type, ht.shortname)
    
示例#16
0
    #    new_species = Species(sp_name, sp_url, sp_info)
    #    session.merge(new_species)
    #    session.commit()
    #    print "Done"

    from sqlalchemy import and_

    tgt = r"D:\work\ms.monina\wp4\florkart_2012_occurrences_eunis_characteristic_species_n2k_areas_germany.txt"

    habitat_type = '9120'

    output = list()

    session = Session()

    habitat_types = session.query(HabitatType).all()

    for ht in habitat_types[:]:

        habitat_type = ht.type_id

        # retrieving all sites with the current habitat type
        sites_with_habitat_type = session.query(SitesHabitatTypes).filter(
            SitesHabitatTypes.type_id == habitat_type).all()

        # bailing out if no sites were found
        if not len(sites_with_habitat_type):
            continue

        print "Working on habitat type %s (%s)..." % (habitat_type,
                                                      ht.shortname)
示例#17
0
文件: db_n2k.py 项目: leaffan/geo
    __table_args__ = {'autoload_with': Engine}

    def __init__(self):
        pass


if __name__ == '__main__':

    from operator import attrgetter

    habitat_type = '9120'

    session = Session()

    # retrieving all sites with the current habitat type
    sites_with_habitat_type = session.query(DbSitesHabitatTypes).filter(
        DbSitesHabitatTypes.type_id == habitat_type).all()
    # retrieving typical species for current habitat type
    typical_species = session.query(DbHabitatTypesSpecies).filter(
        DbHabitatTypesSpecies.type_id == habitat_type).all()

    # reducing sites to site ids
    f = attrgetter('site_id')
    site_ids = [f(site) for site in sites_with_habitat_type]
    # reducing species to species ids
    f = attrgetter('species_id')
    species_ids = [f(typical_sp) for typical_sp in typical_species]

    # retrieving all map tiles that intersect with the previously retrieved sites
    map_ids = session.query(DbSiteOnQuadTile).filter(
        DbSiteOnQuadTile.site_id.in_(site_ids)).all()