コード例 #1
0
def GetGtiffInformation(filein,EPSG=0):

	# open file and get information
	f, a, img = ReadGtiffRaster(filein)
	
	# metadata
	Metadata = f.GetMetadata()

	# dimension	
	ncols, nrows = a.XSize, a.YSize
	
	# ground control points
	GCPs = f.GetGCPs()
	GCPs_projection = f.GetGCPProjection()

	# transformation info (coordinates and resolution)
	Geotransform = f.GetGeoTransform()
	
	# projection info (spatial reference system (EPSG related))
	if EPSG == 0:
		srs = osr.SpatialReference(wkt=f.GetProjection())
	else:
		srs = osr.SpatialReference(); srs.ImportFromEPSG(EPSG)

	#store information
	Infos = CL.GtiffInformation(Metadata, ncols, nrows, GCPs, GCPs_projection, Geotransform, srs)
		
	#deallocate raster
	f = None

	return img, Infos
コード例 #2
0
def array2raster(img, coordinates, EPSG, filein, fileout="ImgOut.tif"):
	#------------------------------------------------------------
	# convert 2D array into GDAL raster (GeoTiff)
	# 	General purpose: recreate raster after 
	#			- change in frame of reference
	#			- conserve the Projection system
	#------------------------------------------------------------
	# get input infos	
	_,Info = GetGtiffInformation(filein, EPSG)

	#process image
	img=ScaleImage(img,8)
	
	# get corner coordinates
	
	# coordinates
	easting = coordinates.easting; northing = coordinates.northing;

	# extrema
	xmin,ymin,xmax,ymax = [easting.min(),northing.min(),easting.max(),northing.max()]

	if len(img.shape)>2:
		nrows,ncols = np.shape(img[0,:,:])
	else:
		nrows,ncols = np.shape(img)
	# store dimension data
	Info.ncols = ncols; Info.nrows=nrows;
		
	#get the edges and recreate the corner coordinates for Geotransform raster properties
	xres = (xmax-xmin)/float(ncols); yres = (ymax-ymin)/float(nrows)
	Geotransform = (xmin,xres,0,ymax,0, -yres); 
	Infos = CL.GtiffInformation(Info.Metadata, Info.ncols, Info.nrows, Info.GCPs, Info.GCPs_projection, Geotransform, Info.srs)
	
	#create output raster
	CreateOutputGtiff(img, fileout, Infos)
	
	return None