Exemplo n.º 1
0
def main(args):
    debut_total = time.time()
    usage = 'USAGE : python place_2_db.py <code INSEE> {use_cache=True}'
    if len(args) < 2:
        print(usage)
        os._exit(0)

    global pgc, fantoir, source, code_insee, code_cadastre, code_dept, dicts, use_cache, places

    code_insee = args[1]
    dicts = {}
    load_dicts()
    code_cadastre = get_code_cadastre_from_insee(code_insee)
    code_dept = get_cadastre_code_dept_from_insee(code_insee)
    format_cadastre = get_cadastre_format(code_insee)

    use_cache = True
    if len(args) > 2:
        use_cache = args[2]
    places = Places()
    load_fantoir(code_insee)

    batch_id_osm = batch_start_log('OSM', 'cumulPlaces', code_cadastre)

    if format_cadastre == 'VECT':
        batch_id_cadastre = batch_start_log('CADASTRE', 'cumulPlaces',
                                            code_cadastre)
        load_cadastre()
    load_osm()

    nb_rec = load_to_db(places)
    batch_end_log(nb_rec, batch_id_osm)
    if format_cadastre == 'VECT':
        batch_end_log(nb_rec, batch_id_cadastre)
Exemplo n.º 2
0
def main(args):
    debut_total = time.time()
    usage = 'USAGE : python place_2_db.py <code INSEE>'
    if len(args) < 2:
        print(usage)
        os._exit(0)

    global pgc, dicts, source, code_insee
    pgc = get_pgc()
    source = 'CADASTRE'
    code_insee = args[1]
    code_cadastre = get_code_cadastre_from_insee(code_insee)
    code_dept = get_cadastre_code_dept_from_insee(code_insee)

    batch_id = batch_start_log(source, 'cumulPlaces', code_cadastre)

    global nodes, ways
    nodes = Nodes()
    ways = Ways()

    data = get_data_from_pg('cadastre_2_places', code_insee)
    for d in data:
        d[3] = format_toponyme(d[3])
    nb_rec = load_to_db(data, code_insee, source, code_cadastre, code_dept)
    batch_end_log(nb_rec, batch_id)
def main(args):
	debut_total = time.time()
	usage = 'USAGE : python hameaux_depuis_noms_de_voies.py <code INSEE>'
	if len(args) != 2:
		print(usage)
		os._exit(0)

	global pgc,dicts,adresses,source,code_insee
	pgc = get_pgc()
	source = 'CADASTRE'
	adresses = Adresses()
	code_insee = args[1]
	code_cadastre = get_code_cadastre_from_insee(code_insee)
	code_dept = get_cadastre_code_dept_from_insee(code_insee)
	
	batch_id = batch_start_log(source,'detecteHameaux',code_cadastre)

	fnadresses = os.path.join('/data/work/cadastre.openstreetmap.fr/bano_cache',code_dept,code_cadastre,code_cadastre+'-adresses.osm')
	# fnadresses = os.path.join('C:\\Users\\vincent\\Documents\\GitHub',code_cadastre+'-adresses.osm')
	load_hsnr_from_cad_file(fnadresses)
	freq = name_frequency()
	sel = select_street_names_by_name(freq)
	adds = collect_adresses_points(sel)
	nb_rec = load_hameaux_2_db(adds)
		
	batch_end_log(nb_rec,batch_id)
def main(args):
    debut_total = time.time()
    usage = 'USAGE : python suffixe_depuis_noms_de_voies.py <code INSEE>'
    if len(args) != 2:
        print(usage)
        os._exit(0)

    global pgc, dicts, adresses, source, code_insee
    pgc = get_pgc()
    source = 'CADASTRE'
    adresses = Adresses()
    code_insee = args[1]
    code_cadastre = get_code_cadastre_from_insee(code_insee)
    code_dept = get_cadastre_code_dept_from_insee(code_insee)

    batch_id = batch_start_log(source, 'detectesuffixe', code_cadastre)

    fnadresses = os.path.join(
        '/data/work/cadastre.openstreetmap.fr/bano_cache', code_dept,
        code_cadastre, code_cadastre + '-adresses.osm')
    load_hsnr_from_cad_file(fnadresses)
    freq = name_frequency()
    sel = select_street_names_by_name(freq)
    adds = collect_adresses_points(sel)
    nb_rec = load_suffixe_2_db(adds)

    batch_end_log(nb_rec, batch_id)
