예제 #1
0
def _test_hexagon_overlay(db: PostgreSQL, shp: DataForTest):

    hex_table_name = "test_hexagons"

    # Make a hexagon layer
    db.make_hexagon_overlay(
        hex_table_name, table_to_cover=shp.NAME, desired_epsg=2272, hexagon_size=5
    )

    assert hex_table_name in db.all_spatial_tables_as_dict()
예제 #2
0
def _test_shp2pgsql_epsg(db: PostgreSQL, shp: DataForTest):

    # Import the shapefile
    _ = db.shp2pgsql(shp.NAME, shp.IMPORT_FILEPATH)

    # Confirm SQL table and shapefile both have same EPSGs
    gdf = gpd.read_file(shp.IMPORT_FILEPATH)
    shapefile_crs = gdf.crs

    sql_epsg = db.all_spatial_tables_as_dict()[shp.NAME]

    assert sql_epsg == shapefile_crs
예제 #3
0
def _test_pgsql2shp_epsg(db: PostgreSQL, shp: DataForTest):

    # Export a spatial table to shapefile
    output_shp = db.pgsql2shp(shp.NAME, shp.EXPORT_FOLDER)

    gdf = gpd.read_file(output_shp)

    sql_epsg = db.all_spatial_tables_as_dict()[shp.NAME]

    shapefile_crs = gdf.crs

    assert sql_epsg == shapefile_crs
def _test_transfer_data_spatial(db1: PostgreSQL, db2: PostgreSQL, shp: DataForTest):

    table_name = shp.NAME

    # Make sure that this table does not exist in the 2nd database
    if table_name in db2.all_tables_as_list():
        db2.table_delete(table_name)

    # Transfer to the 2nd database
    db1.transfer_data_to_another_db(table_name, db2)

    # Confirm there is now a table in the DB
    assert table_name in db2.all_spatial_tables_as_dict()
def _test_make_geotable_from_query(db: PostgreSQL, shp: DataForTest):

    new_geotable = "test_make_geotable_multilinestring"

    query = f"""
        SELECT ST_UNION(geom) AS geom
        FROM {shp.NAME}
    """

    # Make a new geotable
    db.make_geotable_from_query(query,
                                new_geotable,
                                geom_type="MULTILINESTRING",
                                epsg=shp.EPSG)

    # Confirm that the new table's EPSG matches the expected value
    epsg = db.all_spatial_tables_as_dict()[new_geotable]

    assert epsg == shp.EPSG
예제 #6
0
def _test_shp2pgsql(db: PostgreSQL, shp: DataForTest):

    # Import the shapefile
    _ = db.shp2pgsql(shp.NAME, shp.IMPORT_FILEPATH)

    assert shp.NAME in db.all_spatial_tables_as_dict()