Skip to content

Commit e8218db

Browse files
committed
Move station to shpfile logic into standalone function
1 parent a28ef50 commit e8218db

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/core.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,9 @@ void core::config_forcing(pt::ptree &value)
609609
}
610610

611611

612-
auto f = output_folder_path / "stations.vtp";
612+
auto f = output_folder_path / std::format("stations_{}.vtp", _comm_world.rank());
613613
_metdata->write_stations_to_ptv(f.string());
614+
_metdata->write_stations_to_shp((output_folder_path / std::format("stations_{}.shp",_comm_world.rank())).string());
614615

615616
SPDLOG_DEBUG("Finished reading stations. Took {} s", c.toc<s>());
616617

src/metdata.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void metdata::load_from_netcdf(const std::string& path, const triangulation::bou
241241

242242
SPDLOG_DEBUG("Initializing datastructure");
243243

244-
std::vector<std::tuple<float, float>> xy;
244+
245245
auto e = _nc->get_z();
246246

247247
// #pragma omp parallel for
@@ -321,12 +321,12 @@ void metdata::load_from_netcdf(const std::string& path, const triangulation::bou
321321

322322
_dD_tree.insert( boost::make_tuple(Kernel::Point_2(s->x(),s->y()),s) );
323323

324-
xy.emplace_back(longitude, latitude);
324+
325325
}
326326
}
327327
SPDLOG_DEBUG("Done initializing datastructure");
328-
gis::xy2shp(xy, "forcing_points.shp", _mesh_proj4);
329-
SPDLOG_DEBUG("This rank is using # grid cells = {}", xy.size());
328+
329+
SPDLOG_DEBUG("This rank is using # grid cells = {}", _stations.size());
330330
if( skipped == _nstations)
331331
{
332332
CHM_THROW_EXCEPTION(forcing_error,
@@ -825,4 +825,15 @@ std::vector< std::shared_ptr<station>>& metdata::stations()
825825
bool metdata::is_multipart_nc()
826826
{
827827
return _is_multipart_nc;
828+
}
829+
830+
void metdata::write_stations_to_shp(const std::string& fname)
831+
{
832+
std::vector<std::tuple<float, float>> xy;
833+
for(auto itr: _stations)
834+
{
835+
if(itr)
836+
xy.emplace_back(itr->x(), itr->y());
837+
}
838+
gis::xy2shp(xy, fname, _mesh_proj4);
828839
}

src/metdata.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ class metdata
182182
*/
183183
bool is_netcdf();
184184

185+
/**
186+
* Writes the lat and lon of the subsetted forcing poitns to shape file
187+
*/
188+
void write_stations_to_shp(const std::string& fname);
189+
190+
185191
/// Subsets all timeseries to begin at [start, end]. For ascii, the underlying timeseries is modified.
186192
/// For nc, internal offsets are computed to start, end.
187193
/// This updates the internal start and end times, as well as resets the current time to be = start

0 commit comments

Comments
 (0)