Skip to content

Commit

Permalink
Merge pull request #38 from iamtekson/richardburcher-main
Browse files Browse the repository at this point in the history
save georeference file option; The default option will be false.
  • Loading branch information
iamtekson authored Sep 18, 2023
2 parents 2f08671 + 9d8e3d2 commit 9992339
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions geotile/GeoTile.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def generate_tiles(
suffix: Optional[str] = None,
prefix: Optional[str] = None,
save_tiles: Optional[bool] = True,
save_transform: Optional[bool] = False,
out_bands: Optional[list] = None,
image_format: Optional[str] = None,
dtype: Optional[str] = None,
Expand All @@ -193,6 +194,8 @@ def generate_tiles(
Path to the output folder
save_tiles : bool
If True, the tiles will be saved to the output folder else the tiles will be stored in the class
save_transform : bool
If True, the transform will be saved to the output folder in txt file else it will only generate the tiles
suffix : str
The suffix of the tile name (eg. _img)
prefix : str
Expand Down Expand Up @@ -301,25 +304,27 @@ def generate_tiles(

tile_path = os.path.join(output_folder, tile_name)

# tile georeference data to reconstruct spatial location from output inference bboxes
geo_reference_tile_worldfile = (f'{prefix}{str(i)}{suffix}.txt' if suffix or prefix else
f'tile_{col_off}_{row_off}.txt')

geo_reference_tile_worldfile_path = os.path.join(output_folder, geo_reference_tile_worldfile)

crs = meta["crs"]
crs = crs.to_proj4()
if save_transform:
# tile georeference data to reconstruct spatial location from output inference bboxes
geo_reference_tile_worldfile = (f'{prefix}{str(i)}{suffix}.txt' if suffix or prefix else
f'tile_{col_off}_{row_off}.txt')

geo_reference_tile_worldfile_path = os.path.join(output_folder, geo_reference_tile_worldfile)

crs = meta["crs"]
crs = crs.to_proj4()

# raster affine transform information
with open(geo_reference_tile_worldfile_path, "w") as f:
f.write(str(transform.to_gdal()))
f.write("\n")
f.write(crs)

# save the tiles with new metadata
with rio.open(tile_path, 'w', **meta) as outds:
outds.write(self.ds.read(
out_bands, window=window, fill_value=nodata, boundless=True).astype(dtype))

# raster affine transform information
with open(geo_reference_tile_worldfile_path, "w") as f:
f.write(str(transform.to_gdal()))
f.write("\n")
f.write(crs)

if not save_tiles:
# convert list to numpy array
Expand Down

0 comments on commit 9992339

Please sign in to comment.