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
wenqing
ogs
Commits
c04b0b7e
Commit
c04b0b7e
authored
3 years ago
by
Dmitri Naumov
Browse files
Options
Downloads
Patches
Plain Diff
[App/IO] Surfer raster header returns an optional.
parent
b94ce776
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/FileIO/AsciiRasterInterface.cpp
+10
-14
10 additions, 14 deletions
Applications/FileIO/AsciiRasterInterface.cpp
Applications/FileIO/AsciiRasterInterface.h
+5
-3
5 additions, 3 deletions
Applications/FileIO/AsciiRasterInterface.h
with
15 additions
and
17 deletions
Applications/FileIO/AsciiRasterInterface.cpp
+
10
−
14
View file @
c04b0b7e
...
...
@@ -168,13 +168,9 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(
return
nullptr
;
}
// header information
GeoLib
::
RasterHeader
header
;
double
min
(
0.0
);
double
max
(
0.0
);
if
(
readSurferHeader
(
in
,
header
,
min
,
max
))
if
(
auto
const
optional_header
=
readSurferHeader
(
in
))
{
auto
const
[
header
,
min
,
max
]
=
*
optional_header
;
const
double
no_data_val
(
min
-
1
);
std
::
vector
<
double
>
values
(
header
.
n_cols
*
header
.
n_rows
);
std
::
string
s
;
...
...
@@ -191,17 +187,15 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(
}
}
in
.
close
();
return
new
GeoLib
::
Raster
(
std
::
move
(
header
),
values
.
begin
(),
values
.
end
());
return
new
GeoLib
::
Raster
(
header
,
values
.
begin
(),
values
.
end
());
}
ERR
(
"Raster::getRasterFromASCFile() - could not read header of file {:s}"
,
fname
);
return
nullptr
;
}
bool
AsciiRasterInterface
::
readSurferHeader
(
std
::
ifstream
&
in
,
GeoLib
::
RasterHeader
&
header
,
double
&
min
,
double
&
max
)
std
::
optional
<
std
::
tuple
<
GeoLib
::
RasterHeader
,
double
,
double
>>
AsciiRasterInterface
::
readSurferHeader
(
std
::
ifstream
&
in
)
{
std
::
string
tag
;
...
...
@@ -210,10 +204,12 @@ bool AsciiRasterInterface::readSurferHeader(std::ifstream& in,
if
(
tag
!=
"DSAA"
)
{
ERR
(
"Error in readSurferHeader() - No Surfer file."
);
return
false
;
return
{}
;
}
GeoLib
::
RasterHeader
header
;
in
>>
header
.
n_cols
>>
header
.
n_rows
;
double
min
,
max
;
in
>>
min
>>
max
;
header
.
origin
[
0
]
=
min
;
header
.
cell_size
=
(
max
-
min
)
/
static_cast
<
double
>
(
header
.
n_cols
);
...
...
@@ -230,13 +226,13 @@ bool AsciiRasterInterface::readSurferHeader(std::ifstream& in,
else
{
ERR
(
"Error in readSurferHeader() - Anisotropic cellsize detected."
);
return
false
;
return
{}
;
}
header
.
n_depth
=
1
;
header
.
no_data
=
min
-
1
;
in
>>
min
>>
max
;
return
true
;
return
{{
header
,
min
,
max
}}
;
}
void
AsciiRasterInterface
::
writeRasterAsASC
(
GeoLib
::
Raster
const
&
raster
,
...
...
This diff is collapsed.
Click to expand it.
Applications/FileIO/AsciiRasterInterface.h
+
5
−
3
View file @
c04b0b7e
...
...
@@ -16,6 +16,7 @@
#include
<fstream>
#include
<optional>
#include
<string>
#include
<tuple>
#include
<vector>
#include
"GeoLib/Raster.h"
...
...
@@ -47,9 +48,10 @@ private:
/// If the return value is empty, reading was not successful.
static
std
::
optional
<
GeoLib
::
RasterHeader
>
readASCHeader
(
std
::
ifstream
&
in
);
/// Reads the header of a Surfer grd-file.
static
bool
readSurferHeader
(
std
::
ifstream
&
in
,
GeoLib
::
RasterHeader
&
header
,
double
&
min
,
double
&
max
);
/// Reads the header of a Surfer grd-file with minimum and maximum values.
/// If the return value is empty, reading was not successful.
static
std
::
optional
<
std
::
tuple
<
GeoLib
::
RasterHeader
,
double
,
double
>>
readSurferHeader
(
std
::
ifstream
&
in
);
};
/// Reads a vector of rasters given by file names. On error nothing is returned,
...
...
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