Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
caddies
caddies-api
Commits
c63b0a80
Commit
c63b0a80
authored
May 20, 2020
by
mjg226
Browse files
further updates to gdal raster outputs, and bug fix the policy warning on cmake
parent
621e980d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
44 deletions
+83
-44
CMakeLists.txt
CMakeLists.txt
+3
-0
impls/square-cell/vn-neighbours/1-levels/simple/ESRI_ASCIIGrid.hpp
...are-cell/vn-neighbours/1-levels/simple/ESRI_ASCIIGrid.hpp
+80
-44
No files found.
CMakeLists.txt
View file @
c63b0a80
...
...
@@ -28,6 +28,9 @@ endif()
# Version of CMake that this project needs.
cmake_minimum_required
(
VERSION 2.8 FATAL_ERROR
)
cmake_policy
(
SET CMP0054 NEW
)
# A variable which controls the type of build generated
# Options are:
# Debug Release RelWithDebInfo MinSizeRel
...
...
impls/square-cell/vn-neighbours/1-levels/simple/ESRI_ASCIIGrid.hpp
View file @
c63b0a80
...
...
@@ -66,6 +66,9 @@ namespace CA {
static
std
::
string
driver
;
//static int epsgCode = 27700;
static
int
epsgCode
;
static
bool
createCapable
;
static
bool
createCopyCapable
;
#endif
...
...
@@ -296,46 +299,15 @@ namespace CA {
}
// end of readAsciiGridHeader
//! Write a ARC/INFO ASCII GRID format file
//template<typename T>
inline
void
writeAsciiGrid
(
const
std
::
string
&
filename
,
int
decimal_places
=
6
,
bool
print
=
false
)
void
writeAAIGrid
(
const
std
::
string
&
filename
,
int
decimal_places
=
6
,
bool
print
=
false
)
{
// Get starting time.
//Clock total_timer;
#ifndef CAAPI_GDAL_OPTION
#ifdef CA2D_MPI
//MPI_Comm_size(MPI_COMM_WORLD, &_commSize);
int
_rank
;
//MPI_Comm_size(MPI_COMM_WORLD, &_cagrid.comm_size);
//MPI_Comm_rank(MPI_COMM_WORLD, &_rank);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
_rank
);
std
::
stringstream
subGridIdStream
;
subGridIdStream
<<
_rank
;
// Add file extension
String
_filename
=
filename
+
"_"
+
subGridIdStream
.
str
()
+
".asc"
;
#else
// Add file extension
String
_filename
=
filename
+
".asc"
;
#endif // CA2D_MPI
// Open file
std
::
ofstream
onfile
(
_
filename
.
c_str
());
std
::
ofstream
onfile
(
filename
.
c_str
());
// Check if the file was open.
if
(
!
onfile
)
throw
std
::
runtime_error
(
std
::
string
(
"Error opening file: "
+
_
filename
));
throw
std
::
runtime_error
(
std
::
string
(
"Error opening file: "
+
filename
));
// Set manipulators
onfile
.
unsetf
(
std
::
ios
::
floatfield
);
...
...
@@ -359,9 +331,9 @@ namespace CA {
onfile
.
precision
(
decimal_places
);
// Loop through the data.
for
(
unsigned
int
i
=
0
;
i
<
AsciiGridGeneral
<
T
>::
ncols
*
AsciiGridGeneral
<
T
>::
nrows
;
++
i
)
for
(
unsigned
int
i
=
0
;
i
<
AsciiGridGeneral
<
T
>::
ncols
*
AsciiGridGeneral
<
T
>::
nrows
;
++
i
)
{
if
(
i
%
AsciiGridGeneral
<
T
>::
ncols
==
0
)
if
(
i
%
AsciiGridGeneral
<
T
>::
ncols
==
0
)
onfile
<<
"
\n
"
;
onfile
<<
AsciiGridGeneral
<
T
>::
data
[
i
]
<<
" "
;
}
...
...
@@ -371,22 +343,68 @@ namespace CA {
// Close the file.
onfile
.
close
();
}
//! Write a ARC/INFO ASCII GRID format file
//template<typename T>
inline
void
writeAsciiGrid
(
const
std
::
string
&
filename
,
int
decimal_places
=
6
,
bool
print
=
false
)
{
// Get starting time.
//Clock total_timer;
#ifndef CAAPI_GDAL_OPTION
#ifdef CA2D_MPI
//MPI_Comm_size(MPI_COMM_WORLD, &_commSize);
int
_rank
;
//MPI_Comm_size(MPI_COMM_WORLD, &_cagrid.comm_size);
//MPI_Comm_rank(MPI_COMM_WORLD, &_rank);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
_rank
);
std
::
stringstream
subGridIdStream
;
subGridIdStream
<<
_rank
;
// Add file extension
String
_filename
=
filename
+
"_"
+
subGridIdStream
.
str
()
+
".asc"
;
#else
// Add file extension
String
_filename
=
filename
+
".asc"
;
#endif // CA2D_MPI
writeAAIGrid
(
_filename
,
decimal_places
,
print
);
#else
GDALAllRegister
();
/*
if (filename.compare("AAIGrid") == 0) {
//GDALDataset* dataSet;
//dataSet = (GDALDataset*)GDALOpen(filename.c_str(), GDALAccess::GA_Update);
// Add file extension
String _filename = filename + ".asc";
writeAAIGrid(_filename, decimal_places, print);
return;
}*/
GDALDriver
*
poDriver
;
poDriver
=
GetGDALDriverManager
()
->
GetDriverByName
(
ESRI_ASCIIGrid
<
T
>::
driver
.
c_str
());
GDALAllRegister
();
GDALDriver
*
poDriver
;
std
::
string
extension
=
"."
;
extension
+=
poDriver
->
GetMetadataItem
(
GDAL_DMD_EXTENSION
);
if
(
ESRI_ASCIIGrid
<
T
>::
createCapable
==
false
&&
ESRI_ASCIIGrid
<
T
>::
createCopyCapable
)
{
poDriver
=
GetGDALDriverManager
()
->
GetDriverByName
(
"MEM"
);
}
else
{
poDriver
=
GetGDALDriverManager
()
->
GetDriverByName
(
ESRI_ASCIIGrid
<
T
>::
driver
.
c_str
());
extension
+=
poDriver
->
GetMetadataItem
(
GDAL_DMD_EXTENSION
);
}
...
...
@@ -457,6 +475,8 @@ namespace CA {
0
,
0
);
//GDAlClose((GDALDataSet)dataSet);
...
...
@@ -464,6 +484,18 @@ namespace CA {
dataSet
->
FlushCache
();
if
(
ESRI_ASCIIGrid
<
T
>::
createCapable
==
false
&&
ESRI_ASCIIGrid
<
T
>::
createCopyCapable
)
{
poDriver
=
GetGDALDriverManager
()
->
GetDriverByName
(
ESRI_ASCIIGrid
<
T
>::
driver
.
c_str
());
extension
+=
poDriver
->
GetMetadataItem
(
GDAL_DMD_EXTENSION
);
_filename
=
filename
+
extension
;
GDALCreateCopy
(
poDriver
,
_filename
.
c_str
(),
dataSet
,
false
,
NULL
,
NULL
,
NULL
);
}
//delete(poBand);
delete
(
dataSet
);
//delete(poDriver);
...
...
@@ -1202,6 +1234,10 @@ namespace CA {
std
::
string
CA
::
ESRI_ASCIIGrid
<
T
>::
driver
=
"AAIGrid"
;
template
<
typename
T
>
int
CA
::
ESRI_ASCIIGrid
<
T
>::
epsgCode
=
27700
;
template
<
typename
T
>
bool
CA
::
ESRI_ASCIIGrid
<
T
>::
createCapable
=
false
;
template
<
typename
T
>
bool
CA
::
ESRI_ASCIIGrid
<
T
>::
createCopyCapable
=
true
;
#endif
}
// end of namespace
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment