Skip to content

Commit

Permalink
Fix prep tile index
Browse files Browse the repository at this point in the history
  • Loading branch information
collijk committed Dec 31, 2024
1 parent 29219ef commit a3fef76
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/rra_building_density/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import itertools
import warnings
from pathlib import Path

import pyproj
Expand Down Expand Up @@ -54,17 +55,19 @@ def validate_code_or_proj_string(self) -> "CRS":
@model_validator(mode="after")
def validate_code_and_proj_string(self) -> "CRS":
if self.code and self.proj_string:
code_proj = pyproj.CRS.from_user_input(self.code)
proj_proj = pyproj.CRS.from_user_input(self.proj_string)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
code_proj = pyproj.CRS.from_user_input(self.code).to_proj4()
proj_proj = pyproj.CRS.from_user_input(self.proj_string).to_proj4()
if code_proj != proj_proj:
msg = "code and proj_string must represent the same CRS."
raise ValueError(msg)
return self

def to_pyproj(self) -> pyproj.CRS:
if self.proj_string:
return pyproj.CRS.from_proj4(self.proj_string)
return pyproj.CRS.from_user_input(self.code)
if self.code:
return pyproj.CRS.from_user_input(self.code)
return pyproj.CRS.from_user_input(self.proj_string)


CRSES: dict[str, CRS] = {
Expand Down
2 changes: 1 addition & 1 deletion src/rra_building_density/process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}

TASK_RUNNERS = {
"prepare_tile_index": tile_index_task,
"tile_index": tile_index_task,
"ghsl": format_ghsl_task,
"microsoft": format_microsoft_task,
}
6 changes: 3 additions & 3 deletions src/rra_building_density/process/tile_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def tile_index_main(
data.append([block_key, tile_key, tile_poly])

columns = ["block_key", "tile_key", "geometry"]
modeling_frame = gpd.GeoDataFrame(data, columns=columns, crs=crs)
modeling_frame = gpd.GeoDataFrame(data, columns=columns, crs=crs.to_pyproj())

print("Saving")
modeling_frame_info = TileIndexInfo(
Expand Down Expand Up @@ -117,8 +117,8 @@ def tile_index(
"output-dir": output_dir,
},
node_args={
"tile_size": [tile_size],
"block_size": [block_size],
"tile-size": [tile_size],
"block-size": [block_size],
"resolution": resolution,
},
task_resources={
Expand Down

0 comments on commit a3fef76

Please sign in to comment.