|
42 | 42 |
|
43 | 43 | debug = False
|
44 | 44 |
|
| 45 | +def log(item): |
| 46 | + return QgsMessageLog.logMessage(str(item)) |
| 47 | + |
45 | 48 | ###---------- Edit these variables ----------
|
46 | 49 | # Min & max h3 resolution levels, from 0 to 15 (global to sub-meter)
|
47 | 50 | # High resolutions over broad areas can be slow and consume a lot of storage space
|
|
58 | 61 | # --------------------------------------------
|
59 | 62 |
|
60 | 63 | projectPath = os.path.dirname(QgsProject.instance().fileName())
|
| 64 | +if not projectPath: |
| 65 | + # fallback if project not saved |
| 66 | + projectPath = os.environ.get("TEMP", "/tmp") |
| 67 | +else: |
| 68 | + projectPath = os.path.dirname(projectPath) |
| 69 | + |
61 | 70 | geo_csrs = QgsCoordinateReferenceSystem(geographic_coordsys)
|
62 | 71 | out_csrs = QgsCoordinateReferenceSystem(output_projection)
|
63 | 72 |
|
64 |
| -dataPath = os.path.abspath(os.path.join(projectPath, "data")) # use abspath and remove trailing slash |
| 73 | +if not projectPath: |
| 74 | + projectPath = os.environ["TEMP"] |
| 75 | + log(f"No projectPath defined, using TEMP: {projectPath}") |
65 | 76 |
|
| 77 | +dataPath = os.path.abspath(os.path.join(projectPath, "data")) # use abspath and remove trailing slash |
66 | 78 | try:
|
67 | 79 | if not os.path.exists(dataPath):
|
68 | 80 | os.makedirs(dataPath, exist_ok=True) # use makedirs instead of mkdir
|
69 | 81 | except PermissionError:
|
70 |
| - # If we can't create in project directory, fall back to temp |
| 82 | + log(f"Can't create '{dataPath}' falling back to TEMP") |
71 | 83 | dataPath = os.path.abspath(os.path.join(os.environ["TEMP"], "data"))
|
72 | 84 | os.makedirs(dataPath, exist_ok=True)
|
73 | 85 |
|
|
80 | 92 | QgsProject.instance().addMapLayer(mylayer)
|
81 | 93 |
|
82 | 94 |
|
83 |
| -def log(item): |
84 |
| - return QgsMessageLog.logMessage(str(item)) |
85 |
| - |
86 |
| - |
87 | 95 | def proj_to_geo(in_layer):
|
88 | 96 | """Project to geographic coordinate system, in memory.
|
89 | 97 | H3 needs all coordinates in decimal degrees"""
|
|
0 commit comments