spatial-filtering
Apply django-rest-framework-gis spatial filter backends, geometry filter sets, tile and bbox query parameters, distance predicates, and distance ordering safely in DRF views.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- spatial-filtering
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Apply django-rest-framework-gis spatial filter backends, geometry filter sets, tile and bbox query parameters, distance predicates, and distance ordering safely in DRF views.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md9.1 KB
- 参考文档references/troubleshooting.md7.9 KB
- 参考文档references/workflows.md6.9 KB
- 脚本scripts/tile_bbox.py1.6 KB
03 SKILL.md 正文
Spatial filtering
Use this skill when a DRF endpoint must filter or order spatial model rows from URL query parameters. The public filter classes are exposed from rest_framework_gis.filters (and GeoFilterSet is also re-exported by rest_framework_gis.filterset). Start with references/api-reference.md for exact parameters, defaults, view attributes, and schema declarations; use references/workflows.md for view and filter-set recipes; use references/troubleshooting.md for malformed input and spatial-backend failures.
Route the request
- Use
InBBoxFilterforin_bbox=min_lon,min_lat,max_lon,max_lat. It usescontainedunless the view opts intobboverlapswithbbox_filter_include_overlapping = True. - Use
TMSTileFilterfortile=Z/X/Y. It converts a TMS tile whose Y origin is the upper left into the same bbox predicate asInBBoxFilter. - Use
GeometryFilterwithGeoFilterSetandDjangoFilterBackendfor django-filter geometry lookups such ascontains,contains_properly, orwithin. - Use
DistanceToPointFilterforpoint=x,yand optionaldist; configuredistance_filter_fieldand decide explicitly whether the input distance is database units or metres. - Use
DistanceToPointOrderingFilterfor nearest/farthest ordering withpoint=x,y,distance_ordering_filter_field, and optionalorder=desc. It uses a point with SRID 4326 andGeometryDistance; it is not a substitute for the dwithin filter.
Operating sequence
- Confirm the queryset field is a GeoDjango geometry field and identify its SRID and database units.
- Add the selected backend to the view's
filter_backendsand set the matching field attribute. If the attribute is absent or false, that backend intentionally returns the queryset unchanged. - Treat query coordinates as
x,y= longitude/easting then latitude/northing. Treat bbox coordinates as west/south/east/north. - Let malformed bbox, tile, point, and distance values surface as DRF
ParseErrorresponses; do not silently coerce invalid input. - Test the ORM predicate against the actual spatial database. GEOS parsing/import smoke tests do not prove that
contained,bboverlaps,dwithin, orGeometryDistanceexecute on the production database.
Minimal contracts
from rest_framework import generics
from rest_framework_gis.filters import InBBoxFilter
class PlaceList(generics.ListAPIView):
queryset = Place.objects.all()
serializer_class = PlaceSerializer
bbox_filter_field = "geometry"
filter_backends = (InBBoxFilter,)
from rest_framework_gis.filters import DistanceToPointFilter
class NearbyPlaceList(generics.ListAPIView):
queryset = Place.objects.all()
serializer_class = PlaceSerializer
distance_filter_field = "geometry"
distance_filter_convert_meters = True # only for a WGS84 degree field
filter_backends = (DistanceToPointFilter,)
The filter backends only construct/query geometry predicates. Route GeoJSON serializer output to the serialization skill, generated parameter/schema integration to pagination-and-schema, and end-to-end database/backend checks to integration-testing.
Bundled utility
From the runtime skill root, use
python sub-skills/spatial-filtering/scripts/tile_bbox.py --help or
python sub-skills/spatial-filtering/scripts/tile_bbox.py Z X Y to calculate a
tile's west/south/east/north JSON. The utility is self-contained and does
not require the application checkout. It is a coordinate/debugging aid, not a replacement for executing the ORM filter.
Hard warning
Every ORM predicate described here requires a spatially capable database and compatible geometry operations. The current production verified package/module imports and geometry smoke only; it did not verify PostGIS execution. Do not represent PostGIS behavior as verified without running the integration checks in the target environment.
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).