Beispiel #1
0
def main(csv_file):
    #open the csv file
    with open(csv_file, 'r') as csv_input:
        #establish the data as a header-accessible dictionary
        reader = csv.DictReader(csv_input)
        #for each row in the data, read in a filename,
        #grab the file and append it to a table in the evl
        #postgres database for later use
        for row in reader:
            print(row['filename'])
            #initialize ogr2ogr
            ogr = gdaltools.ogr2ogr()
            ogr.set_encoding("UTF-8")
            #establish connection settings
            conn = gdaltools.PgConnectionString(host='localhost',
                                                port=5432,
                                                dbname='evl',
                                                user='******')
            #set up the file input from the isochrones directory
            ogr.set_input('data/isochrones/' + row['filename'])
            #specify the table and postgres format for PostGIS
            ogr.set_output(conn, table_name='isochrones')
            #make sure we append the data
            ogr.set_output_mode(layer_mode=ogr.MODE_LAYER_APPEND)
            #run ogr2ogr
            ogr.execute()
Beispiel #2
0
def _get_layer_conn(layer):
    try:
        conn_params = layer.datastore.connection_params
        params_dict = json.loads(conn_params)
        host = params_dict["host"]
        port = params_dict["port"]
        dbname = params_dict["database"]
        schema = params_dict["schema"]
        user = params_dict["user"]
        password = params_dict["passwd"]
        return gdaltools.PgConnectionString(host, port, dbname, schema, user,
                                            password)
    except:
        pass
def import_zsj(connection, schema, zipfile, kraje=False, vusc=False,
        okresy=False, orp=False, pou=False):

    global logger
    zsj_file_name = get_data_zsj(ZSJ_URL, "zsj", zipfile)
    connection_params = _get_connection(connection)
    if schema:
        connection_params["schema"] = schema

    ogr = gdaltools.ogr2ogr()
    ogr.set_output_mode(
            data_source_mode=ogr.MODE_DS_CREATE_OR_UPDATE,
            layer_mode=ogr.MODE_LAYER_OVERWRITE
    )
    conn = gdaltools.PgConnectionString(**connection_params)

    if kraje:
        logger.info('Importing kraje')
        ogr.set_input(zsj_file_name, table_name="Kraje")
        ogr.set_output(conn, table_name="kraje", srs="EPSG:5514")
        ogr.execute()

    if vusc:
        logger.info('Importing vusc')
        ogr.set_input(zsj_file_name, table_name="Vusc")
        ogr.set_output(conn, table_name="vusc", srs="EPSG:5514")
        ogr.execute()

    if okresy:
        logger.info('Importing okresy')
        ogr.set_input(zsj_file_name, table_name="Okresy")
        ogr.set_output(conn, table_name="okresy", srs="EPSG:5514")
        ogr.execute()

    if orp:
        logger.info('Importing orp')
        ogr.set_input(zsj_file_name, table_name="Orp")
        ogr.set_output(conn, table_name="orp", srs="EPSG:5514")
        ogr.execute()

    if pou:
        logger.info('Importing pou')
        ogr.set_input(zsj_file_name, table_name="Pou")
        ogr.set_output(conn, table_name="pou", srs="EPSG:5514")
        ogr.execute()
def import_obce(connection, schema, obec=False, ku=False, casti_obci=False, ulice=False,
        casti_obci=False, parcely=False, stav_objekty=False, adresy=False):

    global logger

    connection_params = _get_connection(connection)
    if schema:
        connection_params["schema"] = schema

    ogr = gdaltools.ogr2ogr()
    ogr.set_output_mode(
        data_source_mode=ogr.MODE_DS_CREATE_OR_UPDATE,
        layer_mode=ogr.MODE_LAYER_OVERWRITE
    )
    conn = gdaltools.PgConnectionString(**connection_params)

    obce_cislenik = get_obce_cislenik()
    for obec in obce_cislenik:
        if not obec["platne_do"]:
            kod = obec["kod"]
            obec_file = get_obec_file(kod)

            logger.info(f"Importing obec {obec['kod']} - {obec['nazev']}")

            if obec:
                ogr.set_input(obec_file, table_name="Obce")
                ogr.set_output(conn, table_name="obce", srs="EPSG:5514")
                ogr.execute()

            if ku:
                ogr.set_input(obec_file, table_name="KatastralniUzemi")
                ogr.set_output(conn, table_name="katastralni_uzemi", srs="EPSG:5514")
                ogr.execute()

            if casti_obci:
                ogr.set_input(obec_file, table_name="Ulice")
                ogr.set_output(conn, table_name="CastiObci", srs="EPSG:5514")
                ogr.execute()

            if ulice:
                ogr.set_input(obec_file, table_name="Ulice")
                ogr.set_output(conn, table_name="ulice", srs="EPSG:5514")
                ogr.execute()

            if parcely:
                ogr.set_input(obec_file, table_name="Parcely")
                ogr.set_output(conn, table_name="parcely", srs="EPSG:5514")
                ogr.execute()

            if stav_objekty:
                ogr.set_input(obec_file, table_name="StavebniObjekty")
                ogr.set_output(conn, table_name="stavebni_objekty", srs="EPSG:5514")
                ogr.execute()

            if adresy:
                ogr.set_input(obec_file, table_name="AdresniMista")
                ogr.set_output(conn, table_name="adresni_mista", srs="EPSG:5514")
                ogr.execute()

            # from now on, just append
            ogr.set_output_mode(
                data_source_mode=ogr.MODE_DS_CREATE_OR_UPDATE,
                layer_mode=ogr.MODE_LAYER_APPEND
            )