def setdb(url):
    db = AlchemyDataAccess()
    db.connect(url)
    db.create_all(True)
    db.add_postgis_extension()
    set_spatial_units(db)
    return db
Ejemplo n.º 2
0
def setdb(url):
    db = AlchemyDataAccess()
    db.connect(url)
    db.create_all(True)
    db.add_postgis_extension()
    SpatialUnitDynamicMapperFactory.instance().dataaccess = db
    return db
Ejemplo n.º 3
0
def test_as_attribute_name():
    url = 'postgresql://*****:*****@localhost:5432/as_attrname'
    db = AlchemyDataAccess()
    db.connect(url)
    db.create(True)
    db.add_postgis_extension()
    db.create_all_tables()
    SpatialUnitDynamicMapperFactory.instance().dataaccess = db
    tablename1 = 'amz_states'
    shpfilepath1 = os.path.join(os.path.dirname(__file__), '../../data',
                                'amz_states_epsg_4326.shp')
    as_attribute_name = 'NM_ESTADO'
    gp = Geoprocessing()
    sus1 = SpatialUnitInfoRepository(db)
    uc1 = AddSpatialUnit(tablename1, shpfilepath1, as_attribute_name, sus1,
                         SpatialUnitDynamicMapperFactory.instance(), gp)
    su1 = uc1.execute(db)
    sus_list = sus1.list()
    assert len(sus_list) == 1
    assert sus_list[0].dataname == tablename1
    assert sus_list[0].as_attribute_name == 'NM_ESTADO'
    assert sus_list[0].centroid.lat == -6.384962796500002
    assert sus_list[0].centroid.lng == -58.97111531179317
    surepo1 = SpatialUnitDynamicMapperFactory.instance()\
       .create_spatial_unit(tablename1, as_attribute_name)
    su1 = surepo1.get()
    assert len(su1.features) == 13
    assert su1.features[0].name == 'ACRE'
    assert su1.features[1].name == 'AMAPÁ'
    db.drop()
Ejemplo n.º 4
0
def test_intersection_area():
    url = 'postgresql://*****:*****@localhost:5432/intersection_area'
    db = AlchemyDataAccess()
    db.connect(url)
    db.create(True)
    db.add_postgis_extension()
    shpfilepath = os.path.join(os.path.dirname(__file__), '../../data',
                               'csAmz_150km_epsg_4326.shp')
    geoprocess = Geoprocessing()
    geoprocess.export_shp_to_postgis(shpfilepath, 'csAmz_150km', 'suid',
                                     db.engine, True)
    add_suid('csAmz_150km', db.engine)
    SpatialUnitDynamicMapperFactory.instance().dataaccess = db
    SpatialUnitDynamicMapperFactory.instance().add_class_mapper('csAmz_150km')
    sunit = SpatialUnitDynamicMapperFactory.instance().create_spatial_unit(
        'csAmz_150km', 'id')
    feats = sunit.list()
    deter = DeterRepository()
    a1 = deter.get(59241)
    a1geom = a1.geom
    for f in feats:
        fgeom = f.geom
        if fgeom.intersects(a1geom):
            area_info1 = geoprocess.intersection_area(fgeom, a1geom)
            area_info2 = geoprocess.intersection_area(a1geom, fgeom)
            assert area_info1['percentage'] == 0.001008271044465656
            assert area_info2['percentage'] == 100
            assert area_info1['area'] == area_info2[
                'area'] == 0.22686098500569116
            assert fgeom.intersection(a1geom).area == a1geom.area
    db.drop()
