Skip to content

Commit

Permalink
Merge pull request #19 from Open-Source-Agriculture/dev
Browse files Browse the repository at this point in the history
crs_code input
  • Loading branch information
KipCrossing committed May 4, 2021
2 parents d5c80aa + 5cabae6 commit e46b79b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ geoTiff = GeoTiff(tiff_file)
array = geoTiff.read()
```

This will detect the crs code. If it's 'user defined' and you know what it should be, you may supply a crs code:

```python
geoTiff = GeoTiff(tiff_file, crs_code=4236)
```

Get bounding box info about the tiff

```python
Expand Down
4 changes: 2 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
filename = "dem.tif"
dir = "./tests/inputs/"
tiff_file = os.path.join(dir, filename)
# tiff_file = "/home/kipling/Documents/fsm_sample_data/ntz52.tif"
tiff_file = "/home/kipling/Programs/pylandsat_sandbox/data/gamma/Radmap2019-grid-k_conc-Filtered-AWAGS_RAD_2019.tif"
# 138.632071411 -32.447310785 138.644218874 -32.456979174
bounding_box: List[Tuple[float, float]] = [(138.632071411, -32.447310785), (138.644218874, -32.456979174)]


print("testing read tiff")
print(f"reading: {tiff_file}")
print(f"Using bBox: {bounding_box}")
geotiff: GeoTiff = GeoTiff(tiff_file)
geotiff: GeoTiff = GeoTiff(tiff_file, crs_code=4236)
print(geotiff.tif_bBox)
print(geotiff.crs_code)
array = geotiff.read_box(bounding_box)
Expand Down
9 changes: 6 additions & 3 deletions geotiff/geotiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ def get_xy(self, i: int, j: int) -> Tuple[float, float]:


class GeoTiff():
def __init__(self, file: str):
def __init__(self, file: str, crs_code: Optional[int] = None):
"""For representing a geotiff
Args:
file (str): Location of the geoTiff file
crs_code (Optional[int]): the crs code of the tiff file
Raises:
FileTypeError: [description]
Expand All @@ -122,8 +123,10 @@ def __init__(self, file: str):
store = imread(self.file, aszarr=True)
self.z = zarr.open(store, mode='r')
store.close()

self.crs_code: int = self._get_crs_code(tif.geotiff_metadata)
if isinstance(crs_code, int):
self.crs_code: int = crs_code
else:
self.crs_code = self._get_crs_code(tif.geotiff_metadata)
self.tifShape: List[int] = self.z.shape
scale: Tuple[float, float, float] = tif.geotiff_metadata['ModelPixelScale']
tilePoint: List[float] = tif.geotiff_metadata['ModelTiepoint']
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from setuptools.command.install import install

VERSION = "0.1.5"
VERSION = "0.1.6"

# Send to pypi
# python3 setup.py sdist bdist_wheel
Expand Down

0 comments on commit e46b79b

Please sign in to comment.