Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.out.ascii: Create an option to write a LISFLOOD compatible header #4695

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions raster/r.out.ascii/formspecific.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,25 @@ int write_GSGRID(int fd, FILE *fp, int nrows, int ncols, int out_type, int dp,

return (0);
}

/* write the LISFLOOD ASCII heading */
int writeLISFLOODheader(FILE *fp, char *nodataval)
{
struct Cell_head region;
char buf[128];

G_get_window(&region);
fprintf(fp, "ncols\t\t%d\n", region.cols);
fprintf(fp, "nrows\t\t%d\n", region.rows);
G_format_easting(region.west, buf, region.proj);
fprintf(fp, "xllcorner\t%s\n", buf);
G_format_northing(region.south, buf, region.proj);
fprintf(fp, "yllcorner\t%s\n", buf);
fprintf(fp, "cellsize\t%.f\n", region.ew_res);

fprintf(fp, "NODATA_value\t%s\n", nodataval);

return 0;
}


Comment on lines +230 to +231
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format] reported by reviewdog 🐶

Suggested change

2 changes: 2 additions & 0 deletions raster/r.out.ascii/localproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ int write_MODFLOW(int, FILE *, int, int, int, int, int);

int writeGSheader(FILE *, const char *);
int write_GSGRID(int, FILE *, int, int, int, int, char *, int);

int writeLISFLOODheader(FILE *, char *);
21 changes: 20 additions & 1 deletion raster/r.out.ascii/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ int main(int argc, char *argv[])
struct Flag *noheader;
struct Flag *surfer;
struct Flag *modflow;
struct Flag *lisflood;
struct Flag *int_out;
} flag;

Expand All @@ -54,6 +55,9 @@ int main(int argc, char *argv[])
G_add_keyword(_("export"));
G_add_keyword(_("output"));
G_add_keyword("ASCII");
G_add_keyword("Surfer");
G_add_keyword("Modflow");
G_add_keyword("Lisflood");
module->description =
_("Converts a raster map layer into a GRASS ASCII text file.");

Expand Down Expand Up @@ -97,6 +101,10 @@ int main(int argc, char *argv[])
flag.modflow->key = 'm';
flag.modflow->description = _("Write MODFLOW (USGS) ASCII array");

flag.lisflood = G_define_flag();
flag.lisflood->key = 'l';
flag.lisflood->description = _("Write LISFLOOD (EU) ASCII array");

flag.int_out = G_define_flag();
flag.int_out->key = 'i';
flag.int_out->description = _("Force output of integer values");
Expand All @@ -123,7 +131,13 @@ int main(int argc, char *argv[])
G_fatal_error(_("Both -s and -h doesn't make sense"));

if (flag.surfer->answer && flag.modflow->answer)
G_fatal_error(_("Use -M or -s, not both"));
G_fatal_error(_("Use -m or -s, not both"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use G_option_exclusive instead


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format] reported by reviewdog 🐶

Suggested change

if (flag.surfer->answer && flag.lisflood->answer)
G_fatal_error(_("Use -l or -s, not both"));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format] reported by reviewdog 🐶

Suggested change

if (flag.lisflood->answer && flag.modflow->answer)
G_fatal_error(_("Use -m or -l, not both"));

name = parm.map->answer;

Expand Down Expand Up @@ -168,6 +182,11 @@ int main(int argc, char *argv[])
writeMFheader(fp, dp, width, out_type);
rc = write_MODFLOW(fd, fp, nrows, ncols, out_type, dp, width);
}
else if (flag.lisflood->answer) {
if (!flag.noheader->answer)
writeLISFLOODheader(fp, null_str);
rc = write_GRASS(fd, fp, nrows, ncols, out_type, dp, null_str);
}
else {
if (!flag.noheader->answer)
writeGRASSheader(fp);
Expand Down
18 changes: 18 additions & 0 deletions raster/r.out.ascii/r.out.ascii.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ <h2>DESCRIPTION</h2>
NULL data are coded to "1.70141e+038" for SURFER ASCII GRID files (ignoring
the <em>null=</em> parameter).

<p>To write a LISFLOOD .dem ASCII GRID file (with different header) use the
<em>-l</em> flag:

<div class="code"><pre>
r.out.ascii -l input=inname output=outname.dem
</pre></div>

NULL data output are set by the user at "-9999" in this case, see below:

<div class="code"><pre>
ncols 1514
nrows 2747
xllcorner 212236
yllcorner 2910116
cellsize 120
NODATA_value -9999
</pre></div>

<h2>NOTES</h2>

The output from <em>r.out.ascii</em> may be placed into a file by using the
Expand Down
Loading