Beispiel #1
0
class Lake(Base):
    __tablename__ = 'lakes'

    lake_id = Column(Integer, primary_key=True)
    lake_name = Column(Unicode(40))
    lake_geom = GeometryColumn(Polygon(2, srid=4326),
                               comparator=MySQLComparator)
Beispiel #2
0
class Squares(Base, JsonifyMixin):
    __tablename__ = 'square'
    id = Column(Integer, Sequence('square_id_seq', start=1), primary_key=True)
    key_areas = relationship('Key_area',
                             secondary=square_keyarea_association,
                             backref='squares')
    geom = GeometryColumn(Polygon(dimension=2, srid=3857))

    @staticmethod
    def add_from_file(associations_filename, shp_filename):
        '''
        Добавить данные из shp-файла shp_filename. Первое поле аттрибутивной таблицы--идентификатор.
        
        Одновременно добавляются в таблицу связи данные из файла с разделителями associations_filename.
        Файл filename в формате csv (разделитель табуляция), колонки:
        square_id   key_area_id
        '''
        import transaction
        with transaction.manager:
            dbsession = DBSession()
            ogrData = ogr.Open(shp_filename)
            layer = ogrData.GetLayer(0)
            sq = layer.GetNextFeature()
            while sq is not None:
                id = sq.GetFieldAsString(0)
                geom = sq.GetGeometryRef()
                geom = geom.ExportToWkt()
                square = Squares(id=id,
                                 geom=WKTSpatialElement(geom, srid=3857))
                dbsession.add(square)

                sq = layer.GetNextFeature()
            dbsession.flush()

            reader = csv.reader(open(associations_filename), delimiter='\t')
            reader.next()
            records = [line for line in reader]

            for id, key_area_id in records:
                # Определим ключевоq уч-к по его id
                key_a = dbsession.query(Key_area).filter_by(
                    id=key_area_id).one()
                # Определим полигон по его id
                square = dbsession.query(Squares).filter_by(id=id).one()
                square.key_areas.append(key_a)

    @staticmethod
    def export_to_file(filename):
        from nextgisbio.utils.dump_to_file import dump
        fieldnames = ['square_id', 'key_area_id']

        squares_from_db = DBSession().query(Squares).join(
            Squares.key_areas).order_by(Squares.id).all()

        squares = []
        for square in squares_from_db:
            for key_area in square.key_areas:
                squares.append([square.id, key_area.id])

        dump(filename, fieldnames, squares, is_array=True)
Beispiel #3
0
class Lake(Base):
    __tablename__ = 'lakes'

    lake_id = Column(Integer, primary_key=True)
    lake_name = Column(String)
    lake_geom = GeometryColumn(Polygon(2, srid=4326, spatial_index=False),
                               comparator=SQLiteComparator)
Beispiel #4
0
class RestrictionArea(Base):
    __label__ = _(u'restrictionarea')
    __plural__ = _(u'restrictionareas')
    __tablename__ = 'restrictionarea'
    __table_args__ = {'schema': _schema}
    __acl__ = [
        (Allow, AUTHORIZED_ROLE, ALL_PERMISSIONS),
    ]

    id = Column(types.Integer, primary_key=True)
    area = GeometryColumn(Polygon(srid=_srid))
    name = Column(types.Unicode, label=_(u'Name'))
    description = Column(types.Unicode, label=_(u'Description'))
    readwrite = Column(types.Boolean, label=_(u'Read-write mode'), default=False)

    # relationship with Role and Layer
    roles = relationship(
        'Role', secondary=role_ra,
        backref='restrictionareas', cascade='save-update,merge,refresh-expire')
    layers = relationship(
        'Layer', secondary=layer_ra,
        backref='restrictionareas', cascade='save-update,merge,refresh-expire')

    def __init__(self, name='', description='', layers=[], roles=[],
                 area=None, readwrite=False):
        self.name = name
        self.description = description
        self.layers = layers
        self.roles = roles
        self.area = area
        self.readwrite = readwrite

    def __unicode__(self):
        return self.name or u''  # pragma: nocover
Beispiel #5
0
class Lake(Base):
    __tablename__ = 'lakes'

    id = Column(types.Integer, primary_key=True)
    name = Column(types.String, nullable=False)

    category_id = Column(types.Integer, ForeignKey('categories.cid'))
    categorie = relationship(Category)

    the_geom = GeometryColumn(Polygon(dimension=2, srid=4326))