Exemplo n.º 5
0
def main(args):
	debut_total = time.time()
	usage = 'USAGE : python place_2_db.py <code INSEE>'
	if len(args) < 2:
		print(usage)
		os._exit(0)

	global pgc,dicts,source,code_insee
	pgc = get_pgc()
	source = 'CADASTRE'
	code_insee = args[1]
	code_cadastre = get_code_cadastre_from_insee(code_insee)
	code_dept = get_cadastre_code_dept_from_insee(code_insee)
	
	batch_id = batch_start_log(source,'cumulPlaces',code_cadastre)

	global nodes,ways
	nodes = Nodes()
	ways = Ways()

	data = get_data_from_pg('cadastre_2_places',code_insee)
	for d in data:
		d[3] = format_toponyme(d[3])
	nb_rec = load_to_db(data,code_insee,source,code_cadastre,code_dept)
	batch_end_log(nb_rec,batch_id)
Exemplo n.º 6
0
def main(args):
	debut_total = time.time()
	usage = 'USAGE : python place_2_db.py <code INSEE> {use_cache=True}'
	if len(args) < 2:
		print(usage)
		os._exit(0)

	global pgc,fantoir,source,code_insee,code_cadastre,code_dept,dicts,use_cache,places
	
	code_insee = args[1]
	dicts = {}
	load_dicts()
	code_cadastre = get_code_cadastre_from_insee(code_insee)
	code_dept = get_cadastre_code_dept_from_insee(code_insee)
	format_cadastre = get_cadastre_format(code_insee)

	use_cache = True
	if len(args) > 2:
		use_cache = args[2]
	places = Places()
	load_fantoir(code_insee)
	
	batch_id_osm = batch_start_log('OSM','cumulPlaces',code_cadastre)

	if format_cadastre == 'VECT':
		batch_id_cadastre = batch_start_log('CADASTRE','cumulPlaces',code_cadastre)
		load_cadastre()
	load_osm()
		
	nb_rec = load_to_db(places)
	batch_end_log(nb_rec,batch_id_osm)
	if format_cadastre == 'VECT':
		batch_end_log(nb_rec,batch_id_cadastre)
Exemplo n.º 7
0
def main(args):
    debut_total = time.time()
    usage = "USAGE : python suffixe_depuis_noms_de_voies.py <code INSEE>"
    if len(args) != 2:
        print(usage)
        os._exit(0)

    global pgc, dicts, adresses, source, code_insee
    pgc = get_pgc()
    source = "CADASTRE"
    adresses = Adresses()
    code_insee = args[1]
    code_cadastre = get_code_cadastre_from_insee(code_insee)
    code_dept = get_cadastre_code_dept_from_insee(code_insee)

    batch_id = batch_start_log(source, "detectesuffixe", code_cadastre)

    fnadresses = os.path.join(
        "/data/work/cadastre.openstreetmap.fr/bano_cache", code_dept, code_cadastre, code_cadastre + "-adresses.osm"
    )
    load_hsnr_from_cad_file(fnadresses)
    freq = name_frequency()
    sel = select_street_names_by_name(freq)
    adds = collect_adresses_points(sel)
    nb_rec = load_suffixe_2_db(adds)

    batch_end_log(nb_rec, batch_id)
