File size: 4,766 Bytes
843b944
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
Metadata-Version: 2.4
Name: spatial-toolkit-py
Version: 0.0.1
Summary: Lightweight spatial tools for ecologists in Python
Author-email: Abhimanyu Raj Singh <abhimanyu@example.com>
License: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: folium
Requires-Dist: geopandas
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: rasterio
Requires-Dist: rioxarray
Requires-Dist: shapely
Requires-Dist: streamlit
Requires-Dist: streamlit-folium
Requires-Dist: xarray
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: build; extra == "dev"
Dynamic: license-file

# spatial_toolkit

`spatial_toolkit` is a dual-track spatial toolkit for ecologists. The repository
now carries:

- an R package plus Shiny app
- a Python package plus Streamlit app
- shared project memory and step-by-step learning notes

The intent is practical and educational at the same time: build a useful GIS
toolkit for ecology while preserving enough context that a first-time package
author can understand how the repo was assembled and maintained.

## Scope

The current scaffold includes:

- Raster and vector conversions
- Rasterisation, vectorisation, and reclassification
- Raster QC and metadata inspection
- Common ecological GIS helpers such as crop, mask, and reprojection
- Reusable workflows for repeated data processing
- A Shiny app shell for map review, metadata inspection, and attribute tables
- A Streamlit app shell for the same core use cases

## Why both R and Python

The short answer is: both is reasonable, but they should not be treated equally
at every phase.

- R is the better first implementation here because your requested GIS stack
  already maps naturally to `terra`, `sf`, `raster`, and Shiny.
- Python is worth adding because deployment, packaging, and broader data-science
  interoperability are often easier with `streamlit`, `rasterio`, `geopandas`,
  and `xarray`.
- The safest strategy is to keep one reference implementation first, then build
  a parallel implementation with the same concepts and workflows.

That is the approach this repository now follows: R is the reference track and
Python is the parallel native track.

## Product shape

The repository is structured so the same codebase can support:

- An R package
- A local or hosted Shiny app
- A Python package
- A local or hosted Streamlit app
- Reusable workflow functions for scripted batch processing

## Repository layout

- `R/`: reusable R spatial functions and Shiny app wiring
- `python/spatial_toolkit_py/`: reusable Python spatial functions
- `python/app.py`: Streamlit app entrypoint
- `inst/app/www/`: Shiny styling assets
- `tests/`: R tests
- `pytests/`: Python tests
- `memory.txt`: shared project memory and roadmap
- `memopy.txt`: Python-specific maintenance memory
- `R.md`: step-by-step notes for building the R package/app
- `PY.md`: step-by-step notes for building the Python package/app
- `Dockerfile`: container entrypoint for the R app
- `Dockerfile.py`: container entrypoint for the Python app

## R install

```r
# install.packages("pak")
pak::pak(c(
  "shiny",
  "bslib",
  "leaflet",
  "DT",
  "terra",
  "sf",
  "raster"
))
```

## Python install

```bash
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
```

## Run the R app

```r
source("app.R")
```

Or after installing as a package:

```r
spatialtoolkit::run_app()
```

Or from the shell:

```bash
bash run_shiny_local.sh
```

Local URL:

```text
http://127.0.0.1:7860
```

## Run the Python app

```bash
streamlit run python/app.py
```

Or with the fixed local port script:

```bash
bash run_streamlit_local.sh
```

Local URL:

```text
http://127.0.0.1:8501
```

## Initial workflows

The first workflow catalogs focus on raster QC:

- CRS presence
- Resolution
- Extent
- Band count
- Layer names
- Missing values
- Numeric summaries

This can be extended into ecological pre-processing pipelines such as harmonise,
crop to study area, standardise CRS, and export derivative products.

## Deployment direction

Both apps can be deployed to Hugging Face Spaces using Docker:

- `Dockerfile` for the R/Shiny track
- `Dockerfile.py` for the Python/Streamlit track

If we want one public hosted app first, Python/Streamlit is often the simpler
deployment target. If we want the strongest spatial processing foundation first,
R remains the better implementation anchor.

## Learning documents

This repository also doubles as a build log:

- [R.md](R.md) explains how the R package/app was scaffolded
- [PY.md](PY.md) explains how the Python package/app was scaffolded
- [memory.txt](memory.txt) tracks decisions, features, and dependencies
- [memopy.txt](memopy.txt) tracks Python-specific implementation notes