From 6f20bb18a3120bd526a476b3949fe46ade41791d Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 21 Sep 2021 17:01:50 +0200 Subject: [PATCH] geojson2sql: refine name of properties --- utils/geojson2sql.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/utils/geojson2sql.py b/utils/geojson2sql.py index 7b17f9d..42c08b4 100644 --- a/utils/geojson2sql.py +++ b/utils/geojson2sql.py @@ -16,6 +16,9 @@ def safe_json(string): """ Encodes a string a json and escape single quote for postgresql""" return json.dumps(string.replace("'", "''")) +def safe_text(string): + return string.replace("'", "''") + def convert_feature_to_json(feature, program_name): """ Returns a string with a json of properties """ @@ -69,7 +72,7 @@ def import_geosjon_as_sql(filename, sql_filename, schema_name, table_name, colum elif values_list[j].startswith('properties.'): col_name += f'"{c}",' prop = values_list[j].split('.')[1] - col_value += f'\'{f.properties[prop]}\',' + col_value += f'\'{safe_text(f.properties[prop])}\',' else: col_name += f'"{c}",' col_value += f'\'{values_list[j]}\',' @@ -88,7 +91,7 @@ if __name__ == '__main__': schema_name= 'gnc_sites' table_name = 't_sites' column_list = ['id_site', 'uuid_sinp', 'id_program', 'name', 'geom', 'timestamp_create', 'id_type', 'obs_txt'] - values_list = ['__ID1000000__', '__UUID__', '1', 'import arbres remarquables', '__POINT__', '__NOW__', '1', 'import' ] + values_list = ['__ID1000000__', '__UUID__', '1', 'properties.SPFR', '__POINT__', '__NOW__', '1', 'géoportail wallon' ] import_geosjon_as_sql(filename, sql_filename, schema_name, table_name, column_list, values_list) # import arbres.geojson into gnc_sites.t_visit @@ -106,7 +109,7 @@ if __name__ == '__main__': schema_name= 'gnc_sites' table_name = 't_sites' column_list = ['id_site', 'uuid_sinp', 'id_program', 'name', 'geom', 'timestamp_create', 'id_type', 'obs_txt'] - values_list = ['__ID2000000__', '__UUID__', '3', 'import haies remarquables', '__LINESTRING__', '__NOW__', '3', 'import' ] + values_list = ['__ID2000000__', '__UUID__', '3', 'properties.SPFR', '__LINESTRING__', '__NOW__', '3', 'géoportail wallon' ] import_geosjon_as_sql(filename, sql_filename, schema_name, table_name, column_list, values_list) # import haies.geojson into gnc_sites.t_visit