raster2poly 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- raster2poly-0.1.0/.github/workflows/ci.yml +43 -0
- raster2poly-0.1.0/.github/workflows/release.yml +176 -0
- raster2poly-0.1.0/.gitignore +207 -0
- raster2poly-0.1.0/.readthedocs.yaml +15 -0
- raster2poly-0.1.0/LICENSE +21 -0
- raster2poly-0.1.0/PKG-INFO +106 -0
- raster2poly-0.1.0/README.md +75 -0
- raster2poly-0.1.0/docs/notebooks/raster2poly_cookbook.ipynb +419 -0
- raster2poly-0.1.0/docs/requirements.txt +6 -0
- raster2poly-0.1.0/docs/source/api.rst +8 -0
- raster2poly-0.1.0/docs/source/changelog.rst +17 -0
- raster2poly-0.1.0/docs/source/conf.py +49 -0
- raster2poly-0.1.0/docs/source/contributing.rst +58 -0
- raster2poly-0.1.0/docs/source/cookbook.rst +12 -0
- raster2poly-0.1.0/docs/source/index.rst +56 -0
- raster2poly-0.1.0/docs/source/installation.rst +48 -0
- raster2poly-0.1.0/docs/source/introduction.rst +74 -0
- raster2poly-0.1.0/docs/source/methods.rst +170 -0
- raster2poly-0.1.0/docs/source/quickstart.rst +48 -0
- raster2poly-0.1.0/examples/raster2poly_cookbook.ipynb +419 -0
- raster2poly-0.1.0/pyproject.toml +50 -0
- raster2poly-0.1.0/src/raster2poly/__init__.py +9 -0
- raster2poly-0.1.0/src/raster2poly/classifier.py +547 -0
- raster2poly-0.1.0/tests/test_classifier.py +88 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install
|
|
25
|
+
run: pip install ".[dev]"
|
|
26
|
+
|
|
27
|
+
- name: Run tests
|
|
28
|
+
run: pytest --tb=short -q
|
|
29
|
+
|
|
30
|
+
lint:
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@v4
|
|
34
|
+
|
|
35
|
+
- uses: actions/setup-python@v5
|
|
36
|
+
with:
|
|
37
|
+
python-version: "3.12"
|
|
38
|
+
|
|
39
|
+
- name: Install ruff
|
|
40
|
+
run: pip install ruff
|
|
41
|
+
|
|
42
|
+
- name: Lint
|
|
43
|
+
run: ruff check src/
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
name: release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "[0-9]+.[0-9]+.[0-9]+"
|
|
7
|
+
- "[0-9]+.[0-9]+.[0-9]+a[0-9]+"
|
|
8
|
+
- "[0-9]+.[0-9]+.[0-9]+b[0-9]+"
|
|
9
|
+
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
|
|
10
|
+
|
|
11
|
+
env:
|
|
12
|
+
PACKAGE_NAME: "raster2poly"
|
|
13
|
+
OWNER: "geoharkat"
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
# ── 1. Extract version from git tag ──
|
|
17
|
+
details:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
outputs:
|
|
20
|
+
new_version: ${{ steps.release.outputs.new_version }}
|
|
21
|
+
suffix: ${{ steps.release.outputs.suffix }}
|
|
22
|
+
tag_name: ${{ steps.release.outputs.tag_name }}
|
|
23
|
+
is_prerelease: ${{ steps.release.outputs.is_prerelease }}
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
|
|
27
|
+
- name: Extract tag and details
|
|
28
|
+
id: release
|
|
29
|
+
run: |
|
|
30
|
+
if [ "${{ github.ref_type }}" != "tag" ]; then
|
|
31
|
+
echo "::error::No tag found"
|
|
32
|
+
exit 1
|
|
33
|
+
fi
|
|
34
|
+
TAG_NAME=${GITHUB_REF#refs/tags/}
|
|
35
|
+
NEW_VERSION=$(echo "$TAG_NAME" | grep -oP '^[0-9]+\.[0-9]+\.[0-9]+')
|
|
36
|
+
SUFFIX=$(echo "$TAG_NAME" | grep -oP '[a-z]+[0-9]+$' || echo "")
|
|
37
|
+
IS_PRE=$( [ -n "$SUFFIX" ] && echo "true" || echo "false" )
|
|
38
|
+
|
|
39
|
+
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
|
|
40
|
+
echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT"
|
|
41
|
+
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
|
|
42
|
+
echo "is_prerelease=$IS_PRE" >> "$GITHUB_OUTPUT"
|
|
43
|
+
|
|
44
|
+
echo "### Release details" >> "$GITHUB_STEP_SUMMARY"
|
|
45
|
+
echo "| Key | Value |" >> "$GITHUB_STEP_SUMMARY"
|
|
46
|
+
echo "|-----|-------|" >> "$GITHUB_STEP_SUMMARY"
|
|
47
|
+
echo "| Tag | \`$TAG_NAME\` |" >> "$GITHUB_STEP_SUMMARY"
|
|
48
|
+
echo "| Version | \`$NEW_VERSION\` |" >> "$GITHUB_STEP_SUMMARY"
|
|
49
|
+
echo "| Suffix | \`${SUFFIX:-none}\` |" >> "$GITHUB_STEP_SUMMARY"
|
|
50
|
+
echo "| Pre-release | $IS_PRE |" >> "$GITHUB_STEP_SUMMARY"
|
|
51
|
+
|
|
52
|
+
# ── 2. Guard: version must be newer than PyPI ──
|
|
53
|
+
check_pypi:
|
|
54
|
+
needs: details
|
|
55
|
+
runs-on: ubuntu-latest
|
|
56
|
+
steps:
|
|
57
|
+
- name: Fetch latest version from PyPI
|
|
58
|
+
id: pypi
|
|
59
|
+
run: |
|
|
60
|
+
RESPONSE=$(curl -sf "https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json" || echo '{}')
|
|
61
|
+
LATEST=$(echo "$RESPONSE" | jq -r 'select(.info != null) | .info.version // "0.0.0"')
|
|
62
|
+
echo "latest=$LATEST" >> "$GITHUB_OUTPUT"
|
|
63
|
+
echo "Latest PyPI version: $LATEST"
|
|
64
|
+
|
|
65
|
+
- name: Compare versions
|
|
66
|
+
run: |
|
|
67
|
+
NEW="${{ needs.details.outputs.new_version }}"
|
|
68
|
+
OLD="${{ steps.pypi.outputs.latest }}"
|
|
69
|
+
HIGHER=$(printf '%s\n' "$OLD" "$NEW" | sort -V | tail -1)
|
|
70
|
+
if [ "$HIGHER" = "$OLD" ] && [ "$NEW" != "$OLD" ] || [ "$NEW" = "$OLD" ]; then
|
|
71
|
+
echo "::error::$NEW is not newer than $OLD on PyPI"
|
|
72
|
+
exit 1
|
|
73
|
+
fi
|
|
74
|
+
echo "$NEW > $OLD ✓"
|
|
75
|
+
|
|
76
|
+
# ── 3. Build, test, package ──
|
|
77
|
+
build:
|
|
78
|
+
needs: [details, check_pypi]
|
|
79
|
+
runs-on: ubuntu-latest
|
|
80
|
+
strategy:
|
|
81
|
+
matrix:
|
|
82
|
+
python-version: ["3.10", "3.12"]
|
|
83
|
+
steps:
|
|
84
|
+
- uses: actions/checkout@v4
|
|
85
|
+
with:
|
|
86
|
+
fetch-depth: 0
|
|
87
|
+
|
|
88
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
89
|
+
uses: actions/setup-python@v5
|
|
90
|
+
with:
|
|
91
|
+
python-version: ${{ matrix.python-version }}
|
|
92
|
+
|
|
93
|
+
- name: Install build tools
|
|
94
|
+
run: pip install hatch hatchling build twine
|
|
95
|
+
|
|
96
|
+
- name: Install package with dev extras
|
|
97
|
+
run: pip install ".[dev]"
|
|
98
|
+
|
|
99
|
+
- name: Run tests
|
|
100
|
+
run: pytest --tb=short -q
|
|
101
|
+
|
|
102
|
+
- name: Build sdist + wheel
|
|
103
|
+
if: matrix.python-version == '3.12'
|
|
104
|
+
run: python -m build
|
|
105
|
+
|
|
106
|
+
- name: Verify distributions
|
|
107
|
+
if: matrix.python-version == '3.12'
|
|
108
|
+
run: twine check dist/*
|
|
109
|
+
|
|
110
|
+
- name: Upload build artifacts
|
|
111
|
+
if: matrix.python-version == '3.12'
|
|
112
|
+
uses: actions/upload-artifact@v4
|
|
113
|
+
with:
|
|
114
|
+
name: dist
|
|
115
|
+
path: dist/
|
|
116
|
+
|
|
117
|
+
# ── 4. Publish to PyPI (trusted publisher) ──
|
|
118
|
+
pypi_publish:
|
|
119
|
+
name: Publish to PyPI
|
|
120
|
+
needs: [build, details]
|
|
121
|
+
runs-on: ubuntu-latest
|
|
122
|
+
environment:
|
|
123
|
+
name: release
|
|
124
|
+
url: https://pypi.org/project/${{ env.PACKAGE_NAME }}/${{ needs.details.outputs.new_version }}/
|
|
125
|
+
permissions:
|
|
126
|
+
id-token: write
|
|
127
|
+
steps:
|
|
128
|
+
- name: Download artifacts
|
|
129
|
+
uses: actions/download-artifact@v4
|
|
130
|
+
with:
|
|
131
|
+
name: dist
|
|
132
|
+
path: dist/
|
|
133
|
+
|
|
134
|
+
- name: Publish to PyPI
|
|
135
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
136
|
+
|
|
137
|
+
# ── 5. Create GitHub Release ──
|
|
138
|
+
github_release:
|
|
139
|
+
name: GitHub Release
|
|
140
|
+
needs: [build, details]
|
|
141
|
+
runs-on: ubuntu-latest
|
|
142
|
+
permissions:
|
|
143
|
+
contents: write
|
|
144
|
+
steps:
|
|
145
|
+
- uses: actions/checkout@v4
|
|
146
|
+
with:
|
|
147
|
+
fetch-depth: 0
|
|
148
|
+
|
|
149
|
+
- name: Download artifacts
|
|
150
|
+
uses: actions/download-artifact@v4
|
|
151
|
+
with:
|
|
152
|
+
name: dist
|
|
153
|
+
path: dist/
|
|
154
|
+
|
|
155
|
+
- name: Generate changelog
|
|
156
|
+
id: changelog
|
|
157
|
+
run: |
|
|
158
|
+
# Get commits since last tag
|
|
159
|
+
PREV_TAG=$(git tag --sort=-v:refname | head -2 | tail -1 || echo "")
|
|
160
|
+
if [ -n "$PREV_TAG" ]; then
|
|
161
|
+
NOTES=$(git log --pretty=format:"- %s (%h)" "$PREV_TAG"..HEAD)
|
|
162
|
+
else
|
|
163
|
+
NOTES=$(git log --pretty=format:"- %s (%h)" HEAD~20..HEAD)
|
|
164
|
+
fi
|
|
165
|
+
# Write to file (handles multiline)
|
|
166
|
+
echo "$NOTES" > /tmp/changelog.md
|
|
167
|
+
echo "Generated $(echo "$NOTES" | wc -l) changelog entries"
|
|
168
|
+
|
|
169
|
+
- name: Create GitHub Release
|
|
170
|
+
env:
|
|
171
|
+
GH_TOKEN: ${{ github.token }}
|
|
172
|
+
run: |
|
|
173
|
+
gh release create "${{ needs.details.outputs.tag_name }}" dist/* \
|
|
174
|
+
--title "v${{ needs.details.outputs.tag_name }}" \
|
|
175
|
+
--notes-file /tmp/changelog.md \
|
|
176
|
+
${{ needs.details.outputs.is_prerelease == 'true' && '--prerelease' || '' }}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ismail Harkat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: raster2poly
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Classify rasters (KMeans, Random Forest, DN rules) and vectorise to polygons.
|
|
5
|
+
Project-URL: Homepage, https://github.com/geoharkat/raster2poly
|
|
6
|
+
Project-URL: Documentation, https://raster2poly.readthedocs.io
|
|
7
|
+
Project-URL: Issues, https://github.com/geoharkat/raster2poly/issues
|
|
8
|
+
Author: Ismail Harkat
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: classification,geospatial,polygons,raster,remote-sensing,vectorise
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Requires-Dist: geopandas>=0.12
|
|
19
|
+
Requires-Dist: numpy>=1.22
|
|
20
|
+
Requires-Dist: rasterio>=1.3
|
|
21
|
+
Requires-Dist: scikit-learn>=1.2
|
|
22
|
+
Requires-Dist: shapely>=2.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
25
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
26
|
+
Provides-Extra: docs
|
|
27
|
+
Requires-Dist: myst-parser>=2.0; extra == 'docs'
|
|
28
|
+
Requires-Dist: sphinx-rtd-theme>=2.0; extra == 'docs'
|
|
29
|
+
Requires-Dist: sphinx>=7.0; extra == 'docs'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# raster2poly
|
|
33
|
+
|
|
34
|
+
**Classify rasters and vectorise the result to clean polygons** — in three lines of code.
|
|
35
|
+
|
|
36
|
+
Supports unsupervised clustering (KMeans), supervised classification
|
|
37
|
+
(Random Forest from ROI shapefiles), and rule-based DN thresholds.
|
|
38
|
+
Outputs are dissolved, filtered GeoDataFrames ready for GIS.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install raster2poly
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quick start
|
|
47
|
+
|
|
48
|
+
### Unsupervised (KMeans)
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from raster2poly import RasterClassifier
|
|
52
|
+
|
|
53
|
+
clf = RasterClassifier("satellite_image.tif")
|
|
54
|
+
gdf = clf.unsupervised(n_clusters=6, algorithm="mini_batch_kmeans")
|
|
55
|
+
clf.save(gdf, "classes.gpkg")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Supervised (ROI shapefile)
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
gdf = clf.supervised("training_rois.shp", class_col="class_id")
|
|
62
|
+
clf.save(gdf, "supervised.shp")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The ROI file can contain **Points or Polygons** (or both).
|
|
66
|
+
For polygons, every pixel inside the geometry is used as a training
|
|
67
|
+
sample — far more robust than a single zonal mean.
|
|
68
|
+
|
|
69
|
+
### Rule-based (DN ranges)
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
rules = {
|
|
73
|
+
1: [(4, 0.15, 1.0), (5, 0.0, 0.10)], # high Red, low NIR → built-up
|
|
74
|
+
2: [(5, 0.25, 1.0)], # high NIR → vegetation
|
|
75
|
+
}
|
|
76
|
+
gdf = clf.from_dn_ranges(rules)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Band numbers are **1-based**. A pixel must satisfy *all* conditions
|
|
80
|
+
in the list to be assigned that class.
|
|
81
|
+
|
|
82
|
+
## Key improvements over the original script
|
|
83
|
+
|
|
84
|
+
| Issue in original | Fix |
|
|
85
|
+
|---|---|
|
|
86
|
+
| `point_query` returns wrong shape for multi-band | Replaced with per-pixel rasterised extraction |
|
|
87
|
+
| Only zonal *mean* used for polygon ROIs | Every pixel inside the polygon is a training sample |
|
|
88
|
+
| Hardcoded `'class'` column name | Configurable `class_col` parameter |
|
|
89
|
+
| No polygon dissolve — millions of tiny fragments | `dissolve=True` by default, plus `min_area` filter |
|
|
90
|
+
| `rasterstats` dependency for simple ops | Replaced with `rasterio.features.geometry_mask` |
|
|
91
|
+
| No CRS check on ROI shapefile | Auto-reprojects vector → raster CRS |
|
|
92
|
+
| Output always Shapefile | Auto-detects `.shp` / `.gpkg` / `.geojson` |
|
|
93
|
+
| No nodata → NaN conversion | Nodata replaced with NaN on load, masked throughout |
|
|
94
|
+
|
|
95
|
+
## Output format
|
|
96
|
+
|
|
97
|
+
The returned `GeoDataFrame` has two columns:
|
|
98
|
+
|
|
99
|
+
- `class_id` (int) — the class label
|
|
100
|
+
- `geometry` — dissolved polygons
|
|
101
|
+
|
|
102
|
+
Save to any format: `.shp`, `.gpkg`, `.geojson`.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# raster2poly
|
|
2
|
+
|
|
3
|
+
**Classify rasters and vectorise the result to clean polygons** — in three lines of code.
|
|
4
|
+
|
|
5
|
+
Supports unsupervised clustering (KMeans), supervised classification
|
|
6
|
+
(Random Forest from ROI shapefiles), and rule-based DN thresholds.
|
|
7
|
+
Outputs are dissolved, filtered GeoDataFrames ready for GIS.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install raster2poly
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
### Unsupervised (KMeans)
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from raster2poly import RasterClassifier
|
|
21
|
+
|
|
22
|
+
clf = RasterClassifier("satellite_image.tif")
|
|
23
|
+
gdf = clf.unsupervised(n_clusters=6, algorithm="mini_batch_kmeans")
|
|
24
|
+
clf.save(gdf, "classes.gpkg")
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Supervised (ROI shapefile)
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
gdf = clf.supervised("training_rois.shp", class_col="class_id")
|
|
31
|
+
clf.save(gdf, "supervised.shp")
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The ROI file can contain **Points or Polygons** (or both).
|
|
35
|
+
For polygons, every pixel inside the geometry is used as a training
|
|
36
|
+
sample — far more robust than a single zonal mean.
|
|
37
|
+
|
|
38
|
+
### Rule-based (DN ranges)
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
rules = {
|
|
42
|
+
1: [(4, 0.15, 1.0), (5, 0.0, 0.10)], # high Red, low NIR → built-up
|
|
43
|
+
2: [(5, 0.25, 1.0)], # high NIR → vegetation
|
|
44
|
+
}
|
|
45
|
+
gdf = clf.from_dn_ranges(rules)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Band numbers are **1-based**. A pixel must satisfy *all* conditions
|
|
49
|
+
in the list to be assigned that class.
|
|
50
|
+
|
|
51
|
+
## Key improvements over the original script
|
|
52
|
+
|
|
53
|
+
| Issue in original | Fix |
|
|
54
|
+
|---|---|
|
|
55
|
+
| `point_query` returns wrong shape for multi-band | Replaced with per-pixel rasterised extraction |
|
|
56
|
+
| Only zonal *mean* used for polygon ROIs | Every pixel inside the polygon is a training sample |
|
|
57
|
+
| Hardcoded `'class'` column name | Configurable `class_col` parameter |
|
|
58
|
+
| No polygon dissolve — millions of tiny fragments | `dissolve=True` by default, plus `min_area` filter |
|
|
59
|
+
| `rasterstats` dependency for simple ops | Replaced with `rasterio.features.geometry_mask` |
|
|
60
|
+
| No CRS check on ROI shapefile | Auto-reprojects vector → raster CRS |
|
|
61
|
+
| Output always Shapefile | Auto-detects `.shp` / `.gpkg` / `.geojson` |
|
|
62
|
+
| No nodata → NaN conversion | Nodata replaced with NaN on load, masked throughout |
|
|
63
|
+
|
|
64
|
+
## Output format
|
|
65
|
+
|
|
66
|
+
The returned `GeoDataFrame` has two columns:
|
|
67
|
+
|
|
68
|
+
- `class_id` (int) — the class label
|
|
69
|
+
- `geometry` — dissolved polygons
|
|
70
|
+
|
|
71
|
+
Save to any format: `.shp`, `.gpkg`, `.geojson`.
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|