Skip to content

libproj: simple check for area of use#2519

Closed
metzm wants to merge 1 commit intoOSGeo:mainfrom
metzm:libproj_areaofuse
Closed

libproj: simple check for area of use#2519
metzm wants to merge 1 commit intoOSGeo:mainfrom
metzm:libproj_areaofuse

Conversation

@metzm
Copy link
Contributor

@metzm metzm commented Aug 10, 2022

This PR adds a simple check if reprojection would fall outside the intended area of use of the target CRS.

I would prefer to refuse reprojection in these extreme cases, but this might be too restrictive. If subsequent errors occur because reprojected coordinates are invalid, this can be changed accordingly to actually refuse reprojection which is the current behaviour, but without explanation why.

@metzm metzm added enhancement New feature or request C Related code is in C labels Aug 10, 2022
@metzm metzm added this to the 8.4.0 milestone Aug 10, 2022
@metzm metzm requested a review from neteler August 10, 2022 17:01
@wenzeslaus
Copy link
Member

I have resolved the indentation-related conflicts here.

@neteler
Copy link
Member

neteler commented Nov 9, 2022

A test:
I reprojected an Indonesian vector map into the NC sample dataset and do not yet see the warning being triggered:

GRASS nc_spm_08_grass7/user1:grass_main > v.proj location=utm49S_32749 mapset=hutan_mulya input=hutan_mulya_box
Found 2 possible transformations
************************
Operation 1:
Description: Inverse of UTM zone 49S + Inverse of NAD83(HARN) to WGS 84 (3)
+ SPCS83 North Carolina zone (meters)

Area of use: United States (USA) - CONUS onshore - Alabama; Arizona;
Arkansas; California; Colorado; Connecticut; Delaware; Florida; Georgia;
Idaho; Illinois; Indiana; Iowa; Kansas; Kentucky; Louisiana; Maine;
Maryland; Massachusetts; Michigan; Minnesota; Mississippi; Missouri;
Montana; Nebraska; Nevada; New Hampshire; New Jersey; New Mexico; New York;
North Carolina; North Dakota; Ohio; Oklahoma; Oregon; Pennsylvania; Rhode
Island; South Carolina; South Dakota; Tennessee; Texas; Utah; Vermont;
Virginia; Washington; West Virginia; Wisconsin; Wyoming.

Accuracy within area of use: 1 m

PROJ string:
+proj=pipeline +step +inv +proj=utm +zone=49 +south +ellps=WGS84 +step
+proj=push +v_3 +step +proj=cart +ellps=WGS84 +step +inv +proj=helmert
+x=-0.991 +y=1.9072 +z=0.5129 +rx=-0.0257899075194932
+ry=-0.0096500989602704 +rz=-0.0116599432323421 +s=0
+convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step
+proj=pop +v_3 +step +proj=lcc +lat_0=33.75 +lon_0=-79
+lat_1=36.1666666666667 +lat_2=34.3333333333333 +x_0=609601.22 +y_0=0
+ellps=GRS80
************************
Operation 2:
Description: Inverse of UTM zone 49S + Inverse of NAD83(HARN) to WGS 84 (1)
+ SPCS83 North Carolina zone (meters)

Area of use: American Samoa - onshore - Tutuila, Aunu'u, Ofu, Olesega, Ta'u
and Rose islands. Guam - onshore. Northern Mariana Islands - onshore.
Puerto Rico - onshore. United States (USA) - onshore Alabama, Alaska,
Arizona, Arkansas, California, Colorado, Connecticut, Delaware, Florida,
Georgia, Hawaii, Idaho, Illinois, Indiana, Iowa, Kansas, Kentucky,
Louisiana, Maine, Maryland, Massachusetts, Michigan, Minnesota,
Mississippi, Missouri, Montana, Nebraska, Nevada, New Hampshire, New
Jersey, New Mexico, New York, North Carolina, North Dakota, Ohio, Oklahoma,
Oregon, Pennsylvania, Rhode Island, South Carolina, South Dakota,
Tennessee, Texas, Utah, Vermont, Virginia, Washington, West Virginia,
Wisconsin and Wyoming; offshore Gulf of Mexico continental shelf (GoM OCS).
US Virgin Islands - onshore.

Accuracy within area of use: 2 m

PROJ string:
+proj=pipeline +step +inv +proj=utm +zone=49 +south +ellps=WGS84 +step
+proj=lcc +lat_0=33.75 +lon_0=-79 +lat_1=36.1666666666667
+lat_2=34.3333333333333 +x_0=609601.22 +y_0=0 +ellps=GRS80
************************
See also output of:
projinfo -o PROJ -s "EPSG:32749" -t "EPSG:3358"
Please provide the appropriate PROJ string with the pipeline option
************************
Selected PROJ pipeline:
+proj=pipeline +step +inv +proj=utm +zone=49 +south +ellps=WGS84 +step
+proj=lcc +lat_0=33.75 +lon_0=-79 +lat_1=36.1666666666667
+lat_2=34.3333333333333 +x_0=609601.22 +y_0=0 +ellps=GRS80
************************
Reprojecting primitives ...
Building topology for vector map <hutan_mulya_box@user1>...
Registering primitives...
Building areas...
 100%
Attaching islands...
 100%
Attaching centroids...
 100%

@neteler
Copy link
Member

neteler commented Apr 16, 2023

@metzm shall I bump this PR to 8.4.0?

@wenzeslaus wenzeslaus modified the milestones: 8.3.0, 8.4.0 May 12, 2023
@metzm metzm force-pushed the libproj_areaofuse branch 2 times, most recently from 2771774 to c050755 Compare September 11, 2023 09:12
Comment on lines +171 to +173
if (*xmin < -180 && *xmax < -180) {
G_warning(_("The requested region seems to be outside the area of "
"use of the target CRS"));
Copy link
Member

Choose a reason for hiding this comment

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

When I imagine getting this message I think I would lack three pieces of information:

  1. What region? Is that extent of my raster?
  2. The actual numbers and what's wrong about them. This is what I did for g.region: g.region: Add more detail into error messages #1140 and g.region: Add more detail into LL error messages #1988 in lib/gis/adj_cellhd.c. This may also clarify the uncertainty expressed by "it seems to".
  3. What will happen next. It's a warning, not error, so I would expect the code to go on which it does but it also does some adjustment to the values.

@wenzeslaus wenzeslaus modified the milestones: 8.4.0, Future Apr 27, 2024
@metzm metzm force-pushed the libproj_areaofuse branch from cff9075 to 648374d Compare May 19, 2025 08:52
@metzm metzm closed this May 19, 2025
@metzm metzm deleted the libproj_areaofuse branch May 19, 2025 09:31
@metzm
Copy link
Contributor Author

metzm commented May 19, 2025

This test is not working as expected. PROJ has its own mechanism to check for the area of use with its spatial criterions PROJ_SPATIAL_CRITERION_STRICT_CONTAINMENT and PROJ_SPATIAL_CRITERION_PARTIAL_INTERSECTION, the latter is used by default in GDAL and GRASS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C enhancement New feature or request libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants