First Question:
Sentinel-1 original HH or HV tiff image convention is still failing, including in ENVI and SNAP software. Question on two results by using these methods convention contribute to the extents of these two images are different from the original.
Finally, I using gdal_translate solved the problem.But, I think this convention step is superfluous.
However, there is still GCPs information in the result, then direct adding of GCS_WGS_1984 projection information is invalid and will get a tiff file that pixel coordinate is over 5000+ degree northern latitude. This is obviously WRONG! So, I think Geo Points i.e. GCPs information leads to the error.
Therefore, there is second question.
Second Question:
How to add correct projection of a Geotiff image to a tiff without projection information?
Most relevant link is [1], however, there is no answer to the question. Then, I went on searching in Stack Overflow and Google!
Maybe link [3] can answer to the Q. Let me try!
I think my Question is very similar to link [3],
Solving method is like below:
The following website[6] introduces how to georeference. As @Manimalis said, My Sentinel-1 image is similar to the website. It meas 'At this point, the image is not georeferenced yet.' Then I tested 'gdalwarp' method and only to find it is used to georeference. Therefore, it cannot be used. I just need to add these GCPs to Tiff file rather to georeference.
Finally, I changed language(English-->Chinese) and website(Google-->Chinese) for searching. When I type in ' tiff 提取 gcps' only to find the function extracting GCPs in Geotiff files, that is 'GetGCPCount', 'GetGCPProjection', 'GetGCPs' in website[7](as following picture), all this function I also find using Google in English in link [8]. However, I think those functions can only use in C language and there is no practical examples in the website.
The following is the example in website[7].
I think I have found the answer for the question. Those functions of gdal is just answer.(Oct. 12, 2018)
However, I don't how to using SetGCPs......
Saturday(10.13), I attended practice test of civil servant in the morning, I still about 30 questions not to answer. I began to try to find the wrong reason for my code in the afternoon. In the evening, I found that change SetGCPs function to 'ds.SetGCPs( gcp )' can get this error, 'TypeError: Dataset_SetGCPs() takes exactly 3 arguments (2 given)', error of 'TypeError: Dataset_SetGCPs() takes exactly 3 arguments (4 given)' when I use 'ds.SetGCPs( gcpcount , gcp, gcpproj )'. Therefore, I guess gcp should change format before set it into SetGCPs function.
Then, I found maybe the answer of website[3] is useful. I can try it! Besides, website[9] is GCP() function introduction. It can be following two format. I want to use first type.
Or if you want to do it in a more pythonic way (adapted from gdal_edit.py):
However, when I using this method and modified my code, after runing well, I got same error as before. gdal.GCP() function is used for converting the format as same to function of GetGCPs(). I do again some idle work. Sad!
However, this is no error when I just put gcp_list and gcpproj as above picture, but noise tif cannot get GCPs and projection. WHY?????????!!!!!!!!!!!!
I finally solved the error !!!!!! Missing the word 'ds = None', the answer is on website[3].
The following picture is result of noise tiff adding GCPs and projections from Sentinel-1 images. My God! Relevant question I posted on Stack Overflow is website[10]
Reference Link:
[1] https://stackoverflow.com/questions/48770002/project-raster-file-using-gcps
[2] Gdal_translate Webpage: https://www.gdal.org/gdal_translate.html
[3] Add GCP to GeoTIFF https://gis.stackexchange.com/questions/206544/in-python-gdal-how-to-add-ground-control-point-to-geotiff-image-by-using-gdal-tr
[4] Use GDAL command line to copy projections https://gis.stackexchange.com/questions/108673/use-gdal-command-line-to-copy-projections
[5] https://gis.stackexchange.com/questions/257904/converting-geotiff-with-gcps-into-projcs-with-python-gdal
[6] https://gis.stackexchange.com/questions/159004/creating-geotiff-from-tiff-using-gdal/159436#159436
[7] https://blog.csdn.net/bcbobo21cn/article/details/51014246?locationNum=12&fps=1
[8] https://www.gdal.org/classGDALDataset.html
[9] https://gdal.org/java/org/gdal/gdal/GCP.html
[10] https://gis.stackexchange.com/questions/298806/error-of-copying-gcps-information-from-geotiff-to-another-tiff
[11] https://www.dropbox.com/s/bk25khnha7w85wg/procSentinelRTC_recipe.py?dl=0
Sentinel-1 original HH or HV tiff image convention is still failing, including in ENVI and SNAP software. Question on two results by using these methods convention contribute to the extents of these two images are different from the original.
Finally, I using gdal_translate solved the problem.But, I think this convention step is superfluous.
Therefore, there is second question.
Second Question:
How to add correct projection of a Geotiff image to a tiff without projection information?
Most relevant link is [1], however, there is no answer to the question. Then, I went on searching in Stack Overflow and Google!
Maybe link [3] can answer to the Q. Let me try!
I think my Question is very similar to link [3],
Solving method is like below:
you can use gdal_edit.py for this:
gdal_edit.py -gcp 0.0 0.0 68.7535734331 81.6383694455 two.tiff
However, I don't how he extracted all of these points into one string. That's too bad!
GeoTiff official website! 3 formats composite GTiff files!
So, I succeed to georeference a tif file with GDAL with the use of 4 gcps (ground control points). To do this reprojection, I use gdal in command line.
First, use gdal translate like this :
gdal_translate -of GTiff -gcp 0 0 -6.848326 45.501053 -gcp 6862 0 -6.490975 45.501503 -gcp 0 1379 -6.762872 45.377363 -gcp 6862 1379 -6.545354 45.382523 "Inputimage.tif" "OutputImage.tif"
The ground control points are build like this : pixel coordinate in the image (x, y) and then geographical location (longitude, latitude).
I suggest to check with gdalinfo if the output file after gdaltranslate has been correctly fed with the gcps. With gdalinfo, you have to see in dos command something like that :
Coordinate System is `'
GCP Projection =
GCP[ 0]: Id=1, Info=
(0,0) -> (45.501053,-6.848326,0)
GCP[ 1]: Id=2, Info=
(6862,0) -> (45.501503,-6.490975,0)
GCP[ 2]: Id=3, Info=
(0,1379) -> (45.377363,-6.762872,0)
GCP[ 3]: Id=4, Info=
(6862,1379) -> (45.382523,-6.545354,0)
At this point, the image is not georeferenced yet. You have to use gdalwarp like this (there is several way to reproject, here I use "near" :
gdalwarp -r near -order 1 -co COMPRESS=NONE -dstalpha
"OutputImageF_From_gdal_translate.tif"
"FinalImage.tif"
Finally, I changed language(English-->Chinese) and website(Google-->Chinese) for searching. When I type in ' tiff 提取 gcps' only to find the function extracting GCPs in Geotiff files, that is 'GetGCPCount', 'GetGCPProjection', 'GetGCPs' in website[7](as following picture), all this function I also find using Google in English in link [8]. However, I think those functions can only use in C language and there is no practical examples in the website.
The following is the example in website[7].
I think I have found the answer for the question. Those functions of gdal is just answer.(Oct. 12, 2018)
However, I don't how to using SetGCPs......
Saturday(10.13), I attended practice test of civil servant in the morning, I still about 30 questions not to answer. I began to try to find the wrong reason for my code in the afternoon. In the evening, I found that change SetGCPs function to 'ds.SetGCPs( gcp )' can get this error, 'TypeError: Dataset_SetGCPs() takes exactly 3 arguments (2 given)', error of 'TypeError: Dataset_SetGCPs() takes exactly 3 arguments (4 given)' when I use 'ds.SetGCPs( gcpcount , gcp, gcpproj )'. Therefore, I guess gcp should change format before set it into SetGCPs function.
Then, I found maybe the answer of website[3] is useful. I can try it! Besides, website[9] is GCP() function introduction. It can be following two format. I want to use first type.
GCP(double x, double y, double pixel, double line) | |
---|---|
GCP(double x, double y, double z, double pixel, double line) |
Or if you want to do it in a more pythonic way (adapted from gdal_edit.py):
from osgeo import gdal
gcp_items = filter(None, gcp_string.split("-gcp"))
gcp_list = []
for item in gcp_items:
pixel, line, x, y = map(float, item.split())
z = 0
gcp = gdal.GCP(x, y, z, pixel, line)
gcp_list.append(gcp)
ds = gdal.Open("two.tiff", gdal.GA_Update)
wkt = ds.GetProjection()
ds.SetGCPs(gcp_list, wkt)
ds = None
Note: this is assuming that the projection of one.tiff and two.tiff are the same. Otherwise you will have to get the wkt from one.tiff.
However, when I using this method and modified my code, after runing well, I got same error as before. gdal.GCP() function is used for converting the format as same to function of GetGCPs(). I do again some idle work. Sad!
The following picture is result of noise tiff adding GCPs and projections from Sentinel-1 images. My God! Relevant question I posted on Stack Overflow is website[10]
4 days have run off!
Until now(10.14), Second question has successfully solved by myself!
However, I found I have do the Thermal Noise Removal in re-processing Python program(10.15). Therefore, I don't know Tingting Zhu(WHU) in her PhD graduation thesis to do this work by herself. The following picture is SNAP TNR step introduction
My pre-processing p Python program( website[11]) includes 4 steps.
Eventually, I have to again resume my GLCM program modification work.
Last week, my largest harvest is improve my ability of writing and convention from point data to raster interpolation based on XML. This experience is very inspiring! ( 17:09 in Oct. 15, 2018)
[1] https://stackoverflow.com/questions/48770002/project-raster-file-using-gcps
[2] Gdal_translate Webpage: https://www.gdal.org/gdal_translate.html
[3] Add GCP to GeoTIFF https://gis.stackexchange.com/questions/206544/in-python-gdal-how-to-add-ground-control-point-to-geotiff-image-by-using-gdal-tr
[4] Use GDAL command line to copy projections https://gis.stackexchange.com/questions/108673/use-gdal-command-line-to-copy-projections
[5] https://gis.stackexchange.com/questions/257904/converting-geotiff-with-gcps-into-projcs-with-python-gdal
[6] https://gis.stackexchange.com/questions/159004/creating-geotiff-from-tiff-using-gdal/159436#159436
[7] https://blog.csdn.net/bcbobo21cn/article/details/51014246?locationNum=12&fps=1
[8] https://www.gdal.org/classGDALDataset.html
[9] https://gdal.org/java/org/gdal/gdal/GCP.html
[10] https://gis.stackexchange.com/questions/298806/error-of-copying-gcps-information-from-geotiff-to-another-tiff
[11] https://www.dropbox.com/s/bk25khnha7w85wg/procSentinelRTC_recipe.py?dl=0
没有评论:
发表评论