Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_check_ctor_args_bad_srid(self):
with pytest.raises(ArgumentError):
Geometry(srid='foo')
def test_get_col_spec_no_typmod(self):
g = Geometry(geometry_type=None)
assert g.get_col_spec() == 'geometry'
{'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
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)
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)
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
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 ###
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]
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",