## GeoTiff
"""
import mapping.geotools.coordtrans as ct
tif_filespec = r"D:\GIS-data\Belgium\DEM\ngi_dem1_Lambert.tif"
grd_data = lbm.GdalRasterData(tif_filespec, band_nr=0)
grd_data.srs = ct.get_epsg_srs(31370)
grd_style = lbm.GridImageStyle(alpha=0.75)
layer = lbm.MapLayer(grd_data, grd_style)
layers.append(layer)
"""

## Coastlines
coastline_style = lbm.LineStyle(line_color="k", line_width=1)
data = lbm.BuiltinData("coastlines")
layer = lbm.MapLayer(data, coastline_style)
#layers.append(layer)

## Country borders
data = lbm.BuiltinData("countries")
country_style = lbm.LineStyle(line_color="k", line_width=0.75)
layer = lbm.MapLayer(data, country_style)
#layers.append(layer)

## Countries
country_color = "oldlace"
for country in ("france", "germany", "luxembourg", "netherlands",
                "united_kingdom"):
    gis_filename = country + ".TAB"
    gis_filespec = os.path.join(
        "D:\seismo-gis\collections\DCW_countries\Europe\TAB", gis_filename)
#region = (1, 8, 49, 52)
#region = (6, 7, 49, 50)
region = (5., 8., 49.5, 51.5)
projection = "tmerc"
title = "GeoTIFF example"

layers = []

## GeoTiff image
#geotiff_filespec = "C:\\Temp\\matplotlib.tif"
#geotiff_filespec = "E:\\Public\\Data RegWallonne\\Hazard Maps\\rock\\Tr=02500yr\\HazardMap_T=0.0s_Tr=02500yr.TIF"
#geotiff_filespec = "D:\\GIS-data\\Belgium\\DEM\\ngi_dem1_Lambert.TIF"
geotiff_filespec = "C:\\Temp\\macromap.TIF"
gdal_data = lbm.GdalRasterData(geotiff_filespec, band_nr=0, down_sampling=1)
style = lbm.GridImageStyle()
layer = lbm.MapLayer(gdal_data, style)
#layers.append(layer)

## WCS / GeoTiff raster
#geotiff_filespec = "E:\\Home\\_kris\\Projects\\2015 - RegionWallonne\\Figures\\Hazard maps\\rock\\HazardMap_T=0.000s_2.5E+03yr.TIF"
geotiff_filespec = "D:\\seismo-gis\\collections\\ASTER_GDEM\\GEOTIFF\\ASTGTM_N50E006.tif"
gdal_data = lbm.GdalRasterData(geotiff_filespec, band_nr=1, down_sampling=3)
"""
url = 'http://seishaz.oma.be:8080/geoserver/wcs'
layer_name, resolution, bbox = 'ngi:DTM10k', 1000, []
#layer_name, resolution, bbox = 'nasa:ASTER_GDEM_V2', 0.02, region[::2]+region[1::2]
wcs_data = lbm.WCSData(url, layer_name, resolution=resolution, bbox=bbox)
"""
colorbar_style = lbm.ColorbarStyle("Elevation (m)")
#colorbar_style = None
#hillshade_style = lbm.HillshadeStyle(azimuth=45,elevation_angle=30, scale=0.1, color_map="copper")
tick_labels = [
    "%.2f" % contour_levels[i] if i % 2 == 0 else ''
    for i in range(len(contour_levels))
]
colorbar_style = lbm.ColorbarStyle(
    'PGA (g), 10% probability of exceedance in 50 yr',
    format='%.2f',
    spacing='uniform',
    ticks=contour_levels,
    tick_labels=tick_labels)
grd_style = lbm.GridStyle(color_map_theme,
                          contour_levels=contour_levels,
                          contour_labels=contour_labels,
                          line_style=line_style,
                          colorbar_style=colorbar_style)
layer = lbm.MapLayer(grd_data, grd_style)
layers.append(layer)

## Coastlines
coastline_style = lbm.LineStyle(line_color="k", line_width=1)
data = lbm.BuiltinData("coastlines")
layer = lbm.MapLayer(data, coastline_style)
layers.append(layer)

## Provinces
gis_file = r"D:\seismo-gis\collections\Bel_administrative_ROB\TAB\Bel_provinces.TAB"
data = lbm.GisData(gis_file)
style = lbm.PolygonStyle(line_color="k", line_width=0.5, fill_color=None)
layer = lbm.MapLayer(data, style)
layers.append(layer)
#fig_filespec = "E:\\Home\\_kris\\Projects\\2013 - cAt_Rev\\Figures\\Maps\\FocalMechanisms.png"
fig_filespec = None

region = (3, 7, 50, 51.5)
projection = "merc"
#title = "ROB focal mechanisms"
title = ""
resolution = "h"
graticule_interval = (1, 0.5)

layers = []

## Coastlines
coastline_style = lbm.LineStyle(line_color="k", line_width=2)
data = lbm.BuiltinData("coastlines")
layer = lbm.MapLayer(data, coastline_style)
layers.append(layer)

## Country borders
data = lbm.BuiltinData("countries")
country_style = lbm.LineStyle(line_color="k", line_width=2, line_pattern='--')
layer = lbm.MapLayer(data, country_style)
layers.append(layer)

## Source model
#sm_name= "Seismotectonic_Hybrid"
sm_name = "Seismotectonic"
gis_filespec = rob_source_models_dict[sm_name].gis_filespec
src_label_name = rob_source_models_dict[sm_name].column_map['id']
data = lbm.GisData(gis_filespec, src_label_name)
#label_style = lbm.TextStyle(color='darkred', font_weight="bold", horizontal_alignment="center", vertical_alignment="center")
import mapping.layeredbasemap as lbm


