AGENT SKILL

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

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 InBBoxFilter for in_bbox=min_lon,min_lat,max_lon,max_lat. It uses contained unless the view opts into bboverlaps with bbox_filter_include_overlapping = True.
  • Use TMSTileFilter for tile=Z/X/Y. It converts a TMS tile whose Y origin is the upper left into the same bbox predicate as InBBoxFilter.
  • Use GeometryFilter with GeoFilterSet and DjangoFilterBackend for django-filter geometry lookups such as contains, contains_properly, or within.
  • Use DistanceToPointFilter for point=x,y and optional dist; configure distance_filter_field and decide explicitly whether the input distance is database units or metres.
  • Use DistanceToPointOrderingFilter for nearest/farthest ordering with point=x,y, distance_ordering_filter_field, and optional order=desc. It uses a point with SRID 4326 and GeometryDistance; it is not a substitute for the dwithin filter.

Operating sequence

  1. Confirm the queryset field is a GeoDjango geometry field and identify its SRID and database units.
  2. Add the selected backend to the view's filter_backends and set the matching field attribute. If the attribute is absent or false, that backend intentionally returns the queryset unchanged.
  3. Treat query coordinates as x,y = longitude/easting then latitude/northing. Treat bbox coordinates as west/south/east/north.
  4. Let malformed bbox, tile, point, and distance values surface as DRF ParseError responses; do not silently coerce invalid input.
  5. Test the ORM predicate against the actual spatial database. GEOS parsing/import smoke tests do not prove that contained, bboverlaps, dwithin, or GeometryDistance execute 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

VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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).

★ 351