Skip to content
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
79 changes: 56 additions & 23 deletions vector/v.in.pdal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,10 @@ int main(int argc, char *argv[])
Flag *reproject_flag = G_define_flag();
reproject_flag->key = 'w';
reproject_flag->label =
_("Reproject to projects's coordinate system if needed");
_("Reproject to project's coordinate system if needed [deprecated]");
reproject_flag->description =
_("Reprojects input dataset to the coordinate system of"
" the GRASS project (by default only datasets with the"
" matching coordinate system can be imported");
_("This flag is deprecated and will be removed in a future release. "
"Input dataset will always be reprojected if needed.");
reproject_flag->guisection = _("Projection");

Flag *over_flag = G_define_flag();
Expand Down Expand Up @@ -262,6 +261,12 @@ int main(int argc, char *argv[])
if (G_parser(argc, argv))
return EXIT_FAILURE;

if (reproject_flag->answer) {
G_warning(
_("Flag 'w' is deprecated and will be removed in a future release. "
"Input dataset will always be reprojected if needed."));
}

if (access(in_opt->answer, F_OK) != 0) {
G_fatal_error(_("Input file <%s> does not exist"), in_opt->answer);
}
Expand Down Expand Up @@ -341,13 +346,51 @@ int main(int argc, char *argv[])
in_opt->answer);
reader->setOptions(las_opts);

bool need_to_reproject = false;
if (over_flag->answer) {
G_important_message(_("Overriding projection check and assuming"
" that the CRS of input matches"
" the project's CRS"));
}
else {
// getting projection is possible only after prepare
pdal::PointTable table;
try {
reader->prepare(table);
}
catch (const std::exception &err) {
G_fatal_error(_("PDAL error while reading <%s>: %s"),
in_opt->answer, err.what());
}
pdal::SpatialReference spatial_reference =
reader->getSpatialReference();
// The CRS given by the user takes precedence over the file metadata,
// which may be missing or incorrect.
if (input_srs_opt->answer) {
try {
spatial_reference =
pdal::SpatialReference(input_srs_opt->answer);
}
catch (const std::exception &err) {
G_fatal_error(_("Invalid input_srs: %s"), err.what());
}
}
if (spatial_reference.empty())
G_fatal_error(_("The input dataset has undefined projection"));
std::string dataset_wkt = spatial_reference.getWKT();
need_to_reproject = !is_wkt_projection_same_as_loc(dataset_wkt.c_str());
}

Comment thread
saket0187 marked this conversation as resolved.
pdal::Stage *last_stage = reader;
pdal::ReprojectionFilter reprojection_filter;

// we reproject when requested regardless the input projection
if (reproject_flag->answer) {
G_message(_("Reprojecting the input to the project's CRS"));
if (need_to_reproject) {
char *proj_wkt = location_projection_as_wkt(false);
if (!proj_wkt)
G_fatal_error(_("Unable to reproject the input because the current"
" project has no CRS defined. Use the -o flag to"
" import the data without reprojection."));
G_message(_("Reprojecting the input to the project's CRS"));
pdal::Options o4;
// TODO: try catch for user input error
if (input_srs_opt->answer)
Expand All @@ -364,23 +407,13 @@ int main(int argc, char *argv[])
// consumption, so using 10k in case it is faster for some cases
pdal::point_count_t point_table_capacity = 10000;
pdal::FixedPointTable point_table(point_table_capacity);
stream_filter.prepare(point_table);

// getting projection is possible only after prepare
if (over_flag->answer) {
G_important_message(_("Overriding projection check and assuming"
" that the CRS of input matches"
" the project's CRS"));
// Errors from the reprojection filter surface here, and reprojection
// happens without the user asking for it, so they must not escape.
try {
stream_filter.prepare(point_table);
}
else if (!reproject_flag->answer) {
pdal::SpatialReference spatial_reference =
reader->getSpatialReference();
if (spatial_reference.empty())
G_fatal_error(_("The input dataset has undefined projection"));
std::string dataset_wkt = spatial_reference.getWKT();
bool proj_match = is_wkt_projection_same_as_loc(dataset_wkt.c_str());
if (!proj_match)
wkt_projection_mismatch_report(dataset_wkt.c_str());
catch (const std::exception &err) {
G_fatal_error(_("PDAL error: %s"), err.what());
}

G_important_message(_("Running PDAL algorithms..."));
Expand Down
22 changes: 18 additions & 4 deletions vector/v.in.pdal/v.in.pdal.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,27 @@ <h2>DESCRIPTION</h2>
<li>class filter</li>
</ul>

<h2>NOTES</h2>

The coordinate reference system (CRS) of the input is read from the file
metadata and compared with the CRS of the current project (previously called
location). When the two differ, the points are reprojected to the project's
CRS during the import. The <b>-w</b> flag, which used to be required to allow
the reprojection, is deprecated and has no effect.

<p>
The <b>-o</b> flag skips the CRS check and assumes that the input is already
in the project's CRS. Use it when the file has no CRS metadata or when the
metadata is known to be wrong; without it, the import of a file without CRS
metadata fails.

<h2>EXAMPLES</h2>

Import only XYZ coordinates of points, limit the import to the current
computational region and reproject to the current project's coordinate reference
system during the import:
Import only XYZ coordinates of points, limit the import to the
current computational region. The points are reprojected to the
project's CRS if the CRS of the input differs:
<div class="code"><pre>
v.in.pdal input=points.las output=points -c -r -w
v.in.pdal input=points.las output=points -c -r
</pre></div>

<h2>REFERENCES</h2>
Expand Down
21 changes: 17 additions & 4 deletions vector/v.in.pdal/v.in.pdal.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,27 @@ PDAL library. *v.in.pdal* supports the following filters:
- return filter
- class filter

## NOTES

The coordinate reference system (CRS) of the input is read from the file
metadata and compared with the CRS of the current project (previously
called location). When the two differ, the points are reprojected to the
project's CRS during the import. The **-w** flag, which used to be
required to allow the reprojection, is deprecated and has no effect.

The **-o** flag skips the CRS check and assumes that the input is
already in the project's CRS. Use it when the file has no CRS metadata
or when the metadata is known to be wrong; without it, the import of a
file without CRS metadata fails.

## EXAMPLES

Import only XYZ coordinates of points, limit the import to the current
computational region and reproject to the current project's coordinate
reference system during the import:
Import only XYZ coordinates of points, limit the import to the
current computational region. The points are reprojected to the
project's CRS if the CRS of the input differs:

```sh
v.in.pdal input=points.las output=points -c -r -w
v.in.pdal input=points.las output=points -c -r
```

## REFERENCES
Expand Down
Loading