From 4007757297cad12b1a530e32a31f592ff32d186d Mon Sep 17 00:00:00 2001 From: saket0187 Date: Thu, 27 Aug 2026 17:29:36 +0530 Subject: [PATCH 1/3] deprecate -w flag --- vector/v.in.pdal/main.cpp | 68 +++++++++++++++++++++++------------ vector/v.in.pdal/v.in.pdal.md | 21 ++++++++--- 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/vector/v.in.pdal/main.cpp b/vector/v.in.pdal/main.cpp index 6886328b6d4..9c697cd41c9 100644 --- a/vector/v.in.pdal/main.cpp +++ b/vector/v.in.pdal/main.cpp @@ -213,11 +213,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(); @@ -265,6 +264,12 @@ int main(int argc, char *argv[]) if (G_parser(argc, argv)) return EXIT_FAILURE; + if (reproject_flag->answer) { + G_verbose_message( + _("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); } @@ -344,13 +349,40 @@ 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(); + 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()); + } + 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) @@ -367,23 +399,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...")); diff --git a/vector/v.in.pdal/v.in.pdal.md b/vector/v.in.pdal/v.in.pdal.md index e85cb5ada00..95815d1f188 100644 --- a/vector/v.in.pdal/v.in.pdal.md +++ b/vector/v.in.pdal/v.in.pdal.md @@ -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 From 9766241de23c6583dbaa6c2f096fd12929b5c214 Mon Sep 17 00:00:00 2001 From: saket0187 Date: Sun, 6 Sep 2026 13:26:57 +0530 Subject: [PATCH 2/3] Add suggestions --- vector/v.in.pdal/main.cpp | 4 ++-- vector/v.in.pdal/v.in.pdal.html | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/vector/v.in.pdal/main.cpp b/vector/v.in.pdal/main.cpp index a9902a490ce..ef2e0fac57c 100644 --- a/vector/v.in.pdal/main.cpp +++ b/vector/v.in.pdal/main.cpp @@ -262,7 +262,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; if (reproject_flag->answer) { - G_verbose_message( + G_warning( _("Flag 'w' is deprecated and will be removed in a future release. " "Input dataset will always be reprojected if needed.")); } @@ -364,7 +364,7 @@ int main(int argc, char *argv[]) } pdal::SpatialReference spatial_reference = reader->getSpatialReference(); - if (spatial_reference.empty()) + if (spatial_reference.empty() && !input_srs_opt->answer) 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()); diff --git a/vector/v.in.pdal/v.in.pdal.html b/vector/v.in.pdal/v.in.pdal.html index d5832c93cff..798af4597b5 100644 --- a/vector/v.in.pdal/v.in.pdal.html +++ b/vector/v.in.pdal/v.in.pdal.html @@ -11,13 +11,27 @@

DESCRIPTION

  • 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:
    -v.in.pdal input=points.las output=points -c -r -w
    +v.in.pdal input=points.las output=points -c -r
     

    REFERENCES

    From 981fa5914608b76c6a6852283e3fb251d056c507 Mon Sep 17 00:00:00 2001 From: saket0187 Date: Wed, 23 Sep 2026 20:39:52 +0530 Subject: [PATCH 3/3] add changes --- vector/v.in.pdal/main.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/vector/v.in.pdal/main.cpp b/vector/v.in.pdal/main.cpp index ef2e0fac57c..f9cc6ff9660 100644 --- a/vector/v.in.pdal/main.cpp +++ b/vector/v.in.pdal/main.cpp @@ -364,7 +364,18 @@ int main(int argc, char *argv[]) } pdal::SpatialReference spatial_reference = reader->getSpatialReference(); - if (spatial_reference.empty() && !input_srs_opt->answer) + // 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());