Example #1
0
    def test_import_update_mode(self):

        print("======== Perform database update =========")
        updated_test_file = os.path.join(os.getcwd() + '/osm_test',
                                         'bremen-tests-mod.osm.pbf')
        parser.run_import([updated_test_file], {})

        response = self.client.post('/pois',
                                    data=json.dumps(request_poi_bbox),
                                    content_type='application/json')
        self.assertEqual(response.status_code, 200)
        self.assertIn(b'features', response.data)
        data = json.loads(response.get_data(as_text=True))

        # for debugging
        # print(json.dumps(data, indent=4, sort_keys=False))

        # 1 POI has been deleted in the update and 1 added, so number hasn't changed
        self.assertEqual(len(data['features']), 38)

        # 1 POI has been added
        self.assertEqual(data['features'][5]['properties']['osm_id'],
                         2134315509)
        self.assertEqual(data['features'][5]['properties']['osm_tags']['name'],
                         "Ein Impfzentrum")

        # 1 POI has a tag value changed
        self.assertEqual(
            data['features'][20]['properties']['osm_tags']['name'],
            "Kiosk am Markt wurde umbenannt")
Example #2
0
def import_data():
    """Imports osm pbf data to postgis."""

    osm_files = []
    osm_dir = os.getcwd() + '/osm'

    for dirName, subdirList, fileList in os.walk(osm_dir):
        print('Found directory: %s' % dirName)
        for fname in fileList:
            if fname.endswith('.osm.pbf') or fname.endswith('.osm'):
                osm_files.append(os.path.join(dirName, fname))

    logger.info("Starting to import OSM data...{}".format(osm_files))
    parser.run_import(osm_files)
Example #3
0
def import_data():
    """Imports osm pbf data to postgis."""

    osm_files = []
    osm_dir = os.getcwd() + "/osm"

    for dir_name, subdir_list, file_list in os.walk(osm_dir):
        if dir_name.endswith("__pycache__"):
            continue
        logger.info(f"Found directory: {dir_name}")
        for filename in file_list:
            if filename.endswith(".osm.pbf") or filename.endswith(".osm"):
                osm_files.append(os.path.join(dir_name, filename))
    osm_files.sort()

    import_log = {}
    if os.path.isfile(logfile):
        with open(logfile) as f:
            try:
                import_log = json.load(f)
            except JSONDecodeError:
                pass
            finally:
                f.close()

    # we have found previous data in the database, check if file list has changed which would require a full rebuild
    if len(import_log) and set(import_log.keys()) != set(osm_files):
        logger.error(f"File set has changed since last import, full rebuild required. Exiting.")
        return

    logger.info(f"Starting to import OSM data ({len(osm_files)} files in batch)")
    logger.debug(f"Files in import batch: {osm_files}")
    parser.run_import(osm_files, import_log)

    with open(logfile, "w") as f:
        json.dump(import_log, f, indent=4, sort_keys=True)
        f.close()