将AOI分割成多个任务的实用程序。
项目描述
FMTM Splitter
将AOI分割成多个任务的实用程序。
📖 文档: https://hotosm.github.io/fmtm-splitter/
🖥️ 源代码: https://github.com/hotosm/fmtm-splitter
这是一个使用各种算法将多边形分割成任务的程序。它是一个可以被其他项目使用的类,同时也是一个独立的程序。最初是为FMTM项目开发的,但后来进行了转换,使其可以被多个项目使用。
该类接受GeoJson Polygon作为输入,并返回所有任务边界的GeoJson文件多边形。
安装
要安装fmtm-splitter,您可以使用pip。这里有两种选择
-
直接从主分支:
pip install git+https://github.com/hotosm/fmtm-splitter.git
-
PyPi上的最新版本:
pip install fmtm-splitter
分割类型
按方形分割
默认情况下,将多边形分割成正方形。默认尺寸为50米,但可配置。外部正方形被裁剪到AOI边界。
按特征分割
按特征分割使用从OpenStreetMap提取的高速公路数据,并用于生成非正方形任务边界。也可以调整以使用任务中的建筑数量来调整其大小。
自定义SQL查询
还可以提供自定义SQL查询来生成任务。
在代码中的使用
- 可以直接使用FMTMSplitter类,或者使用包装/辅助函数进行分割。
按正方形
import json
from fmtm_splitter.splitter import split_by_square
aoi = json.load("/path/to/file.geojson")
split_features = split_by_square(
aoi,
meters=100,
)
FMTM分割算法
import json
from fmtm_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,
)
数据库连接
- db参数可以是启动新连接的连接字符串。
- 或者可以重用现有的数据库连接。
- 为此,必须传递psycopg2连接或SQLAlchemy会话
SQLAlchemy示例
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from fmtm_splitter.splitter import split_by_sql
# Creates a SQLAlchemy Session object
engine = create_engine("postgresql://postgres:postgres@localhost/postgres")
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
db = SessionLocal()
# Then pass this object as the db param
split_features = split_by_sql(
aoi,
db,
num_buildings=50,
osm_extract=osm_extracts,
)
psycopg2示例
import psycopg2
from fmtm_splitter.splitter import split_by_sql
db = psycopg2.connect("postgresql://postgres:postgres@localhost/postgres")
split_features = split_by_sql(
aoi,
db,
num_buildings=50,
osm_extract=osm_extracts,
)
通过CLI使用
选项
-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
此程序分割多边形(兴趣区域)。现有数据的数据源可以是XLSForm使用的数据提取,也可以是postgresql数据库。
示例
fmtm-splitter -b AOI
fmtm-splitter -v -b AOI -s data.geojson
fmtm-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
使用容器镜像
- fmtm-splitter脚本可以通过预构建的容器镜像使用。
- 这些镜像包含所有依赖项捆绑,因此易于运行。
- 但是,它们需要一个数据库,因此我们使用docker compose。
运行特定命令
docker compose run --rm splitter fmtm-splitter <flags>
交互式运行(以使用多个命令)
docker compose run -it splitter bash
fmtm-splitter
注意:此存储库中的
output
目录挂载到容器中的/data/output
。要持久化数据,输入和输出应放置在此处。
项目详情
下载文件
下载适合您平台文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分发
构建分发
fmtm-splitter-1.3.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 90b739df69c1ab8ad18d615423ef230665e0b43b94c3e6c1ce345f8e4021e18f |
|
MD5 | 14f1a0c6c8fc0e32a6700551a83d7a0c |
|
BLAKE2b-256 | 55d741ae225d7553a561e27dcfc644e5bd08425426708fb06af2167f12acaadf |