示例#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)
示例#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)
示例#3
0
def editor():
    export_form = ExportVectorForm()
    export_form.srs.choices = list(
        current_app.config.geobox_state.config.get('web', 'available_srs'))

    user = current_app.config.geobox_state.user

    target_box_name = 'file_box' if user.is_consultant else 'upload_box'
    target_box_label = _('filebox') if user.is_consultant else _('upload_box')
    target_box = current_app.config.geobox_state.config.get(
        'couchdb', target_box_name)
    export_form.destination.choices = [('file', _('Filesystem')),
                                       (target_box, target_box_label)]

    # load preview layer
    preview_features = False
    preview_layername = False

    box_name = request.args.get('box_name', False)
    filename = request.args.get('filename', False)
    if box_name and filename:
        couchbox = get_couch_box_db(box_name)
        couch_src = CouchFileBox(
            'http://%s:%s' %
            ('127.0.0.1',
             current_app.config.geobox_state.config.get('couchdb', 'port')),
            couchbox)
        preview_features = couch_src.get_attachment(filename)
        preview_layername = "%s (%s)" % (filename, _('Temporary'))

    base_layers = g.db.query(ExternalWMTSSource).filter_by(
        background_layer=True).all()
    for base_layer in base_layers:
        base_layer.bbox = base_layer.bbox_from_view_coverage()

    wfs_search_sources = g.db.query(ExternalWFSSource).filter_by(
        active=True).all()
    if not wfs_search_sources:
        wfs_search_sources = False

    parcel_search_sources = g.db.query(ParcelSearchSource).filter_by(
        active=True).all()
    if not parcel_search_sources:
        parcel_search_sources = False
    server_search_form = ServerSearchForm()

    return render_template(
        'editor.html',
        base_layers=base_layers,
        export_form=export_form,
        preview_layername=preview_layername,
        preview_features=preview_features,
        parcel_service=True,
        wfs_search_sources=wfs_search_sources,
        parcel_search_sources=parcel_search_sources,
        server_search_form=server_search_form,
        with_server=True,
        wms_search_url=current_app.config.geobox_state.config.get(
            'web', 'wms_search_url'),
        is_local=request_is_local())
示例#4
0
def editor():
    export_form = ExportVectorForm()
    export_form.srs.choices = list(current_app.config.geobox_state.config.get('web', 'available_srs'))

    user = current_app.config.geobox_state.user

    target_box_name = 'file_box' if user.is_consultant else 'upload_box'
    target_box_label = _('filebox') if user.is_consultant else _('upload_box')
    target_box = current_app.config.geobox_state.config.get('couchdb', target_box_name)
    export_form.destination.choices = [('file', _('Filesystem')), (target_box, target_box_label)]

    # load preview layer
    preview_features = False
    preview_layername = False

    box_name = request.args.get('box_name', False)
    filename = request.args.get('filename', False)
    if box_name and filename:
        couchbox = get_couch_box_db(box_name)
        couch_src = CouchFileBox('http://%s:%s' % ('127.0.0.1', current_app.config.geobox_state.config.get('couchdb', 'port')), couchbox)
        preview_features = couch_src.get_attachment(filename)
        preview_layername = "%s (%s)" % (filename, _('Temporary'))

    base_layers = g.db.query(ExternalWMTSSource).filter_by(background_layer=True).all()
    for base_layer in base_layers:
        base_layer.bbox = base_layer.bbox_from_view_coverage()

    wfs_search_sources = g.db.query(ExternalWFSSource).filter_by(active=True).all()
    if not wfs_search_sources:
        wfs_search_sources = False

    parcel_search_sources = g.db.query(ParcelSearchSource).filter_by(active=True).all()
    if not parcel_search_sources:
        parcel_search_sources = False
    server_search_form = ServerSearchForm()

    return render_template('editor.html',
        base_layers=base_layers,
        export_form=export_form,
        preview_layername=preview_layername,
        preview_features=preview_features,
        parcel_service=True,
        wfs_search_sources=wfs_search_sources,
        parcel_search_sources=parcel_search_sources,
        server_search_form=server_search_form,
        with_server=True,
        wms_search_url=current_app.config.geobox_state.config.get('web', 'wms_search_url'),
        is_local=request_is_local()
    )