Beispiel #6
0
class Street(Base):
    __tablename__ = 'street'

    id = Column(Integer, Sequence('street_id_seq'), primary_key=True)
    name = Column(Text, nullable=True)
    bounds_left = Column(DOUBLE_PRECISION)
    bounds_right = Column(DOUBLE_PRECISION)
    bounds_top = Column(DOUBLE_PRECISION)
    bounds_bottom = Column(DOUBLE_PRECISION)
    box = GeometryColumn(Polygon(2))
    locality = relationship('Locality')
    locality_id = Column(Integer, ForeignKey('locality.id'), nullable=True)
Beispiel #7
0
class Area(Base):
    __tablename__ = 'area'

    id = Column(Integer, Sequence('area_id_seq'), primary_key=True)
    name = Column(Text, nullable=True)
    bounds_left = Column(DOUBLE_PRECISION)
    bounds_right = Column(DOUBLE_PRECISION)
    bounds_top = Column(DOUBLE_PRECISION)
    bounds_bottom = Column(DOUBLE_PRECISION)
    box = GeometryColumn(Polygon(2))
    district = relationship('District')
    district_id = Column(Integer, ForeignKey('district.id'), nullable=True)
Beispiel #8
0
class Role(Base):
    __label__ = _(u'role')
    __plural__ = _(u'roles')
    __tablename__ = 'role'
    __table_args__ = {'schema': _schema}
    __acl__ = [
        (Allow, AUTHORIZED_ROLE, ALL_PERMISSIONS),
    ]
    id = Column(types.Integer, primary_key=True)
    name = Column(types.Unicode, unique=True, nullable=False, label=_(u'Name'))
    description = Column(types.Unicode, label=_(u'Description'))
    extent = GeometryColumn(Polygon(srid=_srid))
    #product = Column(types.Unicode)

    # functionality
    functionalities = relationship('Functionality',
                                   secondary=role_functionality,
                                   cascade='save-update,merge,refresh-expire')

    def __init__(self,
                 name=u'',
                 description=u'',
                 functionalities=[],
                 extent=None):
        self.name = name
        self.functionalities = functionalities
        self.extent = extent
        self.description = description

    def __unicode__(self):
        return self.name or u''  # pragma: nocover

    def _json_extent(self):
        if self.extent is None:
            return None

        coords = self.extent.coords(DBSession)
        left = coords[0][0][0]
        right = coords[0][0][0]
        top = coords[0][0][1]
        bottom = coords[0][0][1]
        for way in coords:
            for coord in way:
                left = min(left, coord[0])
                right = max(right, coord[0])
                bottom = min(bottom, coord[1])
                top = max(top, coord[1])
        return "[%i, %i, %i, %i]" % (left, bottom, right, top)

    json_extent = property(_json_extent)
Beispiel #9
0
class Area(Base, GeometryTableMixIn):
    __tablename__ = 'areas'
    # The following fragment needed to be commented out in order to
    # make table creation succeed from: paster setup-app development.ini
    # Additionally, this file needs to be imported in websetup.py
    #__table_args__ = {
    #    "autoload": True,
    #    "autoload_with": Session.bind
    #}

    # A primary key column is required by SQLAlchemy to create DDL
    # statements
    id = Column(types.Integer, primary_key=True)
    the_geom = GeometryColumn(Polygon(srid=4326))
Beispiel #10
0
class Overlap(Base):
    __tablename__ = 'overlap'

    id = Column(Integer, primary_key=True)
    geom = GeometryColumn(Polygon(2))
Beispiel #11
0
class Lake(Base):
    __tablename__ = 'lakes'

    lake_id = Column(Integer, primary_key=True)
    lake_name = Column(String)
    lake_geom = GeometryColumn(Polygon(2))
Beispiel #12
0
class Lake(Base, GeometryTableMixIn):
    __tablename__ = 'lakes'

    id = Column(Integer, primary_key=True)
    depth = Column(Numeric(asdecimal=False))
    geom = GeometryColumn(Polygon(2))
Beispiel #13
0
class Lake(Base):
    __tablename__ = 'lakes'

    lake_id = Column(Integer, primary_key=True)
    lake_name = Column(String(255))
    lake_geom = GeometryColumn(Polygon(2), comparator=MSComparator)
Beispiel #14
0
class Lake(Base):
    __tablename__ = 'lakes'

    lake_id = Column(Integer, autoincrement=True, primary_key=True)
    lake_name = Column(Unicode(40))
    lake_geom = GeometryColumn(Polygon(2), nullable=False)
Beispiel #15
0
class Lake(Base, GeometryTableMixIn):
    __tablename__ = 'lakes_mf'

    id = Column(Integer, Sequence('lakes_mf_id_seq'), primary_key=True)
    depth = Column(Numeric(precision=10, scale=2, asdecimal=False))
    geom = GeometryColumn(Polygon(2, diminfo=diminfo))