Ejemplo n.º 1
0
 def processor(cm):
     if cm.has_metadata():
         click.echo_via_pager(json.dumps(cm.get_metadata(), indent=2))
     else:
         utils.print_cmd_warning(
             "You are missing metadata! Quickly! Run 'update_metadata' before it's too late!"
         )
Ejemplo n.º 2
0
 def exporter(cm):
     output = utils.verify_filename(filename)
     if output['dir']:
         os.makedirs(output['path'], exist_ok=True)
         input_filename = os.path.splitext(os.path.basename(cm.path))[0]
         output['path'] = os.path.join(
             output['path'], '{f}.{ext}'.format(f=input_filename,
                                                ext=format))
     else:
         os.makedirs(os.path.dirname(output['path']), exist_ok=True)
     if format.lower() == 'obj':
         utils.print_cmd_status("Exporting CityJSON to OBJ (%s)" %
                                (output['path']))
         try:
             with click.open_file(output['path'], mode='w') as fo:
                 re = cm.export2obj()
                 fo.write(re.getvalue())
         except IOError as e:
             raise click.ClickException('Invalid output file: "%s".\n%s' %
                                        (output['path'], e))
     elif format.lower() == 'stl':
         utils.print_cmd_status("Exporting CityJSON to STL (%s)" %
                                (output['path']))
         try:
             with click.open_file(output['path'], mode='w') as fo:
                 re = cm.export2stl()
                 fo.write(re.getvalue())
         except IOError as e:
             raise click.ClickException('Invalid output file: "%s".\n%s' %
                                        (output['path'], e))
     elif format.lower() == 'glb':
         fname = os.path.splitext(os.path.basename(output['path']))[0]
         bufferbin = "{}.glb".format(fname)
         binfile = os.path.join(os.path.dirname(output['path']), bufferbin)
         utils.print_cmd_status("Exporting CityJSON to glb %s" % binfile)
         glb = cm.export2gltf()
         # TODO B: how many buffer can there be in the 'buffers'?
         try:
             glb.seek(0)
             with click.open_file(binfile, mode='wb') as bo:
                 bo.write(glb.getvalue())
         except IOError as e:
             raise click.ClickException('Invalid output file: "%s".\n%s' %
                                        (binfile, e))
     elif format.lower() == 'b3dm':
         fname = os.path.splitext(os.path.basename(output['path']))[0]
         b3dmbin = "{}.b3dm".format(fname)
         binfile = os.path.join(os.path.dirname(output['path']), b3dmbin)
         b3dm = cm.export2b3dm()
         utils.print_cmd_status("Exporting CityJSON to b3dm %s" % binfile)
         utils.print_cmd_warning(
             "Although the conversion works, the output is probably incorrect."
         )
         try:
             b3dm.seek(0)
             with click.open_file(binfile, mode='wb') as bo:
                 bo.write(b3dm.getvalue())
         except IOError as e:
             raise click.ClickException('Invalid output file: "%s".\n%s' %
                                        (binfile, e))
Ejemplo n.º 3
0
    def processor(cm):
        utils.print_cmd_status('Update the metadata')
        re, errors = cm.update_metadata(overwrite)

        for e in errors:
            utils.print_cmd_warning(e)