... ールドのバウンディングボックスが、ルックアップジオメトリのバウンディングボックスを完全に含むかどうかをテストします。 実装例: Zipcode . objects . filter ( poly__bbcontains = geom ) バックエンド 等価なSQL PostGIS poly ~ geom MariaDB MBRContains(poly, geom) ... フィールドのバウンディングボックスが、ルックアップジオメトリのバウンディングボックスと重なるかどうかをテストします。 実装例: Zipcode . objects . filter ( poly__bboverlaps = geom ) バックエンド 等価なSQL PostGIS poly && geom MariaDB MBROverlaps(poly, geom) ... ルドのバウンディングボックスがルックアップジオメトリのバウンディングボックスに完全に含まれるかどうかをテストします。 実装例: Zipcode . objects . filter ( poly__contained = geom ) バックエンド 等価なSQL PostGIS poly @ geom MariaDB MBRWithin(poly, geom) MyS ... ... ールドのバウンディングボックスが、ルックアップジオメトリのバウンディングボックスを完全に含むかどうかをテストします。 実装例: Zipcode . objects . filter ( poly__bbcontains = geom ) バックエンド 等価なSQL PostGIS poly ~ geom MariaDB MBRContains(poly, geom) ... フィールドのバウンディングボックスが、ルックアップジオメトリのバウンディングボックスと重なるかどうかをテストします。 実装例: Zipcode . objects . filter ( poly__bboverlaps = geom ) バックエンド 等価なSQL PostGIS poly && geom MariaDB MBROverlaps(poly, geom) ... ルドのバウンディングボックスがルックアップジオメトリのバウンディングボックスに完全に含まれるかどうかをテストします。 実装例: Zipcode . objects . filter ( poly__contained = geom ) バックエンド 等価なSQL PostGIS poly @ geom MariaDB MBRWithin(poly, geom) MyS ... ... 集計は実装されていません。 モデルを作成し、ジオメトリフィールドを保存する ¶ 以下にジオメトリオブジェクトの作成例を示します ( Zipcode モデルを想定): >>> from zipcode.models import Zipcode >>> z = Zipcode ( code = 77096 , poly = "POLYGON(( 10 10, 10 20, 20 ... o.contrib.gis.geos import GEOSGeometry >>> poly = GEOSGeometry ( "POLYGON(( 10 10, 10 20, 20 20, 20 15, 10 10))" ) >>> z = Zipcode ( code = 77096 , poly = poly ) >>> z . save () さらに、 GEOSGeometry がフィールドの座標系と異なる座標系 (異なる SRID 値を持 ... , 10 20, 20 20, 20 15, 10 10))" , srid = 3084 ... ) # SRID 3084 is 'NAD83(HARN) / Texas Centric Lambert Conformal' >>> z = Zipcode ( code = 78212 , poly = poly_3084 ) >>> z . save () >>> from django.db import connection >>> print ( ... connection . quer ... ... 集計は実装されていません。 モデルを作成し、ジオメトリフィールドを保存する ¶ 以下にジオメトリオブジェクトの作成例を示します ( Zipcode モデルを想定): >>> from zipcode.models import Zipcode >>> z = Zipcode ( code = 77096 , poly = "POLYGON(( 10 10, 10 20, 20 ... o.contrib.gis.geos import GEOSGeometry >>> poly = GEOSGeometry ( "POLYGON(( 10 10, 10 20, 20 20, 20 15, 10 10))" ) >>> z = Zipcode ( code = 77096 , poly = poly ) >>> z . save () さらに、 GEOSGeometry がフィールドの座標系と異なる座標系 (異なる SRID 値を持 ... , 10 20, 20 20, 20 15, 10 10))" , srid = 3084 ... ) # SRID 3084 is 'NAD83(HARN) / Texas Centric Lambert Conformal' >>> z = Zipcode ( code = 78212 , poly = poly_3084 ) >>> z . save () >>> from django.db import connection >>> print ( ... connection . quer ... ... ic model of a ZIP code and of a Digital Elevation Model as our examples: from django.contrib.gis.db import models class Zipcode ( models . Model ... ジオメトリ型に変換できます: from django.contrib.gis.db.models import PointField from django.db.models.functions import Cast Zipcode . objects . annotate ( geom = Cast ( "geography_field" , PointField ())) . filter ( geom__within = poly ) For more informa ... ... ic model of a ZIP code and of a Digital Elevation Model as our examples: from django.contrib.gis.db import models class Zipcode ( models . Model ... ジオメトリ型に変換できます: from django.contrib.gis.db.models import PointField from django.db.models.functions import Cast Zipcode . objects . annotate ( geom = Cast ( "geography_field" , PointField ())) . filter ( geom__within = poly ) For more informa ... ... 単一の地理情報フィールドまたは式を受け取り、そのジオメトリの Geographic Markup Language (GML) 表現を返します。 例: >>> qs = Zipcode . objects . annotate ( gml = AsGML ( "poly" )) >>> print ( qs [ 0 ] . gml ) <gml:Polygon srsName="EPSG:4326"><gml:OuterBou ... 、SpatiaLite 単一の地理情報フィールドまたは式を受け取り、地理情報の Keyhole Markup Language (KML) 表現を返す。 例: >>> qs = Zipcode . objects . annotate ( kml = AsKML ( "poly" )) >>> print ( qs [ 0 ] . kml ) <Polygon><outerBoundaryIs><LinearRing><coordin ... ... 単一の地理情報フィールドまたは式を受け取り、そのジオメトリの Geographic Markup Language (GML) 表現を返します。 例: >>> qs = Zipcode . objects . annotate ( gml = AsGML ( "poly" )) >>> print ( qs [ 0 ] . gml ) <gml:Polygon srsName="EPSG:4326"><gml:OuterBou ... 、SpatiaLite 単一の地理情報フィールドまたは式を受け取り、地理情報の Keyhole Markup Language (KML) 表現を返す。 例: >>> qs = Zipcode . objects . annotate ( kml = AsKML ( "poly" )) >>> print ( qs [ 0 ] . kml ) <Polygon><outerBoundaryIs><LinearRing><coordin ... ... で他のモデルクラスを参照してください。たとえば、次のようにします: from django.db import models from geography.models import ZipCode class Restaurant ( models . Model ): # ... zip_code = models . ForeignKey ( ZipCode , on_delete = models . SET_NULL , blan ... とえば: from django.db import models class Restaurant ( models . Model ): # ... zip_code = models . ForeignKey ( "geography.ZipCode" , on_delete = models . SET_NULL , blank = True , null = True , ) 詳しくは 遅延リレーションシップ を参照してください。 フィ ... ... で他のモデルクラスを参照してください。たとえば、次のようにします: from django.db import models from geography.models import ZipCode class Restaurant ( models . Model ): # ... zip_code = models . ForeignKey ( ZipCode , on_delete = models . SET_NULL , blan ... とえば: from django.db import models class Restaurant ( models . Model ): # ... zip_code = models . ForeignKey ( "geography.ZipCode" , on_delete = models . SET_NULL , blank = True , null = True , ) 詳しくは 遅延リレーションシップ を参照してください。 フィ ... 2026年10月08日