geojson2sql: refine name of properties
This commit is contained in:
parent
0e4dca5f9e
commit
6f20bb18a3
@ -16,6 +16,9 @@ def safe_json(string):
|
|||||||
""" Encodes a string a json and escape single quote for postgresql"""
|
""" Encodes a string a json and escape single quote for postgresql"""
|
||||||
return json.dumps(string.replace("'", "''"))
|
return json.dumps(string.replace("'", "''"))
|
||||||
|
|
||||||
|
def safe_text(string):
|
||||||
|
return string.replace("'", "''")
|
||||||
|
|
||||||
def convert_feature_to_json(feature, program_name):
|
def convert_feature_to_json(feature, program_name):
|
||||||
""" Returns a string with a json of properties """
|
""" 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.'):
|
elif values_list[j].startswith('properties.'):
|
||||||
col_name += f'"{c}",'
|
col_name += f'"{c}",'
|
||||||
prop = values_list[j].split('.')[1]
|
prop = values_list[j].split('.')[1]
|
||||||
col_value += f'\'{f.properties[prop]}\','
|
col_value += f'\'{safe_text(f.properties[prop])}\','
|
||||||
else:
|
else:
|
||||||
col_name += f'"{c}",'
|
col_name += f'"{c}",'
|
||||||
col_value += f'\'{values_list[j]}\','
|
col_value += f'\'{values_list[j]}\','
|
||||||
@ -88,7 +91,7 @@ if __name__ == '__main__':
|
|||||||
schema_name= 'gnc_sites'
|
schema_name= 'gnc_sites'
|
||||||
table_name = 't_sites'
|
table_name = 't_sites'
|
||||||
column_list = ['id_site', 'uuid_sinp', 'id_program', 'name', 'geom', 'timestamp_create', 'id_type', 'obs_txt']
|
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_geosjon_as_sql(filename, sql_filename, schema_name, table_name, column_list, values_list)
|
||||||
|
|
||||||
# import arbres.geojson into gnc_sites.t_visit
|
# import arbres.geojson into gnc_sites.t_visit
|
||||||
@ -106,7 +109,7 @@ if __name__ == '__main__':
|
|||||||
schema_name= 'gnc_sites'
|
schema_name= 'gnc_sites'
|
||||||
table_name = 't_sites'
|
table_name = 't_sites'
|
||||||
column_list = ['id_site', 'uuid_sinp', 'id_program', 'name', 'geom', 'timestamp_create', 'id_type', 'obs_txt']
|
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_geosjon_as_sql(filename, sql_filename, schema_name, table_name, column_list, values_list)
|
||||||
|
|
||||||
# import haies.geojson into gnc_sites.t_visit
|
# import haies.geojson into gnc_sites.t_visit
|
||||||
|
Loading…
Reference in New Issue
Block a user