Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dmitri Naumov
ogs
Commits
f60a0147
Commit
f60a0147
authored
4 years ago
by
Karsten Rink
Browse files
Options
Downloads
Patches
Plain Diff
[utils] created cli to assign raster data as scalar arrays to mesh
parent
3e75ccc2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Applications/Utils/MeshGeoTools/AssignRasterDataToMesh.cpp
+133
-0
133 additions, 0 deletions
Applications/Utils/MeshGeoTools/AssignRasterDataToMesh.cpp
Applications/Utils/MeshGeoTools/CMakeLists.txt
+1
-0
1 addition, 0 deletions
Applications/Utils/MeshGeoTools/CMakeLists.txt
with
134 additions
and
0 deletions
Applications/Utils/MeshGeoTools/AssignRasterDataToMesh.cpp
0 → 100644
+
133
−
0
View file @
f60a0147
/**
* \file
* \copyright
* Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*/
#include
<memory>
#include
<string>
// ThirdParty
#include
<tclap/CmdLine.h>
#include
"InfoLib/GitInfo.h"
#include
"GeoLib/Raster.h"
#include
"MeshLib/Mesh.h"
#include
"MeshLib/IO/readMeshFromFile.h"
//#include "MeshLib/MeshEnums.h"
#include
"MeshLib/IO/VtkIO/VtuInterface.h"
#include
"MeshLib/MeshEditing/RasterDataToMesh.h"
#include
"Applications/FileIO/AsciiRasterInterface.h"
int
main
(
int
argc
,
char
*
argv
[])
{
TCLAP
::
CmdLine
cmd
(
"Assigns the pixel information of a raster file to a scalar array of a "
"specified 2D mesh. Data will be assigned to a node array by default. "
"Adding information to cell arrays is also possible, pixel values at "
"the centre of the cell will be used in this case. Note that large "
"differences in resolution between cell size of the mesh and pixel "
"size of the raster can give unexpected results. A no-data value will "
"be added in case of missing or transparent values.
\n\n
"
"OpenGeoSys-6 software, version "
+
GitInfoLib
::
GitInfo
::
ogs_version
+
".
\n
"
"Copyright (c) 2012-2020, OpenGeoSys Community "
"(http://www.opengeosys.org)"
,
' '
,
GitInfoLib
::
GitInfo
::
ogs_version
);
TCLAP
::
ValueArg
<
double
>
nodata_arg
(
"e"
,
"nodata"
,
"The no data value used for missing values"
,
false
,
0
,
"a number"
);
cmd
.
add
(
nodata_arg
);
TCLAP
::
SwitchArg
set_cells_arg
(
"c"
,
"cell-array"
,
"Assigns raster data to cell array"
);
cmd
.
add
(
set_cells_arg
);
TCLAP
::
SwitchArg
set_nodes_arg
(
"n"
,
"node-array"
,
"Assigns raster data to node array (default)"
);
cmd
.
add
(
set_nodes_arg
);
TCLAP
::
ValueArg
<
std
::
string
>
array_name_arg
(
"s"
,
"scalar"
,
"The name of the newly created scalar array."
,
true
,
""
,
"scalar array name"
);
cmd
.
add
(
array_name_arg
);
TCLAP
::
ValueArg
<
std
::
string
>
raster_arg
(
"r"
,
"raster"
,
"Name of the input raster (*.asc)"
,
true
,
""
,
"raster file name"
);
cmd
.
add
(
raster_arg
);
TCLAP
::
ValueArg
<
std
::
string
>
output_arg
(
"o"
,
"output"
,
"Name of the output mesh (*.vtu)"
,
true
,
""
,
"output file name"
);
cmd
.
add
(
output_arg
);
TCLAP
::
ValueArg
<
std
::
string
>
input_arg
(
"i"
,
"input"
,
"Name of the input mesh (*.vtu)"
,
true
,
""
,
"input file name"
);
cmd
.
add
(
input_arg
);
cmd
.
parse
(
argc
,
argv
);
bool
create_node_array
(
true
);
bool
create_cell_array
(
false
);
if
(
set_cells_arg
.
isSet
())
{
create_cell_array
=
true
;
create_node_array
=
false
;
}
if
(
set_nodes_arg
.
isSet
())
{
create_node_array
=
true
;
}
std
::
string
const
mesh_name
=
input_arg
.
getValue
().
c_str
();
std
::
string
const
output_name
=
output_arg
.
getValue
().
c_str
();
std
::
string
const
raster_name
=
raster_arg
.
getValue
().
c_str
();
std
::
unique_ptr
<
MeshLib
::
Mesh
>
mesh
(
MeshLib
::
IO
::
readMeshFromFile
(
mesh_name
));
if
(
mesh
->
getDimension
()
>
2
)
{
ERR
(
"Method can only be applied to 2D meshes."
);
return
EXIT_FAILURE
;
}
std
::
unique_ptr
<
GeoLib
::
Raster
>
const
raster
(
FileIO
::
AsciiRasterInterface
::
getRasterFromASCFile
(
raster_name
));
bool
assigned
(
false
);
if
(
create_node_array
)
{
assigned
=
MeshLib
::
RasterDataToMesh
::
projectToNodes
(
*
mesh
,
*
raster
,
nodata_arg
.
getValue
(),
array_name_arg
.
getValue
());
if
(
!
assigned
)
{
ERR
(
"Error assigning raster data to scalar node array"
);
return
EXIT_FAILURE
;
}
INFO
(
"Created node array {:s}"
,
array_name_arg
.
getValue
());
}
if
(
create_cell_array
)
{
assigned
=
MeshLib
::
RasterDataToMesh
::
projectToElements
(
*
mesh
,
*
raster
,
nodata_arg
.
getValue
(),
array_name_arg
.
getValue
());
if
(
!
assigned
)
{
ERR
(
"Error assigning raster data to scalar cell array"
);
return
EXIT_FAILURE
;
}
INFO
(
"Created cell array {:s}"
,
array_name_arg
.
getValue
());
}
MeshLib
::
IO
::
VtuInterface
vtu
(
mesh
.
get
());
vtu
.
writeToFile
(
output_name
);
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
Applications/Utils/MeshGeoTools/CMakeLists.txt
+
1
−
0
View file @
f60a0147
set
(
TOOLS
AssignRasterDataToMesh
computeSurfaceNodeIDsInPolygonalRegion
constructMeshesFromGeometry
createIntermediateRasters
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment