-
Notifications
You must be signed in to change notification settings - Fork 39
Description
########################
WHAT WE WANT TO ACHIEVE
In order to delineate the catchment area we need to accurately provide the location coordinate of the gauging station e.g. [146709.6323,42159.6226]
. We also need to assure that the location of the gauging station is exactly located on a rasterized river network.
I would have imagined that the location of the gauging station should be located at the centre of the cell. Nevertheless, this method was giving me random results which shifted the cell Up, Bottom, Left, Right.
I investigated the problem and found that depending on the point location of the gaging station in the cell (displayed in QGIS) would give different results (see diagram):
• Left-top;
• Right-top;
• Left-Bottom;
• Right-Bottom;
In order that the location of the gaging station matches the location of the raster cell, I found that the location of the gaging station should be at the left-top of the cell (In the Northern hemispher) and not in the centre of the cell, which I believe is a BUG.
########################
# CONVERTING GAGING POINT -> RASTER POINT
function GAUGE(;Gauge_Name, Longitude=Longitude, Latitude=Latitude, Param_GaugeCoordinate)
Gauge = Rasters.Raster((Longitude, Latitude), crs=Crs_GeoFormat)
Gauge .= 0
iX_Gauge, iY_Gauge = Rasters.dims2indices(Gauge, (X(Rasters.Near(Param_GaugeCoordinate[1])), Y(Rasters.Near(Param_GaugeCoordinate[2]))))
Gauge[iX_Gauge, iY_Gauge] = 1
# Saving file
Path_OutputGauge = joinpath(Path_Root, Path_OutputWflow, Gauge_Name)
Rasters.write(Path_OutputGauge, Gauge; ext=".tiff", force=true, verbose=true, missingval=0)
end
# PARAMETERS
ΔX = step(dims(Map, X))
ΔY = step(dims(Map, Y)
Coord_X_Left = first(dims(Map, X))
Coord_X_Right = last(dims(Map, X))
Coord_Y_Top = first(dims(Map ,Y))
Coord_Y_Bottom = last(dims(Map,Y))
Crs_GeoFormat = GeoFormatTypes.convert(WellKnownText, EPSG(Param_Crs))
Longitude, Latitude = Rasters.X(Coord_X_Left: ΔX: Coord_X_Right, crs=Crs_GeoFormat), Rasters.Y(Coord_Y_Top: ΔY: Coord_Y_Bottom, crs=Crs_GeoFormat)
# RUNNING CODE
Param_GaugeCoordinate_X_Right_Top = [146709.6323,42159.6226]
Param_GaugeCoordinate_X_Left_Top = [146700.2167,42159.7300]
Param_GaugeCoordinate_Center = [146726.378,42150.827]
Param_GaugeCoordinate_X_Right_Bottom = [146709.7495,42150.1972]
Param_GaugeCoordinate_X_Left_Bottom = [146700.2801,42150.2118]
GAUGE(Gauge_Name="Gauge_Wflow_X_Right_Top.tiff", Param_GaugeCoordinate=Param_GaugeCoordinate_X_Right_Top)
GAUGE(Gauge_Name="Gauge_Wflow_X_Left_Top.tiff", Param_GaugeCoordinate=Param_GaugeCoordinate_X_Left_Top)
GAUGE(Gauge_Name="Gauge_Wflow_X_Right_Bottom.tiff", Param_GaugeCoordinate=Param_GaugeCoordinate_X_Right_Bottom)
GAUGE(Gauge_Name="Gauge_Wflow_X_Left_Bottom.tiff", Param_GaugeCoordinate=Param_GaugeCoordinate_X_Left_Bottom)