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
Özgür Ozan Sen
ogs
Commits
6ed2a35b
Commit
6ed2a35b
authored
7 months ago
by
Karsten Rink
Committed by
Dmitri Naumov
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
moved xyz header construction into separate method
asdf
parent
8f63182c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GeoLib/IO/AsciiRasterInterface.cpp
+38
-27
38 additions, 27 deletions
GeoLib/IO/AsciiRasterInterface.cpp
with
38 additions
and
27 deletions
GeoLib/IO/AsciiRasterInterface.cpp
+
38
−
27
View file @
6ed2a35b
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include
"BaseLib/FileTools.h"
#include
"BaseLib/FileTools.h"
#include
"BaseLib/Logging.h"
#include
"BaseLib/Logging.h"
#include
"BaseLib/StringTools.h"
#include
"BaseLib/StringTools.h"
#include
"MathLib/Point3d.h"
#include
"GeoLib/Point.h"
#include
"GeoLib/Point.h"
namespace
FileIO
namespace
FileIO
...
@@ -270,37 +271,24 @@ std::optional<std::array<double, 3>> readCoordinates(std::string const& line)
...
@@ -270,37 +271,24 @@ std::optional<std::array<double, 3>> readCoordinates(std::string const& line)
}
}
}
}
GeoLib
::
Raster
*
AsciiRasterInterface
::
getRasterFromXyzFile
(
GeoLib
::
RasterHeader
getXyzHeader
(
std
::
vector
<
std
::
string
>
lines
)
std
::
string
const
&
fname
)
{
{
std
::
ifstream
in
(
fname
.
c_str
());
double
x_min
=
std
::
numeric_limits
<
double
>::
max
();
if
(
!
in
.
is_open
())
double
x_max
=
-
std
::
numeric_limits
<
double
>::
max
();
{
double
y_min
=
std
::
numeric_limits
<
double
>::
max
();
ERR
(
"Raster::getRasterFromXyzFile() - Could not open file {:s}"
,
fname
);
double
y_max
=
-
std
::
numeric_limits
<
double
>::
max
();
return
nullptr
;
}
auto
const
string_lines
=
readFile
(
in
);
in
.
close
();
auto
coords
=
readCoordinates
(
string_lines
[
0
]);
if
(
coords
==
std
::
nullopt
)
{
return
nullptr
;
}
double
x_min
=
(
*
coords
)[
0
];
double
x_max
=
(
*
coords
)[
0
];
double
y_min
=
(
*
coords
)[
1
];
double
y_max
=
(
*
coords
)[
1
];
double
cellsize
=
std
::
numeric_limits
<
double
>::
max
();
double
cellsize
=
std
::
numeric_limits
<
double
>::
max
();
std
::
optional
<
std
::
array
<
double
,
3
>>
coords
;
std
::
size_t
const
n_lines
(
string_
lines
.
size
());
std
::
size_t
const
n_lines
(
lines
.
size
());
for
(
std
::
size_t
i
=
1
;
i
<
n_lines
;
++
i
)
for
(
std
::
size_t
i
=
0
;
i
<
n_lines
;
++
i
)
{
{
coords
=
readCoordinates
(
string_
lines
[
i
]);
coords
=
readCoordinates
(
lines
[
i
]);
if
(
coords
==
std
::
nullopt
)
if
(
coords
==
std
::
nullopt
)
{
{
return
nullptr
;
MathLib
::
Point3d
org
(
std
::
array
<
double
,
3
>
{{
0
,
0
,
0
}});
GeoLib
::
RasterHeader
fail
=
{
0
,
0
,
0
,
org
,
0
,
0
};
return
fail
;
}
}
double
const
diff
=
(
*
coords
)[
0
]
-
x_min
;
double
const
diff
=
(
*
coords
)[
0
]
-
x_min
;
if
(
diff
>
0
)
if
(
diff
>
0
)
...
@@ -321,14 +309,37 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromXyzFile(
...
@@ -321,14 +309,37 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromXyzFile(
header
.
n_depth
=
1
;
header
.
n_depth
=
1
;
header
.
origin
[
0
]
=
x_min
;
header
.
origin
[
0
]
=
x_min
;
header
.
origin
[
1
]
=
y_min
;
header
.
origin
[
1
]
=
y_min
;
return
header
;
}
GeoLib
::
Raster
*
AsciiRasterInterface
::
getRasterFromXyzFile
(
std
::
string
const
&
fname
)
{
std
::
ifstream
in
(
fname
.
c_str
());
if
(
!
in
.
is_open
())
{
ERR
(
"Raster::getRasterFromXyzFile() - Could not open file {:s}"
,
fname
);
return
nullptr
;
}
auto
const
string_lines
=
readFile
(
in
);
in
.
close
();
auto
const
header
=
getXyzHeader
(
string_lines
);
if
(
header
.
n_cols
==
0
&&
header
.
n_rows
==
0
)
{
return
nullptr
;
}
std
::
optional
<
std
::
array
<
double
,
3
>>
coords
;
std
::
vector
<
double
>
values
(
header
.
n_cols
*
header
.
n_rows
,
-
9999
);
std
::
vector
<
double
>
values
(
header
.
n_cols
*
header
.
n_rows
,
-
9999
);
std
::
size_t
const
n_lines
(
string_lines
.
size
());
for
(
std
::
size_t
i
=
0
;
i
<
n_lines
;
++
i
)
for
(
std
::
size_t
i
=
0
;
i
<
n_lines
;
++
i
)
{
{
coords
=
readCoordinates
(
string_lines
[
i
]);
coords
=
readCoordinates
(
string_lines
[
i
]);
std
::
size_t
const
idx
=
static_cast
<
std
::
size_t
>
(
std
::
size_t
const
idx
=
static_cast
<
std
::
size_t
>
(
(
header
.
n_cols
*
(((
*
coords
)[
1
]
-
y_min
)
/
cellsize
))
+
(
header
.
n_cols
*
(((
*
coords
)[
1
]
-
header
.
origin
[
1
])
/
header
.
cell
_
size
))
+
(((
*
coords
)[
0
]
-
x_min
)
/
cellsize
));
(((
*
coords
)[
0
]
-
header
.
origin
[
0
])
/
header
.
cell
_
size
));
values
[
idx
]
=
(
*
coords
)[
2
];
values
[
idx
]
=
(
*
coords
)[
2
];
}
}
return
new
GeoLib
::
Raster
(
header
,
values
.
begin
(),
values
.
end
());
return
new
GeoLib
::
Raster
(
header
,
values
.
begin
(),
values
.
end
());
...
...
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