Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.logger.info('Action: populateTables()')
session = scoped_session(sessionmaker(bind=self.userEngine))
for model in models:
count = 1
shpFiles = model.__shapefiles__
for shpFile in shpFiles:
if not os.path.exists(shpFile):
self.logger.error('Shapefile %s does not exists' % shpFile)
sys.exit(1)
features = ShpToGDALFeatures(shpFile).__read__()
bulk = BulkInsert(model, session, withAutoCommit=1000)
for feature in features:
polygon = feature.GetGeometryRef()
bulk.add(dict(
id=count,
the_geom=WKTElement(polygon.ExportToWkt(), 4326)
))
count += 1
bulk.commit()
self.logger.info('Commit features for %s.' % shpFile)
self.logger.info('All tables have been created.')
def to_internal_value_item(self, value):
if value is None:
return
from geoalchemy2 import ArgumentError, WKTElement
try:
return WKTElement(value)
except ArgumentError as e:
self.error('invalid', error=six.text_type(e))
lambda x: WKTElement(x, srid=srid)
)
def store_intersection(id, ints, lat, lon, elev):
""" Store intersections in DB """
loc = 'POINT(%r %r)' % (lon, lat)
i = GIntersection(
id=id, ints=ints, lat=lat, lon=lon, loc=WKTElement(loc, srid=4326),
elev=elev
)
session.add(i)
return None
df['geom'] = df.apply(lambda r: WKTElement('POINT({} {})'.format(r[dataset.longitude_attr], r[dataset.latitude_attr])), axis=1)
df.to_sql(table_name, engine, if_exists='append', index_label='geoguide_id', chunksize=CHUNKSIZE, dtype={'geom': Geometry('POINT')})