polygon-geospatial
Use H3Shape, LatLngPoly, LatLngMultiPoly, and the GeoJSON-like interface to rasterize polygons, holes, and multipolygons to H3 cells or turn cells back into interoperable geometry.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- polygon-geospatial
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use H3Shape, LatLngPoly, LatLngMultiPoly, and the GeoJSON-like interface to rasterize polygons, holes, and multipolygons to H3 cells or turn cells back into interoperable geometry.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md6.6 KB
- 参考文档references/troubleshooting.md8.2 KB
- 参考文档references/workflows.md6.5 KB
- 脚本scripts/validate_geojson.py11.8 KB
03 SKILL.md 正文
Polygon and geospatial shapes
Use this route for LatLngPoly, LatLngMultiPoly, GeoJSON-like dictionaries,
__geo_interface__ objects, polygon_to_cells, h3shape_to_cells,
geo_to_cells, cells_to_h3shape, and cells_to_geo. It covers holes,
multipolygons, ring normalization, CRS mistakes, and dateline-sensitive
workflows. It does not cover cell/grid/edge algorithms; use
core-indexing for those. Use
api-variants for integer, NumPy, memoryview, or
representation selection, and the root h3-py route for
installation and package-wide routing.
Coordinate and data contract
- H3 shape constructors use
(lat, lng)pairs, in degrees: latitude first, longitude second. - GeoJSON and
__geo_interface__coordinates use(lng, lat)positions. Swap exactly once at the boundary; never pass GeoJSON positions directly toLatLngPoly. - Use a geographic WGS84 / EPSG:4326 CRS before calling H3. Reproject a
projected GeoPandas/Shapely geometry with
to_crs, rather than relabeling its CRS. H3 does not interpret feet, meters, Web Mercator, or local grid coordinates as latitude/longitude. - A polygon is one outer loop followed by zero or more hole loops. A multipolygon is a sequence of such polygons. GeoJSON rings are normally closed; H3 constructors may receive open or closed loops and normalize the stored loop to open form. H3-generated GeoJSON closes rings again.
- Direct
LatLngPolypoints must be 2D. GeoJSON conversion accepts positions with extra ordinates but discards the third and later values; elevation is not preserved by an H3 shape round trip.
Operating procedure
- Identify whether the input is one polygon, several polygons, a GeoJSON
geometry, a Feature wrapper, or a library object. Extract a Feature's
geometrybeforegeo_to_h3shape; that function accepts Polygon or MultiPolygon geometry dictionaries, not Feature/FeatureCollection wrappers. - Confirm the source CRS is geographic WGS84 and inspect coordinate order.
For a library object, its
__geo_interface__is the GeoJSON-like(lng, lat)form. Validate ring closure, dimensions, finite numeric coordinates, and multipolygon nesting before converting. - Construct
LatLngPoly(outer, *holes)for one polygon. Construct each component as aLatLngPoly, then callLatLngMultiPoly(poly1, poly2, ...). Do not pass raw nested multipolygon coordinates to the latter. - Rasterize with
h3shape_to_cells(shape, res)or its aliaspolygon_to_cells(shape, res). This is centroid/center containment and output order is not guaranteed. Usegeo_to_cells(geo, res)when the input is already a Polygon/MultiPolygon geometry or implements__geo_interface__. - Convert cells back with
cells_to_h3shape(cells, tight=True)when a singleLatLngPolyis preferable, ortight=Falsewhen aLatLngMultiPolycontainer is required. Usecells_to_geofor a direct GeoJSON-like dict. Normalize unordered cell results as sets for comparisons. - At an interoperability boundary, use
h3shape_to_geo(shape, container=...)and pass only itsgeometrymember to consumers that expect a geometry. The defaultautoemits the simplest Polygon or MultiPolygon.
Containment and topology cautions
The stable shape-to-cells operation includes cells whose center is inside the
shape; it is not a guarantee of full polygon coverage or any overlap measure.
The experimental h3shape_to_cells_experimental / polygon_to_cells_experimental
functions add center, full, overlap, and bbox_overlap modes, but have no
API stability guarantee. Record the selected mode and package version when
using them.
H3 rasterization accepts outer and hole loops in either winding direction and
does not reorder user-supplied loops. GeoJSON consumers may expect the
right-hand rule (outer counterclockwise, holes clockwise), so normalize winding
with a geospatial library if exporting or plotting external geometry. Shapes
returned by cells_to_h3shape follow the right-hand rule. Keep holes inside
their own outer ring and use separate LatLngPoly objects for disjoint parts.
Treat rings crossing ±180° or enclosing a pole as difficult spherical cases. Use a valid longitude convention, test a small dateline fixture, and consider splitting a dateline-crossing GeoJSON geometry into parts before interoperability conversion. Cell-to-shape output for global, prime-meridian, or antimeridian cell bands may not round-trip through center containment; compare the recovered set explicitly rather than assuming a lossless boundary representation.
Quick recipe
import h3
outer = [(37.804, -122.412), (37.778, -122.507), (37.733, -122.501)]
hole = [(37.782, -122.449), (37.779, -122.465), (37.788, -122.454)]
shape = h3.LatLngPoly(outer, hole)
cells = h3.h3shape_to_cells(shape, res=9)
geojson_geometry = h3.h3shape_to_geo(shape)
roundtrip_shape = h3.geo_to_h3shape(geojson_geometry)
assert roundtrip_shape.__geo_interface__ == geojson_geometry
For a deterministic structural check, run:
python scripts/validate_geojson.py --help
python scripts/validate_geojson.py --self-test
Read api-reference.md for exact constructors, containers, signatures, and return types; read workflows.md for copyable recipes; and read troubleshooting.md before retrying malformed or dateline-sensitive input.
Acceptance checklist
- [ ] CRS is WGS84/EPSG:4326 and coordinates are degrees.
- [ ]
(lat, lng)is used for H3 shapes and(lng, lat)for GeoJSON. - [ ] Polygon/multipolygon nesting and Feature extraction are explicit.
- [ ] Holes are separate rings inside the outer ring; rings have sane dimensions.
- [ ] The chosen containment semantics and resolution are recorded.
- [ ] Cell order is not assumed, and mixed/duplicate cells are rejected or fixed.
- [ ] Output container (
Polygon,MultiPolygon,Feature, or collection) is intentional and suitable for the downstream consumer. - [ ] Third coordinates, winding, antimeridian behavior, and empty results are handled rather than silently assumed.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).