Exemplo n.º 8
0
def main(args):
    global source, batch_id
    global pgc, pgcl
    global code_insee, code_cadastre, code_dept
    global dicts
    global nodes, ways, adresses
    global commune_avec_suffixe
    global geom_suffixe

    debut_total = time.time()
    usage = "USAGE : python addr_cad_2_db.py <code INSEE> <OSM|CADASTRE>"
    if len(args) != 3:
        print(usage)
        os._exit(0)

    source = args[2].upper()
    if source not in ["OSM", "CADASTRE"]:
        print(usage)
        os._exit(0)

    adresses = Adresses()

    pgc = get_pgc()
    pgcl = get_pgc_layers()

    code_insee = args[1]
    code_cadastre = get_code_cadastre_from_insee(code_insee)
    code_dept = get_cadastre_code_dept_from_insee(code_insee)

    batch_id = batch_start_log(source, "loadCumul", code_cadastre)

    dicts = Dicts()
    dicts.load_all(code_insee)

    commune_avec_suffixe = has_addreses_with_suffix(code_insee)
    geom_suffixe = None
    if commune_avec_suffixe:
        geom_suffixe = get_geom_suffixes(code_insee, code_cadastre)

    if source == "CADASTRE":
        fnadresses = os.path.join(
            "/data/work/cadastre.openstreetmap.fr/bano_cache", code_dept, code_cadastre, code_cadastre + "-adresses.osm"
        )
        load_hsnr_from_cad_file(fnadresses, source)
    if source == "OSM":
        load_hsnr_from_pg_osm(code_insee, code_cadastre)
    load_highways_from_pg_osm(code_insee, code_cadastre)
    load_highways_relations_from_pg_osm(code_insee, code_cadastre)
    add_fantoir_to_hsnr()
    load_point_par_rue_from_pg_osm(code_insee, code_cadastre)

    nb_rec = load_to_db(adresses, code_insee, source, code_cadastre, code_dept)

    batch_end_log(nb_rec, batch_id)
    fin_total = time.time()
    print("Execution en " + str(int(fin_total - debut_total)) + " s.")
Exemplo n.º 9
0
def main(args):
    global source, batch_id
    global pgc, pgcl
    global code_insee, code_cadastre, code_dept
    global dicts
    global nodes, ways, adresses
    global commune_avec_suffixe
    global geom_suffixe

    debut_total = time.time()
    usage = 'USAGE : python addr_cad_2_db.py <code INSEE> <OSM|CADASTRE>'
    if len(args) != 3:
        print(usage)
        os._exit(0)

    source = args[2].upper()
    if source not in ['OSM', 'CADASTRE']:
        print(usage)
        os._exit(0)

    adresses = Adresses()

    pgc = get_pgc()
    pgcl = get_pgc_layers()

    code_insee = args[1]
    code_cadastre = get_code_cadastre_from_insee(code_insee)
    code_dept = get_cadastre_code_dept_from_insee(code_insee)

    batch_id = batch_start_log(source, 'loadCumul', code_cadastre)

    dicts = Dicts()
    dicts.load_all(code_insee)

    commune_avec_suffixe = has_addreses_with_suffix(code_insee)
    geom_suffixe = None
    if commune_avec_suffixe:
        geom_suffixe = get_geom_suffixes(code_insee, code_cadastre)

    if source == 'CADASTRE':
        fnadresses = os.path.join(
            '/data/work/cadastre.openstreetmap.fr/bano_cache', code_dept,
            code_cadastre, code_cadastre + '-adresses.osm')
        load_hsnr_from_cad_file(fnadresses, source)
    if source == 'OSM':
        load_hsnr_from_pg_osm(code_insee, code_cadastre)
    load_highways_from_pg_osm(code_insee, code_cadastre)
    load_highways_relations_from_pg_osm(code_insee, code_cadastre)
    add_fantoir_to_hsnr()
    load_point_par_rue_from_pg_osm(code_insee, code_cadastre)

    nb_rec = load_to_db(adresses, code_insee, source, code_cadastre, code_dept)

    batch_end_log(nb_rec, batch_id)
    fin_total = time.time()
    print('Execution en ' + str(int(fin_total - debut_total)) + ' s.')
