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

Fix gdal command #46415

Closed
wants to merge 1 commit into from
Closed

Conversation

roya0045
Copy link
Contributor

@roya0045 roya0045 commented Dec 8, 2021

Description

Minor bug/typo? encountered while digging into #46414

@nyalldawson Would you know if this is a typo, I assume it is.

Though strangely with this error, it yielded the same results as our standard process, now the outputs are different, maybe there is another extra negative somewhere or I'm just dealing with weird cases? Still not sure why already georeferenced images are handling badly regardless of the method.

@github-actions github-actions bot added this to the 3.24.0 milestone Dec 8, 2021
@agiudiceandrea
Copy link
Member

agiudiceandrea commented Dec 8, 2021

@roya0045 I think the minus sign is needed.
AFAIK, in the Georeferencer, for a non georeferenced raster, the "Source Y" coordinate is always negative: the top-left corner of the source raster to be georeferenced has 0,0 coordinates with the X values increasing toward the "right" and the Y values increasing "upwards" (so they are negative "downwards"); in gdal_translate -gcp, the <pixel> and <line> values are also top-left based, with the <pixel> values increasing toward the "right" but with the <line> values increasing "downwards" (so they must be positive "downwards").

@roya0045
Copy link
Contributor Author

roya0045 commented Dec 8, 2021

@roya0045 I think the minus sign is needed. AFAIK, in the Georeferencer, for a non georeferenced raster, the "Source Y" coordinate is always negative: the top-left corner of the source raster to be georeferenced has 0,0 coordinates with the X values increasing toward the "right" and the Y values increasing "upwards" (so they are negative "downwards"); in gdal_translate -gcp, the and values are also top-left based, with the values increasing toward the "right" but with the values increasing "downwards" (so they must be positive "downwards").

So this would only be an issue for raster that are already georeferenced? That's possible.

@agiudiceandrea
Copy link
Member

agiudiceandrea commented Dec 9, 2021

So this would only be an issue for raster that are already georeferenced? That's possible.

Yes. If the added raster has a geotransform set, then the "Source X" and "Source Y" are incorrectly not expressed as raster pixels coordinates, but as geotransformed coordinates.
So, I think the issue could be fixed in one of two ways:

  • always remove any raster geotransform when the raster is added to the Georeferencer map canvas
  • or, make sure to translate the geotransformed coordinates to raster pixels coordinates

@roya0045
Copy link
Contributor Author

roya0045 commented Dec 9, 2021

Though the issue is not the gdal expression exported but the process itself. Maybe @rouault would be able to tell if gdal only works with pixel coordinates or projected coords once an image is georeferenced.

@rouault
Copy link
Contributor

rouault commented Dec 9, 2021

if gdal only works with pixel coordinates or projected coords once an image is georeferenced.

it depends on utilities and options used. It is normally clearly documented. e.g if using gdal_translate, -srcwin is in pixel coordinates and -projwin in georeferenced coordinates

@agiudiceandrea
Copy link
Member

if using gdal_translate, -srcwin is in pixel coordinates and -projwin in georeferenced coordinates

@rouault, AFAIK this is not the case for gdal_translate -gcp option, in which <pixel> and <line> values are always in raster pixels coordinates even if the source raster already has a geotransform set, isn't it?

@roya0045
Copy link
Contributor Author

roya0045 commented Dec 9, 2021

@agiudiceandrea yeah it works fine with non-georeferenced images, in the georeferencer the top-left corner is 0,0 and the image has negative y, so making them positive makes the command work.

Though I have reservations about removing an transformation on the image. If someone would want to adjust something they would have to import the geoerefenced image in the canvas to get the coordinates of the existing pixel. This would be an instance where the user would want to correct the deformation or perform a simple transform on an image that is already georeferenced and 'deformed'. If they have the original points that would be doable.

@rouault
Copy link
Contributor

rouault commented Dec 9, 2021

for gdal_translate -gcp option, in which and values are always in raster pixels coordinates even if the source raster already has a geotransform set, isn't it?

yes

@roya0045
Copy link
Contributor Author

@agiudiceandrea I thinnk the best solution would be to add a coord to the datapoint, currently the 'pixelcoord' is the position in the georeferencer, it's not the true coordinate of the chosen pixel, it's the rastercoord.

I can check into reworking the code and making sure the raster coord gets properly converted into the true pixel coords. That way there is no need for finicking around with a 'hack' (the - in the gdal script) and would be more consistent.

@nyalldawson does that sounds like a reasonable approach?

@roya0045 roya0045 closed this Dec 13, 2021
@roya0045
Copy link
Contributor Author

Needed code seem to be mostly present, though convoluted. Will investigate the issue.

@roya0045 roya0045 deleted the fix_gdal_transpate_cmd branch January 24, 2022 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants