def _create_db_featurestore(name, data, overwrite=False, charset=None): """Create a database store then use it to import a shapefile. If the import into the database fails then delete the store (and delete the PostGIS table for it). """ cat = Layer.objects.gs_catalog try: ds = cat.get_store(settings.DB_DATASTORE_NAME) except FailedRequestError: ds = cat.create_datastore(settings.DB_DATASTORE_NAME) ds.connection_parameters.update( host=settings.DB_DATASTORE_HOST, port=settings.DB_DATASTORE_PORT, database=settings.DB_DATASTORE_DATABASE, user=settings.DB_DATASTORE_USER, passwd=settings.DB_DATASTORE_PASSWORD, dbtype=settings.DB_DATASTORE_TYPE) cat.save(ds) ds = cat.get_store(settings.DB_DATASTORE_NAME) try: cat.add_data_to_store(ds, name, data, overwrite=overwrite, charset=charset) return ds, cat.get_resource(name, store=ds) except Exception: delete_from_postgis(name) raise
def _create_db_featurestore(name, data, overwrite=False, charset=None): """Create a database store then use it to import a shapefile. If the import into the database fails then delete the store (and delete the PostGIS table for it). """ cat = Layer.objects.gs_catalog dsname = OGC_SERVER['default']['OPTIONS']['DATASTORE'] try: ds = cat.get_store(dsname) except FailedRequestError: ds = cat.create_datastore(dsname) db = settings.DATABASES[dsname] ds.connection_parameters.update( host = db['HOST'], port = db['PORT'], database = db['NAME'], user = db['USER'], passwd = db['PASSWORD'], dbtype = db['ENGINE']) cat.save(ds) ds = cat.get_store(dsname) try: cat.add_data_to_store(ds, name, data, overwrite=overwrite, charset=charset) return ds, cat.get_resource(name, store=ds) except Exception: delete_from_postgis(name) raise