Exemplo n.º 10
0
def get_data_by_dept_from_pg(data_type, dept, local=False):
    if dept[0:1] == '0':
        dept = dept[1:]
    etape_dept = 'cache_dept_' + data_type
    # Cache gardé 1h
    if o.age_etape_dept(etape_dept, dept) > 1:  #3600:
        print(u'Mise à jour du cache "{:s}"'.format(data_type.upper()))
        batch_id = o.batch_start_log('', etape_dept, dept)
        fq = open('sql/{:s}.sql'.format(data_type), 'rb')
        str_sql_dept_like = (dept + '___')[0:5]
        str_query = fq.read().replace(
            '=\'__com__', ' LIKE  \'{:s}'.format(str_sql_dept_like))
        fq.close()
        if local:
            pgc = a.get_pgc()
        else:
            pgc = a.get_pgc_layers()
        cur = pgc.cursor()
        cur.execute(str_query)

        pgccad = a.get_pgc()
        str_query_com = "SELECT insee_com,cadastre_com FROM code_cadastre WHERE dept = '{:s}'".format(
            dept)
        cur_com = pgccad.cursor()
        cur_com.execute(str_query_com)
        k_insee = {}
        for c in cur_com:
            k_insee[c[0]] = {'cad': c[1], 'data': []}
        for lt in cur:
            l = list(lt)
            insee = l[-1]
            # Exceptions Paris/Lyon/Marseille
            if insee == '75056' or insee == '13055' or insee == '69123':
                continue
            l = l[0:-1]
            if insee not in k_insee:
                e.write_log_to_file(
                    f_log,
                    'Commune manquante au Cadastre : INSEE # {:s}'.format(
                        insee))
                continue
            k_insee[insee]['data'].append(str(l))
        for k in k_insee.iterkeys():
            cache_file = a.get_cache_filename(data_type, k, k_insee[k]['cad'])
            f = open(cache_file, 'w')
            f.write('\n'.join(k_insee[k]['data']))
            f.close()
        o.batch_end_log(len(k_insee.keys()), batch_id)
Exemplo n.º 11
0
def main(args):
	global source,batch_id
	global pgc,pgcl
	global code_insee,code_cadastre,code_dept
	global dicts
	global nodes,ways,adresses
	
	debut_total = time.time()
	usage = 'USAGE : python addr_cad_2_db.py <code INSEE> <OSM|CADASTRE>'
	if len(args) != 3:
		print(usage)
		os._exit(0)
		
	source = args[2].upper()
	if source not in ['OSM','CADASTRE']:
		print(usage)
		os._exit(0)

	adresses = Adresses()
	
	pgc = get_pgc()
	pgcl = get_pgc_layers()
	
	code_insee = args[1]
	code_cadastre = get_code_cadastre_from_insee(code_insee)
	code_dept = get_cadastre_code_dept_from_insee(code_insee)
	
	batch_id = batch_start_log(source,'loadCumul',code_cadastre)
	
	dicts = Dicts()
	dicts.load_all(code_insee)
	if source == 'CADASTRE':
		fnadresses = os.path.join('/data/work/cadastre.openstreetmap.fr/bano_cache',code_dept,code_cadastre,code_cadastre+'-adresses.osm')
		load_hsnr_from_cad_file(fnadresses,source)
	if source == 'OSM':
		load_hsnr_from_pg_osm(code_insee,code_cadastre)
	load_highways_from_pg_osm(code_insee,code_cadastre)
	load_highways_relations_from_pg_osm(code_insee,code_cadastre)
	add_fantoir_to_hsnr()
	nb_rec = load_to_db(adresses,code_insee,source,code_cadastre,code_dept)
	
	batch_end_log(nb_rec,batch_id)
	fin_total = time.time()
	print('Execution en '+str(int(fin_total - debut_total))+' s.')
Exemplo n.º 12
0
def get_data_by_dept_from_pg(data_type,dept,local=False):
	if dept[0:1] == '0':
		dept = dept[1:]
	etape_dept = 'cache_dept_'+data_type
