Using Java, I want to add geo tags to existing TIFF file and make it into a GeoTIFF file. Otherwise, for buffered image is it possible to add geotags to make a GeoTIFF file.
[GIS] Create GeoTIFF from TIFF using Java
geotiff-tiffjava
Related Solutions
There is a little bit of information which might help you in your task. First you may need to download FWTools inorder to use geotifcp and listgeo.
Create a TIFF File(You already did it..) Let us call it initialtif.tif
find the image width and height(from where you saved it).
imageWidth = 1016
imageHeight = 551
Create a World File for our initialtif.tif using the below parameters.
From Wiki, the World File is defined as below. Refer below image for details. mapWidth and mapHeight are to be measured from your map application.
Line 1: A: pixel size in the x-direction in map units/pixel = mapWidth/imageWidth
Line 2: D: rotation about y-axis = 0
Line 3: B: rotation about x-axis = 0
Line 4: E: pixel size in the y-direction in map units, almost always negative[3] = -mapHeight/imageHeight
Line 5: C: x-coordinate of the center of the upper left pixel = C
Line 6: F: y-coordinate of the center of the upper left pixel = F
Enter these 6 numbers on a text file and save as initialtif.tfw
Get a GeoTiff(say reference.tif) in the same Coordinate System/projection. Get one from your friends or create it yourself using Qgis/Arcgis..
extract metadata from GeoTiff using listgeo
command(In Windows..)
listgeo -proj4 reference.tif >metadata.txt
Create GeoTiff using geotifcp
command
geotifcp -g metadata.txt -e forWorld.TFwx forWorld.TIF finaltiff.tif
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"
Best Answer
You can use java library: GeoTiff-JAI.
More is in this post: https://stackoverflow.com/questions/3716462/how-can-i-write-a-geotiff-in-java