Exemplo n.º 1
0
 def process(self):
     log.debug('Start vector import process. Task %d' % self.task_id)
     try:
         with self.task() as task:
             mapping = Mapping(None, None, '*', other_srs=task.srs)
             couch = VectorCouchDB('http://%s:%s' % ('127.0.0.1', self.app_state.config.get('couchdb', 'port')), task.db_name, task.title)
             # import from file
             if task.source == 'file':
                 input_file = self.app_state.user_data_path('import', task.file_name)
                 if task.type_ == 'geojson':
                     records = json.loads(open(input_file).read())
                     couch.store_records(
                         records['features']
                     )
                 elif task.type_ == 'gml':
                     couch.store_records(
                         load_json_from_gml(input_file, mapping)
                     )
                 elif task.type_ == 'shp':
                     couch.store_records(
                         load_json_from_shape(input_file, mapping)
                     )
             # import from couch db - source name is couchdb name
             else:
                 couch_src = CouchFileBox('http://%s:%s' % ('127.0.0.1', self.app_state.config.get('couchdb', 'port')), task.source)
                 records = couch_src.get_attachment(task.file_name)
                 couch.store_records(
                     records['features']
                 )
         self.task_done()
     except ConvertError, e:
         self.task_failed(e)
Exemplo n.º 2
0
 def process(self):
     log.debug('Start vector import process. Task %d' % self.task_id)
     try:
         with self.task() as task:
             mapping = Mapping(None, None, '*', other_srs=task.srs)
             couch = VectorCouchDB(
                 'http://%s:%s' %
                 ('127.0.0.1', self.app_state.config.get(
                     'couchdb', 'port')), task.db_name, task.title)
             # import from file
             if task.source == 'file':
                 input_file = self.app_state.user_data_path(
                     'import', task.file_name)
                 if task.type_ == 'geojson':
                     records = json.loads(open(input_file).read())
                     couch.store_records(records['features'])
                 elif task.type_ == 'gml':
                     couch.store_records(
                         load_json_from_gml(input_file, mapping))
                 elif task.type_ == 'shp':
                     couch.store_records(
                         load_json_from_shape(input_file, mapping))
             # import from couch db - source name is couchdb name
             else:
                 couch_src = CouchFileBox(
                     'http://%s:%s' %
                     ('127.0.0.1',
                      self.app_state.config.get('couchdb', 'port')),
                     task.source)
                 records = couch_src.get_attachment(task.file_name)
                 couch.store_records(records['features'])
         self.task_done()
     except ConvertError, e:
         self.task_failed(e)
Exemplo n.º 3
0
def upload_gml():
    app_state = current_app.config.geobox_state

    form = forms.GMLUploadForm()
    form.srs.choices = list(app_state.config.get('web', 'available_srs'))
    form.srs.choices.insert(0, ('', _('-- select srs --'), ''))

    if form.validate_on_submit():
        upload_file = request.files['upload_file']
        if upload_file:
            mapping = Mapping(None, None, '*', other_srs=form.srs.data)
            couch_url = 'http://%s:%s' % (
                '127.0.0.1', app_state.config.get('couchdb', 'port'))
            db_name = '%s_%s' % (app_state.home_server.prefix,
                                 app_state.config.get(
                                     'web', 'authorization_layer_name'))
            couch = VectorCouchDB(
                couch_url, db_name,
                app_state.config.get('web', 'authorization_layer_title'))
            couch.remove_all_features()
            couch.store_records(load_json_from_gml(upload_file, mapping))

            download_coverage = couch.coverage()

            db_session = app_state.user_db_session()
            sources = db_session.query(ExternalWMTSSource).filter_by(
                is_public=False).all()
            for source in sources:
                source.download_coverage = json.dumps(download_coverage)
            db_session.commit()

            flash(
                _('gml file %(name)s successfully uploaded and geometries added to %(auth_layer_title)s',
                  name=upload_file.filename,
                  auth_layer_title=app_state.config.get(
                      'web', 'authorization_layer_title')), 'info')
            return redirect(url_for('main.index'))

    return render_template('admin/upload_gml.html', form=form)