Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs-feliks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Feliks Kiszkurno
ogs-feliks
Commits
8f63182c
Commit
8f63182c
authored
7 months ago
by
Karsten Rink
Committed by
Dmitri Naumov
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
xyz file is only read once and values are stored in memory
asdf
parent
726735c6
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
+36
-20
36 additions, 20 deletions
GeoLib/IO/AsciiRasterInterface.cpp
with
36 additions
and
20 deletions
GeoLib/IO/AsciiRasterInterface.cpp
+
36
−
20
View file @
8f63182c
...
@@ -244,23 +244,30 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(
...
@@ -244,23 +244,30 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(
return
new
GeoLib
::
Raster
(
header
,
values
.
begin
(),
values
.
end
());
return
new
GeoLib
::
Raster
(
header
,
values
.
begin
(),
values
.
end
());
}
}
std
::
optional
<
std
::
array
<
double
,
3
>>
readCoordinates
(
std
::
istream
&
in
)
std
::
vector
<
std
::
string
>
readFile
(
std
::
istream
&
in
)
{
{
std
::
vector
<
std
::
string
>
lines
;
std
::
string
line
(
""
);
std
::
string
line
(
""
);
if
(
std
::
getline
(
in
,
line
))
while
(
std
::
getline
(
in
,
line
))
{
{
std
::
array
<
double
,
3
>
coords
;
lines
.
emplace_back
(
line
);
if
(
std
::
sscanf
(
line
.
c_str
(),
"%lf %lf %lf"
,
&
coords
[
0
],
&
coords
[
1
],
}
&
coords
[
2
])
==
3
)
return
lines
;
{
}
return
coords
;
}
std
::
optional
<
std
::
array
<
double
,
3
>>
readCoordinates
(
std
::
string
const
&
line
)
else
{
{
std
::
array
<
double
,
3
>
coords
;
OGS_FATAL
(
"Could not parse coordinates in readCoordinates()."
);
if
(
std
::
sscanf
(
line
.
c_str
(),
"%lf %lf %lf"
,
&
coords
[
0
],
&
coords
[
1
],
}
&
coords
[
2
])
==
3
)
{
return
coords
;
}
else
{
ERR
(
"Raster::getRasterFromXyzFile() - Unexpected file format:
\n
{:s}, line"
);
return
std
::
nullopt
;
}
}
return
std
::
nullopt
;
}
}
GeoLib
::
Raster
*
AsciiRasterInterface
::
getRasterFromXyzFile
(
GeoLib
::
Raster
*
AsciiRasterInterface
::
getRasterFromXyzFile
(
...
@@ -273,7 +280,10 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromXyzFile(
...
@@ -273,7 +280,10 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromXyzFile(
return
nullptr
;
return
nullptr
;
}
}
auto
coords
=
readCoordinates
(
in
);
auto
const
string_lines
=
readFile
(
in
);
in
.
close
();
auto
coords
=
readCoordinates
(
string_lines
[
0
]);
if
(
coords
==
std
::
nullopt
)
if
(
coords
==
std
::
nullopt
)
{
{
return
nullptr
;
return
nullptr
;
...
@@ -284,17 +294,24 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromXyzFile(
...
@@ -284,17 +294,24 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromXyzFile(
double
y_max
=
(
*
coords
)[
1
];
double
y_max
=
(
*
coords
)[
1
];
double
cellsize
=
std
::
numeric_limits
<
double
>::
max
();
double
cellsize
=
std
::
numeric_limits
<
double
>::
max
();
while
((
coords
=
readCoordinates
(
in
)))
std
::
size_t
const
n_lines
(
string_lines
.
size
());
for
(
std
::
size_t
i
=
1
;
i
<
n_lines
;
++
i
)
{
{
coords
=
readCoordinates
(
string_lines
[
i
]);
if
(
coords
==
std
::
nullopt
)
{
return
nullptr
;
}
double
const
diff
=
(
*
coords
)[
0
]
-
x_min
;
double
const
diff
=
(
*
coords
)[
0
]
-
x_min
;
if
(
diff
>
0
)
if
(
diff
>
0
)
{
cellsize
=
std
::
min
(
cellsize
,
diff
);
cellsize
=
std
::
min
(
cellsize
,
diff
);
}
x_min
=
std
::
min
((
*
coords
)[
0
],
x_min
);
x_min
=
std
::
min
((
*
coords
)[
0
],
x_min
);
x_max
=
std
::
max
((
*
coords
)[
0
],
x_max
);
x_max
=
std
::
max
((
*
coords
)[
0
],
x_max
);
y_min
=
std
::
min
((
*
coords
)[
1
],
y_min
);
y_min
=
std
::
min
((
*
coords
)[
1
],
y_min
);
y_max
=
std
::
max
((
*
coords
)[
1
],
y_max
);
y_max
=
std
::
max
((
*
coords
)[
1
],
y_max
);
}
}
in
.
close
();
GeoLib
::
RasterHeader
header
;
GeoLib
::
RasterHeader
header
;
header
.
cell_size
=
cellsize
;
header
.
cell_size
=
cellsize
;
...
@@ -306,15 +323,14 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromXyzFile(
...
@@ -306,15 +323,14 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromXyzFile(
header
.
origin
[
1
]
=
y_min
;
header
.
origin
[
1
]
=
y_min
;
std
::
vector
<
double
>
values
(
header
.
n_cols
*
header
.
n_rows
,
-
9999
);
std
::
vector
<
double
>
values
(
header
.
n_cols
*
header
.
n_rows
,
-
9999
);
in
.
open
(
fname
);
for
(
std
::
size_t
i
=
0
;
i
<
n_lines
;
++
i
)
while
((
coords
=
readCoordinates
(
in
)))
{
{
std
::
size_t
idx
=
static_cast
<
std
::
size_t
>
(
coords
=
readCoordinates
(
string_lines
[
i
]);
std
::
size_t
const
idx
=
static_cast
<
std
::
size_t
>
(
(
header
.
n_cols
*
(((
*
coords
)[
1
]
-
y_min
)
/
cellsize
))
+
(
header
.
n_cols
*
(((
*
coords
)[
1
]
-
y_min
)
/
cellsize
))
+
(((
*
coords
)[
0
]
-
x_min
)
/
cellsize
));
(((
*
coords
)[
0
]
-
x_min
)
/
cellsize
));
values
[
idx
]
=
(
*
coords
)[
2
];
values
[
idx
]
=
(
*
coords
)[
2
];
}
}
in
.
close
();
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