Ejemplo n.º 5
0
def test_add_two_spatial_units():
    url = 'postgresql://*****:*****@localhost:5432/two_sus'
    db = AlchemyDataAccess()
    db.connect(url)
    db.create(True)
    db.add_postgis_extension()
    db.create_all_tables()
    SpatialUnitDynamicMapperFactory.instance().dataaccess = db
    tablename1 = 'csAmz_150km'
    tablename2 = 'csAmz_300km'
    as_attribute_name = 'id'
    shpfilepath1 = os.path.join(os.path.dirname(__file__), '../../data',
                                'csAmz_150km_epsg_4326.shp')
    shpfilepath2 = os.path.join(os.path.dirname(__file__), '../../data',
                                'csAmz_300km_epsg_4326.shp')
    gp = Geoprocessing()
    sus1 = SpatialUnitInfoRepository(db)
    uc1 = AddSpatialUnit(tablename1, shpfilepath1, as_attribute_name, sus1,
                         SpatialUnitDynamicMapperFactory.instance(), gp)
    uc2 = AddSpatialUnit(tablename2, shpfilepath2, as_attribute_name, sus1,
                         SpatialUnitDynamicMapperFactory.instance(), gp)
    su1 = uc1.execute(db)
    su2 = uc2.execute(db)
    sus2 = SpatialUnitInfoRepository(db)
    sus_list = sus2.list()
    assert len(sus_list) == 2
    assert sus_list[0].dataname == tablename1
    assert sus_list[1].dataname == tablename2
    assert sus_list[0].as_attribute_name == 'id'
    assert sus_list[1].as_attribute_name == 'id'
    assert sus_list[0].centroid.lat == -5.491382969006503
    assert sus_list[0].centroid.lng == -58.467185764253415
    assert sus_list[1].centroid.lat == -5.491382969006503
    assert sus_list[1].centroid.lng == -57.792239759933764
    surepo1 = SpatialUnitDynamicMapperFactory.instance()\
       .create_spatial_unit(tablename1, as_attribute_name)
    surepo2 = SpatialUnitDynamicMapperFactory.instance()\
       .create_spatial_unit(tablename2, as_attribute_name)
    su1 = surepo1.get()
    su2 = surepo2.get()
    assert len(su1.features) == 240
    assert len(su2.features) == 70
    db.drop()
Ejemplo n.º 6
0
def test_export_shp_to_postgis():
    url = 'postgresql://*****:*****@localhost:5432/shp_to_postgis'
    db = AlchemyDataAccess()
    db.connect(url)
    db.create(True)
    db.add_postgis_extension()
    shpfilepath = os.path.join(os.path.dirname(__file__), '../../data',
                               'csAmz_150km_epsg_4326.shp')
    geoprocess = Geoprocessing()
    geoprocess.export_shp_to_postgis(shpfilepath, 'csAmz_150km', 'suid',
                                     db.engine, True)
    add_suid('csAmz_150km', db.engine)
    SpatialUnitDynamicMapperFactory.instance().dataaccess = db
    SpatialUnitDynamicMapperFactory.instance().add_class_mapper('csAmz_150km')
    sunit = SpatialUnitDynamicMapperFactory.instance().create_spatial_unit(
        'csAmz_150km', 'id')
    cells = sunit.list()
    assert len(cells) == 240
    assert cells[0].id == 0
    assert cells[-1].id == 239
    db.drop()
Ejemplo n.º 7
0
import sys
sys.path.insert(0,'..')
import warnings
warnings.filterwarnings("ignore")
from ams.usecases import DeterDailyUpdate
from ams.usecases import Initializer
from ams.repository import (DeterRepository,
							SpatialUnitInfoRepository)
from ams.dataaccess import AlchemyDataAccess
from webapp.app.config import Config
from ams.usecases.classify_deter_polygons import ClassifyDeterPolygons

da = AlchemyDataAccess()
da.connect(Config.DATABASE_URL)
su_info_repo = SpatialUnitInfoRepository(da)
init = Initializer(su_info_repo)
init.execute(da)
deter_repo = DeterRepository()
update = DeterDailyUpdate(deter_repo, -1, Config.DATABASE_URL)
update.execute(da, True)

class_deter_polys = ClassifyDeterPolygons(Config.DATABASE_URL, Config.INPUT_GEOTIFF_FUNDIARY_STRUCTURE)
class_deter_polys.execute()
Ejemplo n.º 8
0
 def createdb(url: str) -> DataAccess:
     db = AlchemyDataAccess()
     db.connect(url)
     db.create_all(True)
     db.add_postgis_extension()
     return db
Ejemplo n.º 9
0
from ams.usecases import DeterDailyUpdate, Initializer
from ams.repository import (DeterRepository, SpatialUnitInfoRepository)
from ams.dataaccess import AlchemyDataAccess

db_url = 'postgresql://*****:*****@localhost:5432/AMS'
da = AlchemyDataAccess()
da.connect(db_url)
su_info_repo = SpatialUnitInfoRepository(da)
init = Initializer(su_info_repo)
init.execute(da)
deter_repo = DeterRepository()
update = DeterDailyUpdate(deter_repo, 60)
update.execute(da)
update.terminate()