Skip to content

Commit

Permalink
Fix path interpretation for landscape layers. (#141)
Browse files Browse the repository at this point in the history
StreamCat was failing with a path to categorical image data outside the
layers folder, either joining paths when it shouldn't, e.g.
E:\path\to\layersE:/data/landcover.img, or failing to make a valid DBF
name, e.g. ...\DBFStash\E:\data\landcover.img.  Changes make it work
regardless of / or \ delimiters, previously it failed one way or the
other whichever you used.
  • Loading branch information
brownterryn authored Jan 23, 2025
1 parent ada4bfa commit aac2d92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions StreamCat.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
mask_dir = ""
layer = (
row.LandscapeLayer
if os.sep in row.LandscapeLayer
if "/" in row.LandscapeLayer or "\\" in row.LandscapeLayer
else (f"{LYR_DIR}/{row.LandscapeLayer}")
) # use abspath
if isinstance(row.summaryfield, str):
Expand Down Expand Up @@ -191,4 +191,4 @@
"Be sure to delete the associated files in your `OUTDIR` to rerun:"
f"\n\t> {OUT_DIR}\n\n!!! `$OUT_DIR/DBF_stash/*` "
f"output used in 'Continuous' and 'Categorical' metrics!!!"
)
)
7 changes: 5 additions & 2 deletions StreamCat_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import sys
import time
from collections import OrderedDict, defaultdict, deque
from pathlib import Path
from typing import Generator

import numpy as np
Expand Down Expand Up @@ -965,16 +966,18 @@ def createCatStats(
arcpy.env.snapRaster = inZoneData
if by_RPU == 0:
if LandscapeLayer.count(".tif") or LandscapeLayer.count(".img"):
landscape_layer = Path(LandscapeLayer).stem # / vs. \ agnostic
outTable = "%s/DBF_stash/zonalstats_%s%s%s.dbf" % (
out_dir,
LandscapeLayer.split("/")[-1].split(".")[0],
landscape_layer,
appendMetric,
zone,
)
else:
landscape_layer = Path(LandscapeLayer).name # / vs. \ agnostic
outTable = "%s/DBF_stash/zonalstats_%s%s%s.dbf" % (
out_dir,
LandscapeLayer.split("/")[-1],
landscape_layer,
appendMetric,
zone,
)
Expand Down

0 comments on commit aac2d92

Please sign in to comment.