Esempio n. 1
0
def test_get_intersected_field_values2():

    # expected values to test with actual values
    expected = {}
    expected["canes_tiles"] = {"0": ["31", "32", "21", "11"]}
    expected["gfdl_tiles"] = {"0": ["41", "42", "31", "32", "21"]}
    expected["giss_tiles"] = {"0": ["41", "42", "31", "21"]}
    expected["ncar_tiles"] = {"0": ["82", "83", "84", "72", "73", "74", "62", "63", "64", "52", "53", "42", "43", "32", "22"]}

    # open the shapefiles
    basin_shapefile = osgeo.ogr.Open(fixture["test_poly_nad83"])    
    canes_shapefile = osgeo.ogr.Open(fixture["canes_nad83"])
    gfdl_shapefile = osgeo.ogr.Open(fixture["gfdl_nad83"])
    giss_shapefile = osgeo.ogr.Open(fixture["giss_nad83"])
    ncar_shapefile = osgeo.ogr.Open(fixture["ncar_nad83"])

    # actual values    
    actual = {}
    actual["canes_tiles"] = spatialvectors.get_intersected_field_values(intersector = basin_shapefile, intersectee = canes_shapefile, intersectee_field = "Tile", intersector_field = "")    
    actual["gfdl_tiles"] = spatialvectors.get_intersected_field_values(intersector = basin_shapefile, intersectee = gfdl_shapefile, intersectee_field = "Tile", intersector_field = "")
    actual["giss_tiles"] = spatialvectors.get_intersected_field_values(intersector = basin_shapefile, intersectee = giss_shapefile, intersectee_field = "Tile", intersector_field = "")
    actual["ncar_tiles"] = spatialvectors.get_intersected_field_values(intersector = basin_shapefile, intersectee = ncar_shapefile, intersectee_field = "Tile", intersector_field = "")

    for shapefile in [basin_shapefile, canes_shapefile, gfdl_shapefile, giss_shapefile, ncar_shapefile]:
        shapefile.Destroy()  

    np.testing.assert_equal(actual["canes_tiles"], expected["canes_tiles"])
    np.testing.assert_equal(actual["gfdl_tiles"], expected["gfdl_tiles"])    
    np.testing.assert_equal(actual["giss_tiles"], expected["giss_tiles"])   
    np.testing.assert_equal(actual["ncar_tiles"], expected["ncar_tiles"])
Esempio n. 2
0
def test_get_intersected_field_values4():

    # expected values to test with actual values
    expected = {}
    expected["newhydroid"] = {"01413500": ["149", "61", "22"], "01420500": ["440", "390", "257"], "01414500": None, "01435000": ["262", "220"]}   

    # open the shapefiles
    basin_shapefile = osgeo.ogr.Open(fixture["water_basins_wgs84"])    
    point_shapefile = osgeo.ogr.Open(fixture["wateruse_centroids_sample_wgs84"])

    # actual values    
    actual = {}
    actual["newhydroid"] = spatialvectors.get_intersected_field_values(intersector = basin_shapefile, intersectee = point_shapefile, intersectee_field = "newhydroid", intersector_field = "STAID")

    for shapefile in [basin_shapefile, point_shapefile]:
        shapefile.Destroy()  

    np.testing.assert_equal(actual["newhydroid"], expected["newhydroid"])