How to use the geoalchemy2.types.Geometry function in GeoAlchemy2

To help you get started, we’ve selected a few GeoAlchemy2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geoalchemy / geoalchemy2 / tests / test_types.py View on Github external
def test_check_ctor_args_bad_srid(self):
        with pytest.raises(ArgumentError):
            Geometry(srid='foo')
github geoalchemy / geoalchemy2 / tests / test_types.py View on Github external
def test_get_col_spec_no_typmod(self):
        g = Geometry(geometry_type=None)
        assert g.get_col_spec() == 'geometry'
github jet-admin / jet-bridge / packages / jet_bridge_base / jet_bridge_base / utils / db_types.py View on Github external
{'query': sqltypes.VARCHAR, 'date_type': data_types.TEXT},
    {'query': sqltypes.TEXT, 'date_type': data_types.TEXT},
    {'query': sqltypes.BOOLEAN, 'date_type': data_types.BOOLEAN},
    {'query': sqltypes.INTEGER, 'date_type': data_types.INTEGER},
    {'query': sqltypes.SMALLINT, 'date_type': data_types.INTEGER},
    {'query': sqltypes.BIGINT, 'date_type': data_types.INTEGER},
    {'query': sqltypes.NUMERIC, 'date_type': data_types.FLOAT},
    {'query': sqltypes.DATETIME, 'date_type': data_types.DATE_TIME},
    {'query': sqltypes.TIMESTAMP, 'date_type': data_types.DATE_TIME},
    {'query': sqltypes.JSON, 'date_type': data_types.JSON},
]
default_data_type = data_types.TEXT

try:
    from geoalchemy2 import types
    map_data_types.append({'query': types.Geometry, 'date_type': data_types.GEOMETRY})
    map_data_types.append({'query': types.Geography, 'date_type': data_types.GEOGRAPHY})
except ImportError:
    pass


def map_data_type(value):
    for rule in reversed(map_data_types):
        if isinstance(value, rule['query']):
            return rule['date_type']
    return default_data_type
github flask-admin / flask-admin / examples / geo_alchemy / app.py View on Github external
import flask_admin as admin
from geoalchemy2.types import Geometry
from flask_admin.contrib.geoa import ModelView


# Create application
app = Flask(__name__)
app.config.from_pyfile('config.py')
db = SQLAlchemy(app)


class Point(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    point = db.Column(Geometry("POINT"))


class MultiPoint(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    point = db.Column(Geometry("MULTIPOINT"))


class Polygon(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    point = db.Column(Geometry("POLYGON"))


class MultiPolygon(db.Model):
    id = db.Column(db.Integer, primary_key=True)
github DallasMorningNews / socrata2sql / socrata2sql / cli.py View on Github external
def get_sql_col(col_data_type):
    """Map a Socrata column type to a SQLalchemy column class"""
    col_mappings = {
        'checkbox': Boolean,
        'url': Text,
        'text': Text,
        'number': Numeric,
        'calendar_date': DateTime,
        'point': Geometry(geometry_type='POINT', srid=4326),
        'location': Geometry(geometry_type='POINT', srid=4326),
    }

    try:
        return Column(col_mappings[col_data_type])
    except KeyError:
        msg = 'Unable to map Socrata type "%s" to a SQL type.' % col_data_type
        raise NotImplementedError(msg)
github jet-admin / jet-bridge / jet_bridge / utils / db_types.py View on Github external
map_data_types = [
    {'query': sqltypes.VARCHAR, 'date_type': data_types.TEXT},
    {'query': sqltypes.TEXT, 'date_type': data_types.TEXT},
    {'query': sqltypes.BOOLEAN, 'date_type': data_types.BOOLEAN},
    {'query': sqltypes.INTEGER, 'date_type': data_types.INTEGER},
    {'query': sqltypes.SMALLINT, 'date_type': data_types.INTEGER},
    {'query': sqltypes.NUMERIC, 'date_type': data_types.FLOAT},
    {'query': sqltypes.DATETIME, 'date_type': data_types.DATE_TIME},
    {'query': sqltypes.TIMESTAMP, 'date_type': data_types.DATE_TIME},
    {'query': sqltypes.JSON, 'date_type': data_types.JSON},
]
default_data_type = data_types.TEXT

try:
    from geoalchemy2 import types
    map_data_types.append({'query': types.Geometry, 'date_type': data_types.GEOMETRY})
    map_data_types.append({'query': types.Geography, 'date_type': data_types.GEOGRAPHY})
except ImportError:
    pass


def map_data_type(value):
    for rule in reversed(map_data_types):
        if isinstance(value, rule['query']):
            return rule['date_type']
    return default_data_type
github hotosm / ml-enabler / migrations / versions / 29c35399c52d_.py View on Github external
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('predictions', sa.Column('bbox', geoalchemy2.types.Geometry(geometry_type='POLYGON', srid=4326), nullable=True))
    op.add_column('predictions', sa.Column('version', sa.Integer(), nullable=False))
    # ### end Alembic commands ###
github ealgis / ealgis / django / ealgis / db.py View on Github external
def find_geom_column(self, table_name, srid):
        info = self.get_table(table_name)
        geom_columns = []

        for column in info.columns:
            # GeoAlchemy2 lets us find geometry columns
            if isinstance(column.type, Geometry):
                geom_columns.append(column)

        if len(geom_columns) > 1:
            raise Exception("more than one geometry column for srid '{srid}'?".format(srid=srid))
        return geom_columns[0]
github osmlab / maproulette / maproulette / models.py View on Github external
slug = db.Column(
        db.String(72),
        unique=True,
        primary_key=True,
        nullable=False)
    title = db.Column(
        db.String(128),
        nullable=False)
    description = db.Column(
        db.String,
        default="")
    blurb = db.Column(
        db.String,
        default="")
    geom = db.Column(
        Geometry('POLYGON'))
    help = db.Column(
        db.String,
        default="")
    instruction = db.Column(
        db.String,
        default="")
    active = db.Column(
        db.Boolean,
        nullable=False)
    difficulty = db.Column(
        db.SmallInteger,
        nullable=False,
        default=1)
    tasks = db.relationship(
        "Task",
        cascade="all, delete-orphan",