6
6
import click
7
7
import pandas as pd
8
8
9
+ from .const import COMPRESSION_METHODS , CORE_COLUMNS
9
10
from .convert import convert as convert_
10
11
from .convert import list_all_converter_ids , list_all_converters
11
12
from .create_geojson import create_geojson as create_geojson_
12
13
from .create_geoparquet import create_geoparquet as create_geoparquet_
13
14
from .describe import describe as describe_
14
- from .merge import merge as merge_ , DEFAULT_COLUMNS , DEFAULT_CRS
15
+ from .improve import improve as improve_
16
+ from .merge import merge as merge_ , DEFAULT_CRS
15
17
from .jsonschema import jsonschema as jsonschema_
16
18
from .rename_extension import rename_extension as rename_extension_
17
19
from .util import (check_ext_schema_for_cli , log , parse_converter_input_files ,
18
- valid_file_for_cli , valid_file_for_cli_with_ext ,
20
+ parse_map , valid_file_for_cli , valid_file_for_cli_with_ext ,
19
21
valid_files_folders_for_cli , valid_folder_for_cli )
20
22
from .validate import validate as validate_
21
23
from .validate_schema import validate_schema as validate_schema_
@@ -376,7 +378,7 @@ def jsonschema(schema, out, fiboa_version, id_):
376
378
)
377
379
@click .option (
378
380
'--compression' , '-pc' ,
379
- type = click .Choice ([ "brotli" , "gzip" , "lz4" , "snappy" , "zstd" , "none" ] ),
381
+ type = click .Choice (COMPRESSION_METHODS ),
380
382
help = 'Compression method for the Parquet file.' ,
381
383
show_default = True ,
382
384
default = "brotli"
@@ -385,7 +387,7 @@ def jsonschema(schema, out, fiboa_version, id_):
385
387
'--geoparquet1' , '-gp1' ,
386
388
is_flag = True ,
387
389
type = click .BOOL ,
388
- help = 'Enforces generating a GeoParquet 1.0 file bounding box . Defaults to GeoParquet 1.1 with bounding box.' ,
390
+ help = 'Enforces generating a GeoParquet 1.0 file. Defaults to GeoParquet 1.1 with bounding box.' ,
389
391
default = False
390
392
)
391
393
@click .option (
@@ -518,7 +520,7 @@ def rename_extension(folder, title, slug, org = "fiboa", prefix = None):
518
520
multiple = True ,
519
521
help = 'Additional column names to include.' ,
520
522
show_default = True ,
521
- default = DEFAULT_COLUMNS ,
523
+ default = CORE_COLUMNS ,
522
524
)
523
525
@click .option (
524
526
'--exclude' , '-e' ,
@@ -536,7 +538,7 @@ def rename_extension(folder, title, slug, org = "fiboa", prefix = None):
536
538
)
537
539
@click .option (
538
540
'--compression' , '-pc' ,
539
- type = click .Choice ([ "brotli" , "gzip" , "lz4" , "snappy" , "zstd" , "none" ] ),
541
+ type = click .Choice (COMPRESSION_METHODS ),
540
542
help = 'Compression method for the Parquet file.' ,
541
543
show_default = True ,
542
544
default = "brotli"
@@ -545,7 +547,7 @@ def rename_extension(folder, title, slug, org = "fiboa", prefix = None):
545
547
'--geoparquet1' , '-gp1' ,
546
548
is_flag = True ,
547
549
type = click .BOOL ,
548
- help = 'Enforces generating a GeoParquet 1.0 file bounding box . Defaults to GeoParquet 1.1 with bounding box.' ,
550
+ help = 'Enforces generating a GeoParquet 1.0 file. Defaults to GeoParquet 1.1 with bounding box.' ,
549
551
default = False
550
552
)
551
553
def merge (datasets , out , crs , include , exclude , extension , compression , geoparquet1 ):
@@ -564,6 +566,69 @@ def merge(datasets, out, crs, include, exclude, extension, compression, geoparqu
564
566
sys .exit (1 )
565
567
566
568
569
+ ## IMPROVE (add area, perimeter, and fix geometries)
570
+ @click .command ()
571
+ @click .argument ('input' , nargs = 1 , type = click .Path (exists = True ))
572
+ @click .option (
573
+ '--out' , '-o' ,
574
+ type = click .Path (exists = False ),
575
+ help = 'Path to write the GeoParquet file to. If not given, overwrites the input file.' ,
576
+ default = None
577
+ )
578
+ @click .option (
579
+ '--rename-column' , '-r' ,
580
+ type = click .STRING ,
581
+ callback = lambda ctx , param , value : parse_map (value ),
582
+ multiple = True ,
583
+ help = 'Renaming of columns. Provide the old name and the new name separated by an equal sign. Can be used multiple times.'
584
+ )
585
+ @click .option (
586
+ '--add-sizes' , '-sz' ,
587
+ is_flag = True ,
588
+ type = click .BOOL ,
589
+ help = 'Computes missing sizes (area, perimeter)' ,
590
+ default = False
591
+ )
592
+ @click .option (
593
+ '--fix-geometries' , '-g' ,
594
+ is_flag = True ,
595
+ type = click .BOOL ,
596
+ help = 'Tries to fix invalid geometries that are repored by the validator (uses shapely\' s make_valid method internally)' ,
597
+ default = False
598
+ )
599
+ @click .option (
600
+ '--crs' ,
601
+ type = click .STRING ,
602
+ help = 'Coordinate Reference System (CRS) to use for the GeoParquet file.' ,
603
+ show_default = True ,
604
+ default = DEFAULT_CRS ,
605
+ )
606
+ @click .option (
607
+ '--compression' , '-pc' ,
608
+ type = click .Choice (COMPRESSION_METHODS ),
609
+ help = 'Compression method for the Parquet file.' ,
610
+ show_default = True ,
611
+ default = "brotli"
612
+ )
613
+ @click .option (
614
+ '--geoparquet1' , '-gp1' ,
615
+ is_flag = True ,
616
+ type = click .BOOL ,
617
+ help = 'Enforces generating a GeoParquet 1.0 file. Defaults to GeoParquet 1.1 with bounding box.' ,
618
+ default = False
619
+ )
620
+ def improve (input , out , rename_column , add_sizes , fix_geometries , crs , compression , geoparquet1 ):
621
+ """
622
+ "Improves" a fiboa GeoParquet file according to the given parameters.
623
+ """
624
+ log (f"fiboa CLI { __version__ } - Improve datasets\n " , "success" )
625
+ try :
626
+ improve_ (input , out , rename_column , add_sizes , fix_geometries , crs , compression , geoparquet1 )
627
+ except Exception as e :
628
+ log (e , "error" )
629
+ sys .exit (1 )
630
+
631
+
567
632
cli .add_command (describe )
568
633
cli .add_command (validate )
569
634
cli .add_command (validate_schema )
@@ -574,6 +639,7 @@ def merge(datasets, out, crs, include, exclude, extension, compression, geoparqu
574
639
cli .add_command (converters )
575
640
cli .add_command (rename_extension )
576
641
cli .add_command (merge )
642
+ cli .add_command (improve )
577
643
578
644
if __name__ == '__main__' :
579
645
cli ()
0 commit comments