region = (-180, 180, -90, 90)
origin = (0, 0)
projection = "moll"
title = "Hello World from LayeredBasemap"
resolution = "c"
graticule_interval = (60, 30)

layers = []

## BlueMarble image
bm_style = None
data = lbm.BuiltinData("bluemarble")
layer = lbm.MapLayer(data, bm_style)
#layers.append(layer)

## Continents
continent_style = lbm.PolygonStyle(fill_color="cornsilk", line_pattern=None, line_width=0)
continent_style.bg_color = "powderblue"
data = lbm.BuiltinData("continents")
layer = lbm.MapLayer(data, continent_style)
layers.append(layer)

## Coastlines
coastline_style = lbm.LineStyle(line_color="burlywood", line_width=2)
data = lbm.BuiltinData("coastlines")
layer = lbm.MapLayer(data, coastline_style)
layers.append(layer)
import mapping.layeredbasemap as lbm


region = (0,8,49,52)
projection = "tmerc"
title = "Circles demo"
resolution = "h"
graticule_interval = (2, 1)

layers = []

## Coastlines
coastline_style = lbm.LineStyle(line_color="k", line_width=2)
data = lbm.BuiltinData("coastlines")
layer = lbm.MapLayer(data, coastline_style)
layers.append(layer)

## Country borders
data = lbm.BuiltinData("countries")
country_style = lbm.LineStyle(line_color="k", line_width=2, line_pattern='--')
layer = lbm.MapLayer(data, country_style)
layers.append(layer)

## Circles
uccle = (4.367785, 50.795003)
distances = [25, 50, 75, 100]
circle_data = lbm.CircleData([uccle[0]]*4, [uccle[1]]*4, distances, values=distances, azimuthal_resolution=5)
thematic_color = lbm.ThematicStyleIndividual(distances, ["yellow", "orange", "red", "purple"], colorbar_style=None)
circle_style = lbm.LineStyle(line_color=thematic_color, line_width=2)
layer = lbm.MapLayer(circle_data, circle_style)
    colorbar_style = lbm.ColorbarStyle(title=attribute,
                                       ticks=range(1, 11),
                                       spacing="proportional")
    tsi.colorbar_style = colorbar_style
elif attribute == "id_main":
    values = joined_attributes[attribute]['values'].values()
    vmin, vmax = np.min(values), np.max(values)
    tsi = lbm.ThematicStyleColormap(value_key=attribute, vmin=vmin, vmax=vmax)
    thematic_legend_style = None
    colorbar_style = lbm.ColorbarStyle(title=attribute)
    tsi.colorbar_style = colorbar_style
polygon_style = lbm.PolygonStyle(fill_color=tsi,
                                 line_width=0.1,
                                 thematic_legend_style=thematic_legend_style)
style = lbm.CompositeStyle(polygon_style=polygon_style)
commune_layer = lbm.MapLayer(gis_data, style, legend_label={"polygons": ""})
layers.append(commune_layer)

## Province layer
data = lbm.GisData(
    "D:\\seismo-gis\\collections\\Bel_administrative_ROB\\TAB\\Bel_provinces.TAB"
)
polygon_style = lbm.PolygonStyle(line_width=1, fill_color='none')
gis_style = lbm.CompositeStyle(polygon_style=polygon_style)
province_layer = lbm.MapLayer(data, gis_style, legend_label={"polygons": ""})
layers.append(province_layer)

map = lbm.LayeredBasemap(layers, title, projection, region=region)
fig_filespec = None
#fig_filespec = "C:\\Temp\\seismodb_%s.png" % attribute
map.plot(fig_filespec=fig_filespec)
from eqcatalog.source_models import rob_source_models_dict
import mapping.layeredbasemap as lbm


fig_folder = "E:\\Home\\_kris\\Publications\\2014 - DGEB"
fig_filespec = None
#fig_filespec = os.path.join(fig_folder, "SourceModel_RVRS_CSS.png")


layers = []

## Coastlines
data = lbm.BuiltinData("coastlines")
style = lbm.LineStyle()
layer = lbm.MapLayer(data, style)
layers.append(layer)

## Countries
data = lbm.BuiltinData("countries")
style = lbm.LineStyle(line_pattern="dashed")
layer = lbm.MapLayer(data, style)
layers.append(layer)

## Fault sources (projected fault planes)
sm_name = "RVRS_CSS"
gis_filespec = rob_source_models_dict[sm_name].gis_filespec
gis_filespec = gis_filespec.split('_')[0] + ".TAB"
#src_label_name = rob_source_models_dict[sm_name].column_map['id']
src_label_name = None
data = lbm.GisData(gis_filespec, src_label_name)
import mapping.layeredbasemap as lbm

region = (1, 8, 49, 52)
projection = "merc"
#projection = "EPSG:31300"
title = "Test"
resolution = "i"
graticule_interval = (2, 1)

layers = []

data = lbm.WMSData("http://seishaz.oma.be:8080/geoserver/rob/wms?",
                   layers=["bel_villages_polygons"],
                   verbose=True)
style = lbm.WMSStyle(xpixels=1200)
layer = lbm.MapLayer(data, style)
#layers.append(layer)

coastline_style = lbm.LineStyle(line_color="r", line_width=1)
data = lbm.BuiltinData("coastlines")
layer = lbm.MapLayer(data, coastline_style)
layers.append(layer)

#data = lbm.GdalRasterData("C:\\Temp\\matplotlib.tif", band_nr=0)
#style = lbm.GridImageStyle(masked=True, alpha=0.5)
#layer = lbm.MapLayer(data, style)
#layers.append(layer)

data = lbm.BuiltinData("countries")
country_style = lbm.LineStyle(line_color="r", line_width=1, line_pattern='--')
layer = lbm.MapLayer(data, country_style)