2

I have used gdal to read geotiff file. I tried to calculate longitude and latitude value for each pixel and line. Here is part of my code.

   for (int l_idx = 0;l_idx < line;l_idx++ )
{
    for (int p_idx = 0;p_idx < pixel;p_idx++)
    {
        if (elevation_data[(l_idx * pixel + p_idx)] > 0 && written_count < count)
        {
            x[(l_idx * pixel + p_idx)] = geo_transform[0] + geo_transform[1] * (p_idx) + geo_transform[2] * (l_idx);
            y[(l_idx * pixel + p_idx)] = geo_transform[3] + geo_transform[4] * (p_idx) + geo_transform[5] * (l_idx);
            x[(l_idx * pixel + p_idx)] += geo_transform[1] / 2.0;
            y[(l_idx * pixel + p_idx)] += geo_transform[5] / 2.0;

            fprintf_s(fp, "pixel and line %f,%f,", x[(l_idx * pixel + p_idx)], y[(l_idx * pixel + p_idx)]);
            coordinates_info->Transform(1, &x[(l_idx * pixel + p_idx)], &y[(l_idx * pixel + p_idx)]);
            fprintf_s(fp, "long and lat %f,%f, ", x[(l_idx * pixel + p_idx)], y[(l_idx * pixel + p_idx)]);
            fprintf_s(fp, "elevation %f\n", elevation_data[(l_idx * pixel + p_idx)]);

        }           

    }
}

I saved my output into the file. I have imported same geotiff file in photo scan ,global mapper tool.I didn't(using above code) get any longitude and latitude or Easting and Northing value displayed in those tools. May I know the reason. Is there any mistake in my code or DO i need to any conversion or code?? or How to check the correctness of my output(correct long & lat)?

  • You need to give more information. What CRS does the GeoTIFF use. What do you get from the other tools? – bugmenot123 Jan 24 '17 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.