[gdal-dev] GCPsToGeoTransform returns wrong values

Bar Ori Ori.Bar at elbitsystems.com
Thu Nov 19 04:24:34 PST 2015


What I decided to do it to set the GPCs on the corners :

var gcps = new[]
{
new GCP(LeftUp.X, LeftUp.Y, LeftUp.Z, 0, 0, null, "1"),
new GCP(RightUp.X, RightUp.Y, RightUp.Z, Width , 0, null, "2"),
new GCP(RightDown.X, RightDown.Y, RightDown.Z, Width, Height, null, "3"),
new GCP(LeftDown.X, LeftDown.Y, LeftDown.Z, 0, Height, null, "4")
};

Then to run :
var geotransform = new double[6];
Gdal.GCPsToGeoTransform(gcps, geotransform, 0)

In case it returns TRUE, a rectangular shape, so I call:
dataSet.GetGeoTransform(geotransform);

Otherwise, I put the GCPs on the middle of pixels ( gcps[0] += 0.5 etc… ) and call :
dataSet.SetGCPs(gcps, projection)

When I want to reload the information, so first I check the GCPs count. If 0, so I take and calculate the corners coordinates using the geotransform.
Otherwise, I get the GCPs.

It works for me.
Ready to hear if there is a better solution.

From: gdal-dev [mailto:gdal-dev-bounces at lists.osgeo.org] On Behalf Of Bar Ori
Sent: 18 November 2015 13:18
To: gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] GCPsToGeoTransform returns wrong values

I found in did that the GDALGCPsToGeoTransform using the pixels values for calculation:

At gdal_misc.cpp :
padfGeoTransform[1] = (pasGCPs[1].dfGCPX - pasGCPs[0].dfGCPX) / (pasGCPs[1].dfGCPPixel - pasGCPs[0].dfGCPPixel);
padfGeoTransform[0] = pasGCPs[0].dfGCPX - pasGCPs[0].dfGCPPixel * padfGeoTransform[1];

in this case, the question is what is the best practice for the problem I published (sometimes rectangle, sometimes not).

From: gdal-dev [mailto:gdal-dev-bounces at lists.osgeo.org]<mailto:[mailto:gdal-dev-bounces at lists.osgeo.org]> On Behalf Of Bar Ori
Sent: 18 November 2015 12:00
To: Ari Jolma
Cc: gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>
Subject: Re: [gdal-dev] GCPsToGeoTransform returns wrong values

Thanks Ari for your reply.

In my situation, sometimes I am working with rectangles and sometimes not. Depends the source of information.
I thought to always use the GCPs as follows:
In case my shape has rectangular form, so the dataSet.GetGCPCount() will return me “0” and I will use the dataSet.GetGeoTransform(), otherwise, will use the dataSet.GetGCPs().
The issue is that for setting the GCPs, I must put the coordinate in the middle of pixel (that is why I  subtract “0.5”). If I wouldn’t, so yes, the geotransform values would be correct.
Is it a bad practice? Should I figure out the shape from start and to take two different steps?

From: gdal-dev [mailto:gdal-dev-bounces at lists.osgeo.org]<mailto:[mailto:gdal-dev-bounces at lists.osgeo.org]> On Behalf Of Ari Jolma
Sent: 18 November 2015 11:35
To: gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>
Subject: Re: [gdal-dev] GCPsToGeoTransform returns wrong values

Bar,

I think you are setting the GCPs up wrongly if you want them to be at the corners.

GCP(LeftDown.X, LeftDown.Y, LeftDown.Z, Height - 0.5, null, "4") does not have 0 before Height-0.5.

GCPsToGeoTransform checks the special case of GCPs in rectangular shape and in top-left, top-right, bottom-right, bottom-left order and returns the exact transform the dataset has.

I'm not sure if it makes sense to have real values for the pixel coordinates although they are real values.

Best,

Ari
On 18.11.2015 09:32, Bar Ori wrote:
Hi,
I noticed something that for me looks weird and I would like to know maybe I am doing something wrong.
If not, how should I overcome this behavior.

I set 4 GCPs as follows:

var gcps = new[]
{
new GCP(LeftUp.X, LeftUp.Y, LeftUp.Z, 0.5, 0.5, null, "1"),
new GCP(RightUp.X, RightUp.Y, RightUp.Z, Width - 0.5, 0.5, null, "2"),
new GCP(RightDown.X, RightDown.Y, RightDown.Z, Width - 0.5, Height - 0.5, null, "3"),
new GCP(LeftDown.X, LeftDown.Y, LeftDown.Z, Height - 0.5, null, "4")
};

And when I am doing as follows:

var geotransform = new double[6];
Gdal.GCPsToGeoTransform(gcps, geotransform, 0)

Or (after using dataSet.SetGCPs(gcps, projection) :

var geotransform = new double[6];
dataSet.GetGeoTransform(geotransform);

So the values returned, are wrong.
For example, if the LeftUp.X was 35.01050 so the value of geotransform[0], which supposed to be the same value, can be 35.0082.
The same with all the geotransform values.
If I am getting from the dataset and setting again, every time it is changing more and more.
Is there any connection to the use of the “0.5”?

Thanks.


[cid:image001.png at 01D122D6.033D74C0]

Ori Bar | Software Developer
Applications Development
Elbit Systems Land and C4I
T  +972-9-8898900  |   M  +972-504-734296




The information in this e-mail transmission contains proprietary and business
sensitive information.  Unauthorized interception of this e-mail may constitute
a violation of law. If you are not the intended recipient, you are hereby
notified that any review, dissemination, distribution or duplication of this
communication is strictly prohibited. You are also asked to contact the sender
by reply email and immediately destroy all copies of the original message.


_______________________________________________

gdal-dev mailing list

gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>

http://lists.osgeo.org/mailman/listinfo/gdal-dev


The information in this e-mail transmission contains proprietary and business
sensitive information.  Unauthorized interception of this e-mail may constitute
a violation of law. If you are not the intended recipient, you are hereby
notified that any review, dissemination, distribution or duplication of this
communication is strictly prohibited. You are also asked to contact the sender
by reply email and immediately destroy all copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20151119/a4d34748/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 4160 bytes
Desc: image001.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20151119/a4d34748/attachment-0001.png>


More information about the gdal-dev mailing list