Пример #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 process(self):
        log.debug('Start vector import process. Task %d' % self.task_id)
        try:
            with self.task() as task:
                mapping = mappings[task.mapping_name].copy()
                mapping.json_defaults = mapping.json_defaults.copy()
                mapping.json_defaults['import_timestamp'] = datetime.now().isoformat();
                mapping.json_defaults['import_file'] = task.file_name;

                input_file = self.app_state.user_data_path('import', task.file_name)
                couch = CouchDB('http://%s:%s' % ('127.0.0.1', self.app_state.config.get('couchdb', 'port')), task.db_name)
                couch.store_records(
                    load_json_from_shape(input_file, mapping)
                )
            self.task_done()
        except ConvertError, e:
            self.task_failed(e)