forked from OSGeo/grass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v.fill.holes: Add new tool to remove inner isles, keep outer boundary (…
…OSGeo#2486) * Write boundaries of areas with centroids. * Writes each boundary only once using index of already written boundaries. * Copies attributes. * Has tests for removal of holes are preservation of attributes. * Has documentation including an image and a notebook to generate the image. * Does not free memory at the end as in many existing modules.
- Loading branch information
1 parent
58ea686
commit 72c56a2
Showing
14 changed files
with
932 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ SUBDIRS = \ | |
v.edit \ | ||
v.extract \ | ||
v.extrude \ | ||
v.fill.holes \ | ||
v.generalize \ | ||
v.hull \ | ||
v.info \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
MODULE_TOPDIR = ../.. | ||
|
||
PGM = v.fill.holes | ||
|
||
LIBES = $(VECTORLIB) $(DBMILIB) $(GISLIB) | ||
DEPENDENCIES = $(VECTORDEP) $(DBMIDEP) $(GISDEP) | ||
EXTRA_INC = $(VECT_INC) | ||
EXTRA_CFLAGS = $(VECT_CFLAGS) | ||
|
||
include $(MODULE_TOPDIR)/include/Make/Module.make | ||
|
||
default: cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,301 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Graphics for Documentation of _v.fill.holes_\n", | ||
"\n", | ||
"Requires _pngquant_, _optipng_ and _ImageMagic_ (_mogrify_, _montage_)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import sys\n", | ||
"\n", | ||
"from IPython.display import Image\n", | ||
"\n", | ||
"import grass.script as gs\n", | ||
"import grass.jupyter as gj" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gj.init(\"~/grassdata/nc_spm_08_grass7/user1\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Explanation Plots" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Use data and import code from tests.\n", | ||
"sys.path.append(\"./tests\")\n", | ||
"import conftest\n", | ||
"from pathlib import Path" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"work_dir = Path(\".\")\n", | ||
"conftest.import_data(\n", | ||
" path=work_dir,\n", | ||
" areas_name=\"data\",\n", | ||
" areas_with_space_in_between=\"dissolve_data\",\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!v.fill.holes input=data output=data_filled" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!g.region vector=data grow=3 res=1\n", | ||
"text_position = (75,5)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"plot = gj.Map(use_region=True, width=700)\n", | ||
"plot.d_background(color=\"white\")\n", | ||
"plot.d_vect(map=\"data\")\n", | ||
"plot.d_text(at=text_position, color=\"black\", text=\"(a) Original\")\n", | ||
"plot.save(\"original.png\")\n", | ||
"plot.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"plot = gj.Map(use_region=True, width=700)\n", | ||
"plot.d_background(color=\"white\")\n", | ||
"plot.d_vect(map=\"data_filled\")\n", | ||
"plot.d_text(at=text_position, color=\"black\", text=\"(b) Filled\")\n", | ||
"plot.save(\"new.png\")\n", | ||
"plot.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"example_1 = \"v_fill_holes_filled.png\"\n", | ||
"!montage original.png new.png -tile 2x1 -geometry +0+0 {example_1}\n", | ||
"Image(example_1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!v.fill.holes input=dissolve_data output=dissolve_data_filled\n", | ||
"!v.db.update map=dissolve_data column=name value=\"area\"\n", | ||
"!v.dissolve input=dissolve_data output=dissolved_data column=name\n", | ||
"!v.fill.holes input=dissolved_data output=dissolved_data_filled" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!g.region vector=dissolve_data grow=2 res=1\n", | ||
"\n", | ||
"text_position = (75,5)\n", | ||
"\n", | ||
"plot = gj.Map(use_region=True, width=700)\n", | ||
"plot.d_background(color=\"white\")\n", | ||
"plot.d_vect(map=\"dissolve_data\")\n", | ||
"plot.d_text(at=text_position, color=\"black\", text=\"(a) Original\")\n", | ||
"plot.save(\"original.png\")\n", | ||
"\n", | ||
"plot = gj.Map(use_region=True, width=700)\n", | ||
"plot.d_background(color=\"white\")\n", | ||
"plot.d_vect(map=\"dissolve_data_filled\")\n", | ||
"plot.d_text(at=text_position, color=\"black\", text=\"() Filled without dissolve\")\n", | ||
"plot.save(\"not_working.png\")\n", | ||
"\n", | ||
"plot = gj.Map(use_region=True, width=700)\n", | ||
"plot.d_background(color=\"white\")\n", | ||
"plot.d_vect(map=\"dissolved_data\")\n", | ||
"plot.d_text(at=text_position, color=\"black\", text=\"(b) Dissloved\")\n", | ||
"plot.save(\"dissolved.png\")\n", | ||
"\n", | ||
"plot = gj.Map(use_region=True, width=700)\n", | ||
"plot.d_background(color=\"white\")\n", | ||
"plot.d_vect(map=\"dissolved_data_filled\")\n", | ||
"plot.d_text(at=text_position, color=\"black\", text=\"(c) Filled\")\n", | ||
"plot.save(\"filled.png\")\n", | ||
"\n", | ||
"example_2 = \"v_fill_holes_filled_with_dissolve.png\"\n", | ||
"!montage original.png dissolved.png filled.png -tile 3x1 -geometry +0+0 {example_2}\n", | ||
"Image(example_2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Example" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!v.extract --overwrite input=lakes where=\"FTYPE != 'ROCK/ISLAND'\" output=lakes_only --qq" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!g.region n=243300 s=242950 w=647200 e=648000" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"plot = gj.Map(use_region=True, width=700)\n", | ||
"plot.d_background(color=\"white\")\n", | ||
"plot.d_vect(map=\"lakes_only\", legend_label=\"Original\")\n", | ||
"plot.d_legend_vect(flags=\"b\", at=(60,10))\n", | ||
"plot.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!v.fill.holes input=lakes_only output=lakes_filled" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"plot = gj.Map(use_region=True, width=700)\n", | ||
"plot.d_background(color=\"white\")\n", | ||
"plot.d_vect(map=\"lakes_filled\", legend_label=\"Filled\")\n", | ||
"plot.d_legend_vect(flags=\"b\", at=(60,10))\n", | ||
"plot.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!v.dissolve input=lakes_filled column=NAME output=lakes_dissolved --qq" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"plot = gj.Map(use_region=True, width=700)\n", | ||
"plot.d_background(color=\"white\")\n", | ||
"plot.d_vect(map=\"lakes_dissolved\", legend_label=\"Dissolved\")\n", | ||
"plot.d_legend_vect(flags=\"b\", at=(60,10))\n", | ||
"plot.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"plot = gj.Map(use_region=True, width=1024)\n", | ||
"plot.d_background(color=\"#E28A2B\")\n", | ||
"plot.d_vect(map=\"lakes_filled\", color=\"none\", fill_color=\"#384C6B\", legend_label=\"Filled\")\n", | ||
"plot.d_vect(map=\"lakes_only\", color=\"#859BBA\", fill_color=\"none\", width=2, legend_label=\"Original\")\n", | ||
"plot.d_legend_vect(flags=\"b\", at=(80,85), fontsize=22, symbol_size=35)\n", | ||
"filename = \"v_fill_holes.png\"\n", | ||
"plot.save(filename)\n", | ||
"!mogrify -trim {filename}\n", | ||
"!pngquant --ext \".png\" -f {filename}\n", | ||
"!optipng -o7 {filename}\n", | ||
"Image(filename)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.