-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function to read TIF file, and extracting crucial geographical and dimensional information, and converting them into a manipulable format for further analysis and processing.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#Read TIF image | ||
|
||
import rasterio | ||
|
||
|
||
def readimage(filepath): | ||
"""Read TIF image from file. | ||
Inputs: | ||
filepath = path of TIF image file | ||
Returns: | ||
imagearray = image object as numpy array | ||
crs = coordinate reference system | ||
width = width of digital number array values | ||
height = height of digital number array values | ||
bands = total number of bands in image | ||
bounds = spatial extent of the image mapped on the earth's surface | ||
:param filename: str | ||
:return imagearray: numpy.ndarray | ||
:return crs: rasterio.crs.CRS | ||
:return width: int | ||
:return height: int | ||
:return bands: int | ||
:return bounds: rasterio.coords.BoundingBox | ||
""" | ||
img = rasterio.open(filepath) | ||
inputarray = img.read() | ||
crs = img.crs | ||
width = img.width | ||
height = img.height | ||
bands = img.count | ||
bounds = img.bounds | ||
|
||
return inputarray, crs, width, height, bands, bounds | ||
|