Exemplo n.º 1
0
def _create_shapefile_test_data():
    """ Create test data for tests """
    import spatialvectors
    import osgeo.ogr

    fixture = {}

    # open the shapefiles
    test_poly_wgs84_shapefile = osgeo.ogr.Open(
        os.path.abspath(
            os.path.join(
                os.getcwd(),
                "../../data/spatial-datafiles/basins/test_poly_wgs84.shp")))
    water_basin_wgs84_shapefile = osgeo.ogr.Open(
        os.path.abspath(
            os.path.join(
                os.getcwd(),
                "../../data/spatial-datafiles/basins/water_basin_wgs84.shp")))
    water_basins_wgs84_shapefile = osgeo.ogr.Open(
        os.path.abspath(
            os.path.join(
                os.getcwd(),
                "../../data/spatial-datafiles/basins/water_basins_wgs84.shp")))
    water_basin_pourpoint_wgs84_shapefile = osgeo.ogr.Open(
        os.path.abspath(
            os.path.join(
                os.getcwd(),
                "../../data/spatial-datafiles/basins/water_basin_pourpoint_wgs84.shp"
            )))
    canes_wgs84_shapefile = osgeo.ogr.Open(
        os.path.abspath(
            os.path.join(
                os.getcwd(),
                "../../data/spatial-datafiles/gcm-tiles/CanES_wgs84.shp")))
    wateruse_centroids_sample_wgs84_shapefile = osgeo.ogr.Open(
        os.path.abspath(
            os.path.join(
                os.getcwd(),
                "../../data/spatial-datafiles/wateruse-centroids/wateruse_centroids_sample_wgs84.shp"
            )))

    fixture["test_poly_wgs84"] = spatialvectors.fill_shapefile_dict(
        shapefile=test_poly_wgs84_shapefile)
    fixture["water_basin_wgs84"] = spatialvectors.fill_shapefile_dict(
        shapefile=water_basin_wgs84_shapefile)
    fixture["water_basins_wgs84"] = spatialvectors.fill_shapefile_dict(
        shapefile=water_basins_wgs84_shapefile)
    fixture[
        "water_basin_pourpoint_wgs84"] = spatialvectors.fill_shapefile_dict(
            shapefile=water_basin_pourpoint_wgs84_shapefile)
    fixture["canes_wgs84"] = spatialvectors.fill_shapefile_dict(
        shapefile=canes_wgs84_shapefile)
    fixture[
        "wateruse_centroids_sample_wgs84"] = spatialvectors.fill_shapefile_dict(
            shapefile=wateruse_centroids_sample_wgs84_shapefile)

    return fixture
Exemplo n.º 2
0
def get_shps_colors_fields(files_list, settings):
	"""
	Return shapefiles, projected to WGS84 (if needed) and 
	lists of map display fields and colors corresponding to 
	each shapefile.

    Parameters
    ----------
    files_list : list
    	List of shapefiles to create a map with
    settings : dictionary
        Dictionary of user settings
	"""
	# reproject all shapefiles
	shp_reproj_list = spatialvectors.reproject(shapefiles = files_list)

	shp_info_list = []
	display_fields = []
	colors = []
	colors_index = 0
	for shapefile in shp_reproj_list:
	    shp = osgeo.ogr.Open(shapefile)    

	    shp_info = spatialvectors.fill_shapefile_dict(shapefile = shp)
	    shp_info_list.append(shp_info)

	    for key, values in settings["water_shapefiles"].iteritems():
	        if key in shp_info["name"].split("_")[0]:
	        	display_fields.append(values["field"])
	        	colors.append(values["color"])

	    if not colors:
			display_fields.append("")
			colors.append(settings["map_colors_list"][colors_index])
			colors_index += 1

	return shp_info_list, display_fields, colors
Exemplo n.º 3
0
def get_shps_colors_fields(files_list, settings):
    """
	Return shapefiles, projected to WGS84 (if needed) and 
	lists of map display fields and colors corresponding to 
	each shapefile.

    Parameters
    ----------
    files_list : list
    	List of shapefiles to create a map with
    settings : dictionary
        Dictionary of user settings
	"""
    # reproject all shapefiles
    shp_reproj_list = spatialvectors.reproject(shapefiles=files_list)

    shp_info_list = []
    display_fields = []
    colors = []
    colors_index = 0
    for shapefile in shp_reproj_list:
        shp = osgeo.ogr.Open(shapefile)

        shp_info = spatialvectors.fill_shapefile_dict(shapefile=shp)
        shp_info_list.append(shp_info)

        for key, values in settings["water_shapefiles"].iteritems():
            if key in shp_info["name"].split("_")[0]:
                display_fields.append(values["field"])
                colors.append(values["color"])

        if not colors:
            display_fields.append("")
            colors.append(settings["map_colors_list"][colors_index])
            colors_index += 1

    return shp_info_list, display_fields, colors
def _create_shapefile_test_data():
    """ Create test data for tests """
    import spatialvectors
    import osgeo.ogr
    
    fixture = {}

    # open the shapefiles
    test_poly_wgs84_shapefile = osgeo.ogr.Open(os.path.abspath(os.path.join(os.getcwd(), "../../data/spatial-datafiles/basins/test_poly_wgs84.shp"))) 
    water_basin_wgs84_shapefile = osgeo.ogr.Open(os.path.abspath(os.path.join(os.getcwd(), "../../data/spatial-datafiles/basins/water_basin_wgs84.shp")))      
    water_basins_wgs84_shapefile = osgeo.ogr.Open(os.path.abspath(os.path.join(os.getcwd(), "../../data/spatial-datafiles/basins/water_basins_wgs84.shp")))  
    water_basin_pourpoint_wgs84_shapefile = osgeo.ogr.Open(os.path.abspath(os.path.join(os.getcwd(), "../../data/spatial-datafiles/basins/water_basin_pourpoint_wgs84.shp")))      
    canes_wgs84_shapefile = osgeo.ogr.Open(os.path.abspath(os.path.join(os.getcwd(), "../../data/spatial-datafiles/gcm-tiles/CanES_wgs84.shp"))) 
    wateruse_centroids_sample_wgs84_shapefile = osgeo.ogr.Open(os.path.abspath(os.path.join(os.getcwd(), "../../data/spatial-datafiles/wateruse-centroids/wateruse_centroids_sample_wgs84.shp"))) 

    fixture["test_poly_wgs84"] = spatialvectors.fill_shapefile_dict(shapefile = test_poly_wgs84_shapefile)
    fixture["water_basin_wgs84"] = spatialvectors.fill_shapefile_dict(shapefile = water_basin_wgs84_shapefile)
    fixture["water_basins_wgs84"] = spatialvectors.fill_shapefile_dict(shapefile = water_basins_wgs84_shapefile)
    fixture["water_basin_pourpoint_wgs84"] = spatialvectors.fill_shapefile_dict(shapefile = water_basin_pourpoint_wgs84_shapefile)
    fixture["canes_wgs84"] = spatialvectors.fill_shapefile_dict(shapefile = canes_wgs84_shapefile)  
    fixture["wateruse_centroids_sample_wgs84"] = spatialvectors.fill_shapefile_dict(shapefile = wateruse_centroids_sample_wgs84_shapefile)  

    return fixture