34using std::resetiosflags;
35using std::setiosflags;
36using std::setprecision;
82 for (
unsigned int n = 0; n <
m_VEdgeCell.size(); n++)
114 stack<CGeom2DIPoint> PtiStack;
122 while (! PtiStack.empty())
125 if (nRoundLoop++ > nRoundLoopMax)
131 int nX = Pti.
nGetX();
132 int nY = Pti.
nGetY();
134 while ((nX >= 0) && (!
m_pRasterGrid->m_Cell[nX][nY].bBasementElevIsMissingValue()) && (
m_pRasterGrid->m_Cell[nX][nY].bIsInundated()))
139 bool bSpanAbove =
false;
140 bool bSpanBelow =
false;
159 m_pRasterGrid->m_Cell[nX][nY].SetWaveValuesToDeepWaterWaveValues();
175 m_pRasterGrid->m_Cell[nX][nY].SetWaveValuesToDeepWaterWaveValues();
194 if ((! bSpanAbove) && (nY > 0) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bBasementElevIsMissingValue()) && (
m_pRasterGrid->m_Cell[nX][nY - 1].bIsInundated()))
200 else if (bSpanAbove && (nY > 0) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bBasementElevIsMissingValue()) && (!
m_pRasterGrid->m_Cell[nX][nY - 1].bIsInundated()))
221 string strOutFile =
m_strOutPath +
"is_contiguous_sea_";
223 strOutFile +=
".tif";
225 GDALDriver* pDriver = GetGDALDriverManager()->GetDriverByName(
"gtiff");
235 pdRaster[n++] =
m_pRasterGrid->m_Cell[nX][nY].bIsInContiguousSea();
239 GDALRasterBand* pBand = pDataSet->GetRasterBand(1);
241 int nRet = pBand->RasterIO(GF_Write, 0, 0,
m_nXGridSize,
m_nYGridSize, pdRaster,
m_nXGridSize,
m_nYGridSize, GDT_Float64, 0, 0, NULL);
242 if (nRet == CE_Failure)
300 vector<bool> VbPossibleStartCellLHEdge;
301 vector<bool> VbTraced;
302 vector<int> VnSearchDirection;
303 vector<CGeom2DIPoint> V2DIPossibleStartCell;
306 for (
unsigned int n = 0; n <
m_VEdgeCell.size() - 1; n++)
326 bool bThisCellIsSea =
m_pRasterGrid->m_Cell[nXThis][nYThis].bIsInContiguousSea();
327 bool bNextCellIsSea =
m_pRasterGrid->m_Cell[nXNext][nYNext].bIsInContiguousSea();
330 if ((! bThisCellIsSea) && bNextCellIsSea)
333 if (!
m_pRasterGrid->m_Cell[nXThis][nYThis].bIsPossibleCoastStartCell())
336 m_pRasterGrid->m_Cell[nXThis][nYThis].SetPossibleCoastStartCell();
342 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXThis, nYThis));
343 VbPossibleStartCellLHEdge.push_back(
true);
345 VbTraced.push_back(
false);
349 else if (bThisCellIsSea && (! bNextCellIsSea))
352 if (!
m_pRasterGrid->m_Cell[nXNext][nYNext].bIsPossibleCoastStartCell())
355 m_pRasterGrid->m_Cell[nXNext][nYNext].SetPossibleCoastStartCell();
361 V2DIPossibleStartCell.push_back(
CGeom2DIPoint(nXNext, nYNext));
362 VbPossibleStartCellLHEdge.push_back(
false);
364 VbTraced.push_back(
false);
370 if (V2DIPossibleStartCell.size() == 0)
372 LogStream <<
m_ulIter <<
": no coastline start/finish points found after grid edges searched.";
385 LogStream <<
m_ulIter <<
": " << V2DIPossibleStartCell.size() <<
" possible coastline start/finish points found" << endl;
388 for (
unsigned int n = 0; n < V2DIPossibleStartCell.size(); n++)
394 if (VbPossibleStartCellLHEdge[n])
418 cerr <<
m_ulIter <<
": no valid coasts found, see " <<
m_strLogFile <<
" for more information" << endl;
426int CSimulation::nTraceCoastLine(
unsigned int const nTraceFromStartCellIndex,
int const nStartSearchDirection,
int const nHandedness, vector<bool>*pVbTraced, vector<CGeom2DIPoint>
const* pV2DIPossibleStartCell)
428 bool bHitStartCell =
false;
429 bool bAtCoast =
false;
430 bool bHasLeftStartEdge =
false;
431 bool bTooLong =
false;
432 bool bOffEdge =
false;
433 bool bRepeating =
false;
435 int nStartX = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetX();
436 int nStartY = pV2DIPossibleStartCell->at(nTraceFromStartCellIndex).nGetY();
439 int nSearchDirection = nStartSearchDirection;
449 m_pRasterGrid->m_Cell[nStartX][nStartY].SetAsCoastline(
true);
451 ILTempGridCRS.
Append(&PtiStart);
479 if ((nRoundLoop > 10) && (ILTempGridCRS.
nGetSize() < 2))
488 if (! bHasLeftStartEdge)
491 if (((nStartSearchDirection ==
SOUTH) && (nY > nStartY)) || ((nStartSearchDirection ==
NORTH) && (nY < nStartY)) ||
492 ((nStartSearchDirection ==
EAST) && (nX > nStartX)) || ((nStartSearchDirection ==
WEST) && (nX < nStartX)))
493 bHasLeftStartEdge =
true;
503 for (
unsigned int nn = 0; nn < pVbTraced->size(); nn++)
505 if ((nn != nTraceFromStartCellIndex) && (! pVbTraced->at(nn)))
509 if (bAtCoast && (nX == pV2DIPossibleStartCell->at(nn).nGetX()) && (nY == pV2DIPossibleStartCell->at(nn).nGetY()))
512 LogStream <<
m_ulIter <<
": Possible coastline found, traced from [" << nStartX <<
"][" << nStartY <<
"] and hit another coast start cell at [" << nX <<
"][" << nY <<
"]" << endl;
514 pVbTraced->at(nn) =
true;
515 bHitStartCell =
true;
530 int nSeawardNewDirection = 0;
531 int nXStraightOn = 0;
532 int nYStraightOn = 0;
533 int nXAntiSeaward = 0;
534 int nYAntiSeaward = 0;
535 int nAntiSeawardNewDirection = 0;
538 int nGoBackNewDirection = 0;
548 switch (nSearchDirection)
554 nSeawardNewDirection =
EAST;
558 nYStraightOn = nY - 1;
561 nXAntiSeaward = nX - 1;
563 nAntiSeawardNewDirection =
WEST;
568 nGoBackNewDirection =
SOUTH;
576 nSeawardNewDirection =
SOUTH;
579 nXStraightOn = nX + 1;
584 nYAntiSeaward = nY - 1;
585 nAntiSeawardNewDirection =
NORTH;
590 nGoBackNewDirection =
WEST;
598 nSeawardNewDirection =
WEST;
602 nYStraightOn = nY + 1;
605 nXAntiSeaward = nX + 1;
607 nAntiSeawardNewDirection =
EAST;
612 nGoBackNewDirection =
NORTH;
620 nSeawardNewDirection =
NORTH;
623 nXStraightOn = nX - 1;
628 nYAntiSeaward = nY + 1;
629 nAntiSeawardNewDirection =
SOUTH;
634 nGoBackNewDirection =
EAST;
644 switch (nSearchDirection)
650 nSeawardNewDirection =
WEST;
654 nYStraightOn = nY - 1;
657 nXAntiSeaward = nX + 1;
659 nAntiSeawardNewDirection =
EAST;
664 nGoBackNewDirection =
SOUTH;
672 nSeawardNewDirection =
NORTH;
675 nXStraightOn = nX + 1;
680 nYAntiSeaward = nY + 1;
681 nAntiSeawardNewDirection =
SOUTH;
686 nGoBackNewDirection =
WEST;
694 nSeawardNewDirection =
EAST;
698 nYStraightOn = nY + 1;
701 nXAntiSeaward = nX - 1;
703 nAntiSeawardNewDirection =
WEST;
708 nGoBackNewDirection =
NORTH;
716 nSeawardNewDirection =
SOUTH;
719 nXStraightOn = nX - 1;
724 nYAntiSeaward = nY - 1;
725 nAntiSeawardNewDirection =
NORTH;
730 nGoBackNewDirection =
EAST;
742 if (
m_pRasterGrid->m_Cell[nXSeaward][nYSeaward].bIsInContiguousSea())
755 ILTempGridCRS.
Append(&Pti);
762 ILTempGridCRS.
Append(&Pti);
774 nSearchDirection = nSeawardNewDirection;
783 if (
m_pRasterGrid->m_Cell[nXStraightOn][nYStraightOn].bIsInContiguousSea())
796 ILTempGridCRS.
Append(&Pti);
803 ILTempGridCRS.
Append(&Pti);
823 if (
m_pRasterGrid->m_Cell[nXAntiSeaward][nYAntiSeaward].bIsInContiguousSea())
836 ILTempGridCRS.
Append(&Pti);
843 ILTempGridCRS.
Append(&Pti);
855 nSearchDirection = nAntiSeawardNewDirection;
867 nSearchDirection = nGoBackNewDirection;
879 int nCoastSize = ILTempGridCRS.
nGetSize();
887 for (
int n = 0; n < nCoastSize; n++)
888 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsCoastline(
false);
901 LogStream <<
", it ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
907 for (
int n = 0; n < nCoastSize; n++)
908 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsCoastline(
false);
920 LogStream <<
", it ended at [" << ILTempGridCRS[nCoastSize - 1].nGetX() <<
"][" << ILTempGridCRS[nCoastSize - 1].nGetY() <<
"] = {" <<
dGridCentroidXToExtCRSX(ILTempGridCRS[nCoastSize - 1].nGetX()) <<
", " <<
dGridCentroidYToExtCRSY(ILTempGridCRS[nCoastSize - 1].nGetY()) <<
"}";
926 for (
int n = 0; n < nCoastSize; n++)
927 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsCoastline(
false);
948 for (
int n = 0; n < nCoastSize; n++)
949 m_pRasterGrid->m_Cell[ILTempGridCRS[n].nGetX()][ILTempGridCRS[n].nGetY()].SetAsCoastline(
false);
957 int nCoastEndX = ILTempGridCRS[nCoastSize - 1].nGetX();
958 int nCoastEndY = ILTempGridCRS[nCoastSize - 1].nGetY();
960 if ((nCoastEndX != nEndX) || (nCoastEndY != nEndY))
963 if (!
m_pRasterGrid->m_Cell[nCoastEndX][nCoastEndY].bIsBoundingBoxEdge())
966 ILTempGridCRS.
Append(nEndX, nEndY);
974 int nStartEdge =
m_pRasterGrid->m_Cell[nStartX][nStartY].nGetBoundingBoxEdge();
975 int nEndEdge =
m_pRasterGrid->m_Cell[nEndX][nEndY].nGetBoundingBoxEdge();
980 for (
int j = 0; j < nCoastSize; j++)
1004 int nCoast =
static_cast<int>(
m_VCoast.size()) - 1;
1007 m_VCoast[nCoast].SetCoastlineExtCRS(<empExtCRS);
1010 m_VCoast[nCoast].SetCoastlineGridCRS(&ILTempGridCRS);
1028 m_VCoast[nCoast].SetSeaHandedness(nHandedness);
1029 m_VCoast[nCoast].SetStartEdge(nStartEdge);
1030 m_VCoast[nCoast].SetEndEdge(nEndEdge);
1036 LogStream <<
m_ulIter <<
": Smoothed coastline " << nCoast <<
" runs from {" << LTempExtCRS[0].dGetX() <<
", " << LTempExtCRS[0].dGetY() <<
"} to {" << LTempExtCRS[nCoastSize - 1].dGetX() <<
", " << LTempExtCRS[nCoastSize - 1].dGetY() <<
"} i.e. from the ";
1038 if (nStartEdge ==
NORTH)
1041 else if (nStartEdge ==
SOUTH)
1044 else if (nStartEdge ==
WEST)
1047 else if (nStartEdge ==
EAST)
1052 if (nEndEdge ==
NORTH)
1055 else if (nEndEdge ==
SOUTH)
1058 else if (nEndEdge ==
WEST)
1061 else if (nEndEdge ==
EAST)
1079 m_VCoast[nCoast].CreateProfilesAtCoastPoints();
1143 for (
unsigned int n = 0; n <
m_VEdgeCell.size(); n++)
int nGetSize(void) const
Returns the number of integer point in the vector which represents this 2D shape.
void Append(CGeom2DIPoint const *)
Appends a new integer point to the vector which represents this 2D shape.
void Append(CGeom2DPoint const *)
Appends a point to this 2D shape.
Geometry class used to represent 2D point objects with integer coordinates.
int nGetY(void) const
Returns the CGeom2DIPoint object's integer Y coordinate.
int nGetX(void) const
Returns the CGeom2DIPoint object's integer X coordinate.
Geometry class used to represent 2D vector integer line objects.
Geometry class used to represent 2D vector line objects.
Real-world class used to represent coastline objects.
int m_nYMinBoundingBox
The minimum y value of the bounding box.
void FindAllSeaCells(void)
Finds and flags all sea areas which have at least one cell at a grid edge (i.e. does not flag 'inland...
CGeomLine LSmoothCoastRunningMean(CGeomLine *) const
Does running-mean smoothing of a CGeomLine coastline vector (is in external CRS coordinates)
int nLocateSeaAndCoasts(int &)
First find all connected sea areas, then locate the vector coastline(s), then put these onto the rast...
CGeomRasterGrid * m_pRasterGrid
Pointer to the raster grid object.
int m_nXGridSize
The size of the grid in the x direction.
static int nGetOppositeDirection(int const)
Returns the opposite direction.
vector< CRWCoast > m_VFloodWaveSetupSurgeRunup
TODO 007 Info needed.
vector< CRWCoast > m_VCoast
The coastline objects.
int nLocateFloodAndCoasts(void)
First find all connected sea areas, then locate the vector coastline(s), then put these onto the rast...
int nTraceCoastLine(unsigned int const, int const, int const, vector< bool > *, vector< CGeom2DIPoint > const *)
Traces a coastline (which is defined to be just above still water level) on the grid using the 'wall ...
int nTraceAllFloodCoasts(void)
Locates all the potential coastline start points on the edges of the raster grid, then traces vector ...
void FloodFillLand(int const, int const)
Use the sealevel, wave set-up and run-up to evaluate flood hydraulically connected TODO 007 Not clear...
int m_nYGridSize
The size of the grid in the y direction.
double m_dThisIterTopElevMin
This-iteration lowest elevation of DEM.
double m_dGeoTransform[6]
double m_dMissingValue
Used by CoastalME for floating-point missing values.
void CalcCoastTangents(int const)
Calculates tangents to a coastline: the tangent is assumed to be the orientation of energy/sediment f...
vector< CRWCoast > m_VFloodWaveSetupSurge
TODO 007 Info needed.
int m_nXMaxBoundingBox
The maximum x value of the bounding box.
string m_strLogFile
Name of output log file.
bool m_bOmitSearchWestEdge
Omit the west edge of the grid from coast-end searches?
double dGridCentroidYToExtCRSY(int const) const
Given the integer Y-axis ordinate of a cell in the raster grid CRS, returns the external CRS Y-axis o...
bool m_bOmitSearchNorthEdge
Omit the north edge of the grid from coast-end searches?
vector< CGeom2DIPoint > m_VEdgeCell
Edge cells.
string m_strOutPath
Path for all output files.
int m_nYMaxBoundingBox
The maximum y value of the bounding box.
unsigned long m_ulThisIterNumSeaCells
The number of grid cells which are marked as sea, for this iteration.
CGeomLine LSmoothCoastSavitzkyGolay(CGeomLine *, int const, int const) const
Does smoothing of a CGeomLine coastline vector (is in external CRS coordinates) using a Savitzky-Gola...
int m_nXMinBoundingBox
The minimum x value of the bounding box.
bool bIsWithinValidGrid(int const, int const) const
Checks whether the supplied point (an x-y pair, in the grid CRS) is within the raster grid,...
int m_nCoastSmooth
Which method to use for coast smoothing.
void DoCoastCurvature(int const, int const)
Calculates both detailed and smoothed curvature for every point on a coastline.
bool m_bOmitSearchSouthEdge
Omit the south edge of the grid from coast-end searches?
string m_strGDALBasementDEMProjection
GDAL projection string for the basement DEM raster file.
unsigned long m_ulIter
The number of the current iteration (time step)
double dGridCentroidXToExtCRSX(int const) const
Given the integer X-axis ordinate of a cell in the raster grid CRS, returns the external CRS X-axis o...
int nTraceAllCoasts(int &)
Locates all the potential coastline start/finish points on the edges of the raster grid,...
void CellByCellFillSea(int const, int const)
Cell-by-cell fills all sea cells starting from a given cell. The cell-by-cell fill (aka 'floodfill') ...
bool bIsInterventionCell(int const, int const) const
Returns true if the cell is an intervention.
double m_dThisIterTopElevMax
This-iteration highest elevation of DEM.
int FindAllInundatedCells(void)
Finds and flags all sea areas which have at least one cell at a grid edge (i.e. does not flag 'inland...
char ** m_papszGDALRasterOptions
Options for GDAL when handling raster files.
int m_nLevel
TODO 007 Used in WAVESETUP + SURGE + RUNUP.
bool m_bOmitSearchEastEdge
Omit the east edge of the grid from coast-end searches?
vector< int > m_VEdgeCellEdge
The grid edge that each edge cell belongs to.
This file contains global definitions for CoastalME.
int const RTN_ERR_NOCOAST
int const LF_CAT_SEDIMENT_INPUT
int const LF_CAT_SEDIMENT_INPUT_SUBMERGED
int const LOG_FILE_MIDDLE_DETAIL
bool bFPIsEqual(const T d1, const T d2, const T dEpsilon)
int const LOG_FILE_HIGH_DETAIL
int const SMOOTH_SAVITZKY_GOLAY
int const SMOOTH_RUNNING_MEAN
int const LF_CAT_SEDIMENT_INPUT_NOT_SUBMERGED
int const RTN_ERR_TRACING_COAST
Contains CRWCoast definitions.
Contains CGeomILine definitions.
Contains CGeomLine definitions.
Contains CGeomRasterGrid definitions.
Contains CSimulation definitions.