Exemplo n.º 1
0
    def create_gis_export(self):
        self._start_time = timezone.now()

        _bootstrapper = BootStrapper(self._polyfile_string,
                                     detail_level=self._detail_level)
        _bootstrapper.bootstrap()
        geom_in_qgis_display_srs = _bootstrapper.geom.transform(
            QGIS_DISPLAY_SRID, clone=True)

        with tempfile.TemporaryDirectory() as tmp_dir:
            data_dir = os.path.join(tmp_dir, 'data')
            data_location = self._dump_gis_data(data_dir, tmp_dir)
            unzipped_result_size = recursive_getsize(data_dir)

            symbology_dir = os.path.join(tmp_dir, 'symbology')
            self._dump_qgis_symbology(data_location,
                                      geom_in_qgis_display_srs,
                                      target_dir=symbology_dir)

            zip_folders_relative([tmp_dir],
                                 zip_out_file_path=self._out_zip_file_path)

        job = get_current_job()
        if job:
            total_duration = timezone.now() - self._start_time
            job.meta['duration'] = total_duration
            job.meta['unzipped_result_size'] = unzipped_result_size
            job.save()
        return self._out_zip_file_path
Exemplo n.º 2
0
    def create_gis_export(self):
        self._start_time = timezone.now()

        bootstrap.boostrap(self._polyfile_string,
                           detail_level=self._detail_level)

        with tempfile.TemporaryDirectory() as tmp_dir:
            data_dir = os.path.join(tmp_dir, 'data')
            static_dir = os.path.join(tmp_dir, 'static')
            os.makedirs(data_dir)
            shutil.copytree(self._static_directory, static_dir)
            shutil.copy(odb_license, static_dir)
            extract_to(to_format=self._conversion_format,
                       output_dir=data_dir,
                       base_filename=self._base_file_name,
                       out_srs=self._out_srs)
            unzipped_result_size = recursive_getsize(data_dir)
            zip_folders_relative([tmp_dir],
                                 zip_out_file_path=self._out_zip_file_path)

        job = get_current_job()
        if job:
            total_duration = timezone.now() - self._start_time
            job.meta['duration'] = total_duration
            job.meta['unzipped_result_size'] = unzipped_result_size
            job.save()
        return self._out_zip_file_path
Exemplo n.º 3
0
    def _produce_garmin(self, config_file_path, out_dir):
        out_dir = os.path.join(
            out_dir, 'garmin')  # hack to get a subdirectory in the zipfile.
        os.makedirs(out_dir, exist_ok=True)

        shutil.copy(copying_notice, out_dir)
        shutil.copy(odb_license, out_dir)
        shutil.copy(creative_commons_license, out_dir)

        _mkgmap_path = os.path.abspath(
            os.path.join(_path_to_commandline_utils, 'mkgmap', 'mkgmap.jar'))
        mkg_map_command = ['java', '-jar', _mkgmap_path]
        output_dir = ['--output-dir={0}'.format(out_dir)]
        config = [
            '--bounds={0}'.format(_path_to_bounds_zip),
            '--precomp-sea={0}'.format(_path_to_sea_zip),
            '--read-config={0}'.format(config_file_path),
        ]

        subprocess.check_call(mkg_map_command + output_dir + config)
        self._unzipped_result_size = recursive_getsize(out_dir)
Exemplo n.º 4
0
def produce_pbf(*, output_zip_file_path, filename_prefix,
                osmosis_polygon_file_string, **__):
    _start_time = timezone.now()

    with tempfile.TemporaryDirectory() as tmp_dir:
        out_dir = os.path.join(tmp_dir, 'pbf')
        os.makedirs(out_dir, exist_ok=True)
        pbf_out_path = os.path.join(out_dir, filename_prefix + '.pbf')

        shutil.copy(odb_license, out_dir)

        cut_pbf_along_polyfile(osmosis_polygon_file_string, pbf_out_path)

        unzipped_result_size = recursive_getsize(out_dir)

        zip_folders_relative([tmp_dir], output_zip_file_path)

    job = get_current_job()
    if job:
        job.meta['duration'] = timezone.now() - _start_time
        job.meta['unzipped_result_size'] = unzipped_result_size
        job.save()
Exemplo n.º 5
0
def test_recursive_getsize_sums_up_sizes_correctly_with_subdirectories(
        directory_with_subdirectories):
    directory, expected_size = directory_with_subdirectories
    assert recursive_getsize(directory) == expected_size