Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: preserve CRS from input geotiff #10

Merged
merged 1 commit into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mapa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _get_tiff_for_bbox(bbox_geojson: dict, allow_caching: bool) -> Path:
return _fetch_merge_and_clip_tiffs(bbox_geojson, bbox_hash, allow_caching)


def create_stl_for_bbox(
def convert_bbox_to_stl(
bbox_geometry: dict,
as_ascii: bool = False,
model_size: int = 200,
Expand All @@ -151,7 +151,7 @@ def create_stl_for_bbox(
allow_caching: bool = True,
) -> Path:
if bbox_geometry is None:
print("ERROR: make sure to draw a rectangle on the map first!")
click.echo("⛔️ ERROR: make sure to draw a rectangle on the map first!")
return

click.echo("⏳ converting bounding box to STL file... \n")
Expand Down
33 changes: 16 additions & 17 deletions mapa/mapa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"metadata": {},
"outputs": [],
"source": [
"from mapa import create_stl_for_bbox\n",
"from mapa import convert_bbox_to_stl\n",
"from mapa.map import show_map"
]
},
Expand All @@ -32,7 +32,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c6ed5b5bb2d5430394a72af98a754b8f",
"model_id": "e29f8fff53b4431c93fc194ba59f7140",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -42,6 +42,13 @@
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Rectangle detected, execute next cells to continue!\n"
]
}
],
"source": [
Expand All @@ -59,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"id": "39c8fef3",
"metadata": {
"scrolled": true
Expand All @@ -71,24 +78,24 @@
"text": [
"⏳ converting bounding box to STL file... \n",
"\n",
"fetching 2 stac items...\n",
"🚀 using cached stac item ALPSMLC30_N047E008_DSM ✅ (0.0s)\n",
"🚀 using cached stac item ALPSMLC30_N046E008_DSM ✅ (0.0s)\n",
"⬇️ fetching 2 stac items...\n",
"🚀 using cached stac item ALPSMLC30_N046E009_DSM ✅ (0.0s)\n",
"🚀 using cached stac item ALPSMLC30_N045E009_DSM ✅ (0.0s)\n",
"🔪 clipping region of interest... ✅ (0.1s) \n",
"🔍 reducing image resolution... ✅ (0.0s) \n",
"🗺 creating base raster for tiff... ✅ (0.0s) \n",
"🗺 creating base raster for tiff... ✅ (0.2s) \n",
"⛰ computing triangles of 3d surface... ✅ (0.1s) \n",
"📐 computing triangles of body sides... ✅ (0.2s) \n",
"💾 saving data to stl file... ✅ (0.7s) \n",
"\n",
"🎉 successfully generated STL file: /Users/ppqw/dev/geospacial/mapa/mapa/alps.stl\n"
"🎉 successfully generated STL file: /Users/ppqw/dev/geospacial/mapa/mapa/output.stl\n"
]
}
],
"source": [
"stl_file_name = \"output.stl\"\n",
"\n",
"path = create_stl_for_bbox(\n",
"path = convert_bbox_to_stl(\n",
" bbox_geometry=drawer.last_draw[\"geometry\"],\n",
" output_file=stl_file_name, # path to output stl file\n",
" model_size=200, # in millimeter\n",
Expand All @@ -98,14 +105,6 @@
" make_square=False, # cuts longer side of the input bbox to get a square\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "63dc3189",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
6 changes: 4 additions & 2 deletions mapa/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def clip_tiff_to_bbox(input_tiff: Path, bbox_geometry: dict, bbox_hash: str) ->
"height": out_img.shape[1],
"width": out_img.shape[2],
"transform": out_transform,
"crs": data.crs,
}
)
clipped_tiff = _path_to_clipped_tiff(bbox_hash)
Expand Down Expand Up @@ -94,7 +95,8 @@ def determine_elevation_scale(tiff: DatasetReader, model_size: int) -> float:
def merge_tiffs(tiffs: List[Path], bbox_hash: str) -> Path:
datasets = []
for tiff in tiffs:
datasets.append(rio.open(tiff))
data = rio.open(tiff)
datasets.append(data)
mosaic, out_trans = merge(datasets)
out_meta = datasets[0].meta.copy()
out_meta.update(
Expand All @@ -103,7 +105,7 @@ def merge_tiffs(tiffs: List[Path], bbox_hash: str) -> Path:
"height": mosaic.shape[1],
"width": mosaic.shape[2],
"transform": out_trans,
"crs": "+proj=utm +zone=35 +ellps=GRS80 +units=m +no_defs ",
"crs": data.crs,
}
)
tiff = _path_to_merged_tiff(bbox_hash)
Expand Down
Loading