# Cache gardé 1h
	if o.age_etape_dept(etape_dept,dept) > 1 : #3600:
		print(u'Mise à jour du cache "{:s}"'.format(data_type.upper()))
		batch_id = o.batch_start_log('',etape_dept,dept)
		fq = open('sql/{:s}.sql'.format(data_type),'rb')
		str_sql_dept_like = (dept+'___')[0:5]
		str_query = fq.read().replace('=\'__com__',' LIKE  \'{:s}'.format(str_sql_dept_like))
		fq.close()
		if local:
			pgc = a.get_pgc()
		else:
			pgc = a.get_pgc_layers()
		cur = pgc.cursor()
		cur.execute(str_query)
		
		pgccad = a.get_pgc()
		str_query_com = "SELECT insee_com,cadastre_com FROM code_cadastre WHERE dept = '{:s}'".format(dept)
		cur_com = pgccad.cursor()
		cur_com.execute(str_query_com)
		k_insee = {}
		for c in cur_com:
			k_insee[c[0]] = {'cad':c[1],'data':[]}
		for lt in cur:
			l = list(lt)
			insee = l[-1]
			# Exceptions Paris/Lyon/Marseille
			if insee == '75056' or insee == '13055' or insee == '69123':
				continue
			l = l[0:-1]
			if insee not in k_insee:
				e.write_log_to_file(f_log,'Commune manquante au Cadastre : INSEE # {:s}'.format(insee))
				continue
			k_insee[insee]['data'].append(str(l))
		for k in k_insee.iterkeys():
			cache_file = a.get_cache_filename(data_type,k,k_insee[k]['cad'])
			f = open(cache_file,'w')
			f.write('\n'.join(k_insee[k]['data']))
			f.close()
		o.batch_end_log(len(k_insee.keys()),batch_id)
Exemplo n.º 13
0
def main(args):
    debut_total = time.time()
    if len(args) < 2:
        print('USAGE : python addr_cad_2_db.py <code INSEE>')
        os._exit(0)

    global source, batch_id
    global pgc, pgcl
    global code_insee, code_cadastre, code_dept
    global dicts
    global nodes, ways, adresses

    adresses = Adresses()
    source = 'CADASTRE'

    pgc = get_pgc()
    pgcl = get_pgc_layers()

    code_insee = args[1]
    code_cadastre = get_code_cadastre_from_insee(code_insee)
    code_dept = '0' + code_insee[0:2]
    if code_insee[0:2] == '97':
        code_dept = code_insee[0:3]

    batch_id = batch_start_log(source, 'loadCumul', code_cadastre)

    dicts = Dicts()
    dicts.load_all(code_insee)
    fnadresses = os.path.join(
        '/data/work/cadastre.openstreetmap.fr/bano_cache', code_dept,
        code_cadastre, code_cadastre + '-adresses.osm')
    load_hsnr_from_cad_file(fnadresses, source)
    load_highways_from_pg_osm(code_insee)
    load_highways_relations_from_pg_osm(code_insee)
    add_fantoir_to_hsnr()
    nb_rec = load_to_db(adresses, code_insee, source, code_cadastre, code_dept)

    batch_end_log(nb_rec, batch_id)
    fin_total = time.time()
    print('Execution en ' + str(int(fin_total - debut_total)) + ' s.')
Exemplo n.º 14
0
def main(args):
    global batch_id
    global pgc
    global code_insee, code_dept, cadastre_com
    global nodes, ways

    nodes = Nodes()
    ways = Ways()
    pgc = get_pgc()

    debut_total = time.time()
    usage = 'USAGE : python parcelles_buildings_2_db.py <code INSEE>'
    if len(args) != 2:
        print(usage)
        os._exit(0)
    code_insee = args[1]
    cadastre_com = get_code_cadastre_from_insee(code_insee)
    # cadastre_com = 'S0335'
    fn_parcelles = os.path.join(get_cache_directory(code_insee, cadastre_com),
                                cadastre_com + '-parcelles.osm')
    # fn_parcelles = 'C:\\Users\\vincent\\Documents\\GitHub\\ZA063-parcelles.osm'
    batch_id = batch_start_log('CADASTRE', 'importParcelles', cadastre_com)
    nb_parcelles = load_parcelles(fn_parcelles)
    batch_end_log(nb_parcelles, batch_id)

    a_fn_houses_parts = glob.glob('{:s}/{:s}-[0-9]-[0-9]-houses.osm'.format(
        get_cache_directory(code_insee, cadastre_com), cadastre_com))
    # a_fn_houses_parts = glob.glob('{:s}\\{:s}-[0-9]-[0-9]-houses.osm'.format('C:\\Users\\vincent\\Documents\\GitHub','ZA063'))
    create_tmp_building_table()
    nb_buildings = 0
    batch_id = batch_start_log('CADASTRE', 'importBuildings', cadastre_com)
    for h in a_fn_houses_parts:
        print(h)
        nodes = Nodes()
        ways = Ways()
        nb_buildings += load_tmp_buildings(h)
    load_buildings()
    batch_end_log(nb_buildings, batch_id)
    pgc.close()
