Пример #1
0
 def test_shape_aoi(self):
     print('TEST2<<<<')
     geom = spatial.shape_geometry(self.long, self.lat)
     shape, center = spatial.shape_aoi(geom)
     print(shape)
     try:
         conversion = self.conn.execute('SELECT %s::geometry;',
                                        (shape, )).first()
         assert conversion
     except Exception as e:
         print('TEST FAILED')
         raise e
     # SELECT 'SRID=3857;POLYGON(((-179.748110962 -22.8178), (-178.348110962 -22.8178),
     # (-179.048 -22.1178405762), (-179.048 -23.5178405762), (-179.748110962 -22.8178), ))'::geometry;
     print('TEST PASSED\n')
Пример #2
0
    def setUp(self):
        """Create a random square."""
        geojson = {
                "geometry": {
                    "type": "Polygon",
                    "coordinates": rand_polygon()
                }
            }
        # simulate a single view/area
        self.polygon_avg = spatial.from_list_to_ewkt(geojson['geometry']['coordinates'])
        # simulate a view with 3 areas
        p = (-14, -68)  # rand_coordinates()
        self.polygon_big, _ = spatial.shape_aoi(p, size=8)  # spatial.from_list_to_ewkt(rand_polygon(size=12))
        # simulate a random point

        self.point = spatial.shape_geometry(p[0], p[1])
Пример #3
0
 def test_insert_area_and_center(self):
     """Test insertion of row in t_areas"""
     geom = spatial.shape_geometry(self.long, self.lat)
     shape, center = spatial.shape_aoi(geom)
     try:
         self.conn.execute(
             'INSERT INTO t_areas(center, aoi) VALUES (\'{center}\', \'{polygon}\');'
             .format(center=center, polygon=shape))
         select = self.conn.execute(
             'SELECT  COUNT(id) FROM t_areas WHERE center = \'{center}\';'.
             format(center=center)).fetchall()
         self.assertEqual(select[0][0], 1)
     except Exception as e:
         print('TEST FAILED')
         raise e
     print('TEST PASSED\n')
Пример #4
0
    def store_new_aoi(cls, center):
        """
        There is no area for this center, a new area is stored
        with center equal to this center.

        :param str center: a EWKT string of a point
        :return object: Controller object
        """
        area, center = spatial.shape_aoi(center)
        points = cls.find_all_points_in_(area)
        geojson = cls.serialize_geojson(points) if len(
            points) != 0 is not None else cls.initialize_geojson(center)
        ins = Areas.__table__.insert().values(aoi=area,
                                              center=center,
                                              data=geojson)
        cls.alchemy.execute(ins)
        return Controller(area)
 def test_shape_aoi(self):
     print('TEST2<<<<')
     geom = spatial.shape_geometry(self.long, self.lat)
     shape, center = spatial.shape_aoi(geom)
     print(shape)
     try:
         conversion = self.conn.execute(
             'SELECT %s::geometry;',
             (shape, )
         ).first()
         assert conversion
     except Exception as e:
         print('TEST FAILED')
         raise e
     # SELECT 'SRID=3857;POLYGON(((-179.748110962 -22.8178), (-178.348110962 -22.8178),
     # (-179.048 -22.1178405762), (-179.048 -23.5178405762), (-179.748110962 -22.8178), ))'::geometry;
     print('TEST PASSED\n')
def test_should_return_an_exisiting_area():
    from src.xco2 import Areas
    from sqlalchemy import func
    from src.spatial import spatial
    # get a center from t_areas
    # build a smaller area around it
    # check if ST_Contains find the area in the db
    query = Areas.__table__.select().limit(1)
    one = dbProxy.alchemy.execute(query).first()
    square, _ = spatial.shape_aoi(one.center, size=1)

    contains = Areas.__table__.select().where(
        func.ST_Contains(Areas.aoi, square))
    c_query = dbProxy.alchemy.execute(contains).fetchall()

    if c_query:
        for c in c_query:
            print(c.id, c.aoi, '\n')
    else:
        raise AssertionError('test_should_return_an_exisiting_area FAILED')
Пример #7
0
    def store_new_aoi(cls, center):
        """
        There is no area for this center, a new area is stored
        with center equal to this center.

        :param str center: a EWKT string of a point
        :return object: Controller object
        """
        area, center = spatial.shape_aoi(center)
        points = cls.find_all_points_in_(area)
        geojson = cls.serialize_geojson(
            points
        ) if len(points) != 0 is not None else cls.initialize_geojson(center)
        ins = Areas.__table__.insert().values(
            aoi=area,
            center=center,
            data=geojson
        )
        cls.alchemy.execute(ins)
        return Controller(area)
def test_should_return_an_exisiting_area():
    from src.xco2 import Areas
    from sqlalchemy  import func
    from src.spatial import spatial
    # get a center from t_areas
    # build a smaller area around it
    # check if ST_Contains find the area in the db
    query = Areas.__table__.select().limit(1)
    one = dbProxy.alchemy.execute(query).first()
    square, _ = spatial.shape_aoi(one.center, size=1)

    contains = Areas.__table__.select().where(
        func.ST_Contains(Areas.aoi, square)
    )
    c_query = dbProxy.alchemy.execute(contains).fetchall()

    if c_query:
        for c in c_query:
            print(c.id, c.aoi, '\n')
    else:
        raise AssertionError('test_should_return_an_exisiting_area FAILED' )
 def test_insert_area_and_center(self):
     """Test insertion of row in t_areas"""
     geom = spatial.shape_geometry(self.long, self.lat)
     shape, center = spatial.shape_aoi(geom)
     try:
         self.conn.execute(
             'INSERT INTO t_areas(center, aoi) VALUES (\'{center}\', \'{polygon}\');'.format(
                 center=center,
                 polygon=shape
             )
         )
         select = self.conn.execute(
             'SELECT  COUNT(id) FROM t_areas WHERE center = \'{center}\';'.format(
                 center=center
             )
         ).fetchall()
         self.assertEqual(
             select[0][0],
             1
         )
     except Exception as e:
         print('TEST FAILED')
         raise e
     print('TEST PASSED\n')
Пример #10
0
 def __init__(self, center):
     from src.spatial import spatial
     self.center = center
     self.aoi = spatial.shape_aoi(self.center)
     self.data = None