Hello, everybody:
I have a new problem: can I save a image file with coastlines and lat-lon lines in geotiff format?
Thank Adam that it has no any error messages in saving image files in geotiff format, and the image files do have the informations about parameters of projection, area_def, pixel-size, latitude-longitude, time-tag, and etc.(by the software OpenEV 1.80)
But the image file with coastlines and lat-lon lines and saved in geotiff format has no the informatin metioned above.
Here is my code:
**********************************************
from PIL import Image, ImageFont
from pycoast import ContourWriter
from pycoast import ContourWriterAGG
from mpop.projector import get_area_def
from mpop.imageo import geo_image
from mpop.satellites import PolarFactory
from datetime import datetime,timedelta
import mpop
areaid='jap_test'
area_def=get_area_def(areaid)
tslots=[]
start_time=datetime(2013,7,1,4,1)
tstep=timedelta(seconds=60)
end_time=start_time+timedelta(minutes=20)
orbit="00001"
while start_time<end_time:
tslots.append(start_time)
start_time+=tstep
global_data=[]
for time_slot in tslots:
global_data.append(PolarFactory.create_scene("npp","","viirs",time_slot,orbit))
#loading the channels
gldata=[]
for glbd in global_data:
try:
glbd.load(['DNB'])
#glbd.area=glbd['DNB'].area
gldata.append(glbd)
except:
pass
global_data=mpop.scene.assemble_segments(global_data)
local_data=global_data.project(areaid,mode="nearest")
img=geo_image.GeoImage(local_data['DNB'].data,areaid,tslots[0],fill_value=0,mode='L')
img.enhance(stretch='linear')
geotrf = [area_def.area_extent[0], area_def.pixel_size_x, 0,
area_def.area_extent[3], 0, -area_def.pixel_size_y]
from osgeo import gdal, osr
srs = osr.SpatialReference()
srs.ImportFromProj4(area_def.proj4_string)
srs.SetProjCS(area_def.proj_id)
try:
srs.SetWellKnownGeogCS(area_def.proj_dict['ellps'])
except KeyError:
pass
try:
srs.SetAuthority('PROJCS', 'EPSG',
int(area_def.proj_dict['init'].split('epsg:')[1]))
except (KeyError, IndexError):
pass
srs = srs.ExportToWkt()
img.save('/root/test.tif', geotransform=geotrf,spatialref=srs,compression=0)
font=ImageFont.truetype('/usr/share/fonts/dejavu/DejaVuSerif.ttf',64)
cw=ContourWriter('/home/user1/GSHHS_DATA_ROOT')
cw.add_coastlines_to_file('/root/test.tif',area_def,resolution='l',level=4)
cw.add_grid_to_file('/root/test_other.tif',area_def,(10.0,10.0),(2.0,2.0),font,fill='red',outline='red',minor_outline='red')
***********************
I try different ways, the results are the same: missing the informations of geotiff files should have.
1.As above code, save a projected image in geotiff format, and then add coastlines and lat-lon lines.
2.save a projected image in geotiff format, and then open it, adding coastlines and lat-lon lines, saving in geotiff format with different file name.
3.save a projected image in png format, and then open it, adding coastlines and lat-lon lines, saving in geotiff format with different file name.
How should I do it?
Thanks for your help.
Bocheng