Exemplo n.º 15
0
def main(args):
    global batch_id
    global pgc
    global code_insee, code_dept, cadastre_com
    global nodes, ways

    nodes = Nodes()
    ways = Ways()
    pgc = get_pgc()

    debut_total = time.time()
    usage = "USAGE : python parcelles_buildings_2_db.py <code INSEE>"
    if len(args) != 2:
        print(usage)
        os._exit(0)
    code_insee = args[1]
    cadastre_com = get_code_cadastre_from_insee(code_insee)
    # cadastre_com = 'S0335'
    fn_parcelles = os.path.join(get_cache_directory(code_insee, cadastre_com), cadastre_com + "-parcelles.osm")
    # fn_parcelles = 'C:\\Users\\vincent\\Documents\\GitHub\\ZA063-parcelles.osm'
    batch_id = batch_start_log("CADASTRE", "importParcelles", cadastre_com)
    nb_parcelles = load_parcelles(fn_parcelles)
    batch_end_log(nb_parcelles, batch_id)

    a_fn_houses_parts = glob.glob(
        "{:s}/{:s}-[0-9]-[0-9]-houses.osm".format(get_cache_directory(code_insee, cadastre_com), cadastre_com)
    )
    # a_fn_houses_parts = glob.glob('{:s}\\{:s}-[0-9]-[0-9]-houses.osm'.format('C:\\Users\\vincent\\Documents\\GitHub','ZA063'))
    create_tmp_building_table()
    nb_buildings = 0
    batch_id = batch_start_log("CADASTRE", "importBuildings", cadastre_com)
    for h in a_fn_houses_parts:
        print(h)
        nodes = Nodes()
        ways = Ways()
        nb_buildings += load_tmp_buildings(h)
    load_buildings()
    batch_end_log(nb_buildings, batch_id)
    pgc.close()
Exemplo n.º 16
0
def main(args):
	debut_total = time.time()
	if len(args) < 2:
		print('USAGE : python addr_cad_2_db.py <code INSEE>')
		os._exit(0)

	global source,batch_id
	global pgc,pgcl
	global code_insee,code_cadastre,code_dept
	global dicts
	global nodes,ways,adresses
	
	adresses = Adresses()
	source = 'CADASTRE'
	
	pgc = get_pgc()
	pgcl = get_pgc_layers()
	
	code_insee = args[1]
	code_cadastre = get_code_cadastre_from_insee(code_insee)
	code_dept = '0'+code_insee[0:2]
	if code_insee[0:2] == '97':
		code_dept = code_insee[0:3]
	
	batch_id = batch_start_log(source,'loadCumul',code_cadastre)
	
	dicts = Dicts()
	dicts.load_all(code_insee)
	fnadresses = os.path.join('/data/work/cadastre.openstreetmap.fr/bano_cache',code_dept,code_cadastre,code_cadastre+'-adresses.osm')
	load_hsnr_from_cad_file(fnadresses,source)
	load_highways_from_pg_osm(code_insee)
	load_highways_relations_from_pg_osm(code_insee)
	add_fantoir_to_hsnr()
	nb_rec = load_to_db(adresses,code_insee,source,code_cadastre,code_dept)
	
	batch_end_log(nb_rec,batch_id)
	fin_total = time.time()
	print('Execution en '+str(int(fin_total - debut_total))+' s.')
