Area Splitter
A utility for splitting an AOI into multiple tasks.
📖 Documentation: https://hotosm.github.io/fmtm-splitter/
🖥️ Source Code: https://github.com/hotosm/field-tm/blob/main/src/backend/packages/area-splitter
This is a program to split polygons into tasks using a variety of algorithms. It is a class that can be used by other projects, but also a standalone program. It was originally developed for the FMTM project, but then converted so it can be used by multiple projects.
The class takes GeoJson Polygon as an input, and returns a GeoJson file Multipolygon of all the task boundaries.
Installation
pip install area-splitter
Note Postgis should have SFCGAL enabled:
CREATE EXTENSION IF NOT EXISTS postgis_sfcgal WITH SCHEMA public;
Splitting Types
Split By Square
The default is to split the polygon into squares. The default dimension is 50 meters, but that is configurable. The outer square are clipped to the AOI boundary.
Split By Feature
The split by feature uses highway data extracted from OpenStreetMap, and uses it to generate non square task boundaries. It can also be adjusted to use the number of buildings in a task to adjust it's size.
Custom SQL query
It is also possible to supply a custom SQL query to generate the tasks.
Usage In Code
- Either the FMTMSplitter class can be used directly, or the wrapper/ helper functions can be used for splitting.
By square:
import json
from area_splitter.splitter import split_by_square
aoi = json.load("/path/to/file.geojson")
split_features = split_by_square(
aoi,
meters=100,
)
The FMTM splitter algorithm:
import json
from area_splitter.splitter import split_by_sql
aoi = json.load("/path/to/file.geojson")
osm_extracts = json.load("/path/to/file.geojson")
db = "postgresql://postgres:postgres@localhost/postgres"
split_features = split_by_sql(
aoi,
db,
num_buildings=50,
osm_extract=osm_extracts,
)
Database Connections
- The db parameter can be a connection string to start a new connection.
- Or an existing database connection can be reused.
- To do this, either the psycopg connection, or a DBAPI connection string must be passed:
psycopg example:
import psycopg
from area_splitter.splitter import split_by_sql
db = psycopg.connect("postgresql://postgres:postgres@localhost/postgres")
split_features = split_by_sql(
aoi,
db,
num_buildings=50,
osm_extract=osm_extracts,
)
Usage Via CLI
Options:
-h, --help show this help message and exit
-v, --verbose verbose output
-o OUTFILE, --outfile OUTFILE Output file from splitting
-m METERS, --meters METERS Size in meters if using square splitting
-b BOUNDARY, --boundary BOUNDARY Polygon AOI
-s SOURCE, --source SOURCE Source data, Geojson or PG:[dbname]
-c CUSTOM, --custom CUSTOM Custom SQL query for database
This program splits a Polygon (the Area Of Interest) The data source for existing data can'be either the data extract used by the XLSForm, or a postgresql database.
Examples:
area-splitter -b AOI
area-splitter -v -b AOI -s data.geojson
area-splitter -v -b AOI -s PG:colorado
# Where AOI is the boundary of the project as a polygon
# And OUTFILE is a MultiPolygon output file,which defaults to fmtm.geojson
# The task splitting defaults to squares, 50 meters across
Metadata
Release files for area-splitter 3.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| area_splitter-3.0.1.tar.gz | 138.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| area_splitter-3.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 172.4 kB
Release files / area_splitter-3.0.1.tar.gz
| Download URL | area_splitter-3.0.1.tar.gz |
|---|---|
| Size | 138.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2b8f9f1fc4ae9b8419faba082cd4ef06d6766ede94d9b4ed3bfae698db7d64d
|
|
BLAKE2b-256 checksum How to use checksums |
c5742cb3591560da450e321374d339013554923f4e0884ad88e3cf1b7a84d798
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.4
|
Release files / area_splitter-3.0.1-py3-none-any.whl
| Download URL | area_splitter-3.0.1-py3-none-any.whl |
|---|---|
| Size | 34.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f6569b634dce04315f5526e350bc4e149a5462ac784788a80ace9301d525fa5
|
|
BLAKE2b-256 checksum How to use checksums |
265fd6ec6f2982836737060512de560c374d2ed8b950aa0ab50a6285cfb49e3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.4
|
Security for area-splitter 3.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.