Exemplo n.º 17
0
def main(args):
	debut_total = time.time()
	usage = 'USAGE : python place_2_db.py <code INSEE> <CADASTRE|OSM>'
	if len(args) < 3:
		print(usage)
		os._exit(0)

	global pgc,pgcl,fantoir,source,code_insee,code_cadastre,code_dept,dicts
	source = args[2].upper()
	if source not in ['OSM','CADASTRE']:
		print(usage)
		os._exit(0)

	pgc = get_pgc()
	pgcl = get_pgc_layers()
	code_insee = args[1]
	code_cadastre = get_code_cadastre_from_insee(code_insee)
	code_dept = get_cadastre_code_dept_from_insee(code_insee)
	fantoir = {}
	dicts = Dicts()
	dicts.load_all()
	load_fantoir(code_insee)
	# print(dicts)
	batch_id = batch_start_log(source,'cumulPlaces',code_cadastre)

	global places
	places = []
	if source == 'CADASTRE':
		data = get_data_from_pg('cadastre_2_places',code_insee)
		# for d in data:
			# places.append(Place(d[0],d[1],d[2],d[3],d[5],source,d[4]))
	else:
		data = get_data_from_pgl('place_insee',code_insee,code_cadastre)
	for d in data:
		places.append(Place(d[0],d[1],d[2],d[3].decode('utf8'),d[5],source,d[4]))
		
	nb_rec = load_to_db(places,code_insee,source,code_cadastre,code_dept)
	batch_end_log(nb_rec,batch_id)
import subprocess
import glob
import time
from outils_de_gestion import batch_start_log
from outils_de_gestion import batch_end_log
from pg_connexion import get_pgc

if len(sys.argv) > 1:
	print('USAGE : ./convert_qadastre_2_osm_differentiel.py')
	os._exit(0)

pgc = get_pgc()
str_query = "SELECT DISTINCT c.insee_com,c.cadastre_com,c.nom_com,c.cadastre_dept FROM code_cadastre c JOIN (SELECT cadastre_com FROM code_cadastre  WHERE format_cadastre = 'VECT' EXCEPT SELECT b1.cadastre_com FROM batch b1 JOIN batch b2 USING (cadastre_com) WHERE b1.etape = 'importQadastre' AND b2.etape = 'recupCadastre' AND b1.timestamp_debut > b2.timestamp_debut AND b1.date_fin IS NOT NULL AND b2.date_fin IS NOT NULL) j USING (cadastre_com) ORDER BY 4,3;"

cur = pgc.cursor()
cur.execute(str_query)
for c in cur:
	print(c[2])
	parts = glob.glob('/data/work/cadastre.openstreetmap.fr/bano_cache/{:s}/{:s}/{:s}-[0-9]-[0-9].pdf'.format(c[3],c[1],c[1]))
	nb_parts = len(parts)
	batch_id = batch_start_log('CADASTRE','importQadastre',c[1])
	for p in parts:
		p_out = p[0:-4]+'-houses.osm'
		suffixe = '-'.join(p[0:-4].rsplit('-',2)[1:])
		print(suffixe)
		subprocess.call('./qadastre_convert.sh {:s} {:s} "{:s}"'.format(c[3],c[1],suffixe),shell=True)
		if not os.path.exists(p_out):
			nb_parts -=1
	batch_end_log(nb_parts,batch_id)
	time.sleep(1)
Exemplo n.º 19
0
	os._exit(0)

pgc = get_pgc()
if len(sys.argv) == 2:
	str_query = 'SELECT insee_com,cadastre_com,nom_com,cadastre_dept FROM code_cadastre WHERE format_cadastre = \'VECT\' AND dept = \'{:s}\' ORDER BY dept,nom_com;'.format(sys.argv[1])
else:
	str_query = 'SELECT c.insee_com,c.cadastre_com,c.nom_com,c.cadastre_dept FROM code_cadastre c LEFT OUTER JOIN (SELECT cadastre_com FROM batch WHERE etape = \'importQadastre\' AND date_fin IS NOT NULL) b ON c.cadastre_com = b.cadastre_com WHERE b.cadastre_com IS NULL AND c.format_cadastre = \'VECT\' ORDER BY dept,nom_com;' 

cur = pgc.cursor()
cur.execute(str_query)
for c in cur:
	print(c[2])
	parts = glob.glob('/data/work/cadastre.openstreetmap.fr/bano_cache/{:s}/{:s}/{:s}-[0-9]-[0-9].pdf'.format(c[3],c[1],c[1]))
	nb_parts = len(parts)
	batch_id = batch_start_log('CADASTRE','importQadastre',c[1])
	for p in parts:
		# print(p)
		p_out = p[0:-4]+'-houses.osm'
		p_out_city = p[0:-4]+'-city-limit.osm'
		p_out_water = p[0:-4]+'-water.osm'
		suffixe = '-'.join(p[0:-4].rsplit('-',2)[1:])
		if not (os.path.exists(p_out) or os.path.exists(p_out_city) or os.path.exists(p_out_water) ):
			print(p_out)
			subprocess.call('./qadastre.sh {:s} {:s} "{:s}"'.format(c[3],c[1],suffixe),shell=True)
			if not os.path.exists(p_out):
				nb_parts -=1
		# os._exit(0)
	batch_end_log(nb_parts,batch_id)
	time.sleep(1)
	# os._exit(0)
Exemplo n.º 20
0
def main(args):
	global source,batch_id
	global pgc,pgcl
	global code_insee,code_cadastre,code_dept
	global dicts
	global nodes,ways,adresses
	global commune_avec_suffixe
	global geom_suffixe
	global use_cache
	
	use_cache = True

	debut_total = time.time()
	usage = 'USAGE : python addr_cad_2_db.py <code INSEE> <OSM|CADASTRE> {use_cache=True}'
	if len(args) < 3:
		print(usage)
		os._exit(0)
	if len(args) > 3:
		# use_cache = eval(args[3])
		use_cache = args[3]
	source = args[2].upper()
	if source not in ['OSM','CADASTRE']:
		print(usage)
		os._exit(0)

	adresses = Adresses()
	
	pgc = get_pgc()
	pgcl = get_pgc_layers()
	
	code_insee = args[1]
	code_cadastre = get_code_cadastre_from_insee(code_insee)
	code_dept = get_cadastre_code_dept_from_insee(code_insee)
	
	batch_id = batch_start_log(source,'loadCumul',code_cadastre)
	
	dicts = Dicts()
	dicts.load_all(code_insee)

	commune_avec_suffixe = has_addreses_with_suffix(code_insee)
	geom_suffixe = None
	if commune_avec_suffixe:
		geom_suffixe = get_geom_suffixes(code_insee,code_cadastre)

	if source == 'CADASTRE':
		fnadresses = os.path.join('/data/work/cadastre.openstreetmap.fr/bano_cache',code_dept,code_cadastre,code_cadastre+'-adresses.osm')
		load_hsnr_from_cad_file(fnadresses,source)
	if source == 'OSM':
		load_hsnr_from_pg_osm(code_insee,code_cadastre)
		load_hsnr_bbox_from_pg_osm(code_insee,code_cadastre)
		load_type_highway_from_pg_osm(code_insee,code_cadastre)
	load_highways_from_pg_osm(code_insee,code_cadastre)
	load_highways_relations_from_pg_osm(code_insee,code_cadastre)
	load_highways_bbox_from_pg_osm(code_insee,code_cadastre)
	load_highways_relations_bbox_from_pg_osm(code_insee,code_cadastre)
	add_fantoir_to_hsnr()
	load_point_par_rue_from_pg_osm(code_insee,code_cadastre)
	load_point_par_rue_complement_from_pg_osm(code_insee,code_cadastre)
	nb_rec = load_to_db(adresses,code_insee,source,code_cadastre,code_dept)
	
	batch_end_log(nb_rec,batch_id)
	fin_total = time.time()