| 1 |
import re |
| 2 |
|
| 3 |
from django.contrib.gis.db import models |
| 4 |
|
| 5 |
|
| 6 |
class BaseSpatialFeatures: |
| 7 |
gis_enabled = True |
| 8 |
|
| 9 |
# Does the database contain a SpatialRefSys model to store SRID information? |
| 10 |
has_spatialrefsys_table = True |
| 11 |
|
| 12 |
# Does the backend support the django.contrib.gis.utils.add_srs_entry() utility? |
| 13 |
supports_add_srs_entry = True |
| 14 |
# Does the backend introspect GeometryField to its subtypes? |
| 15 |
supports_geometry_field_introspection = True |
| 16 |
|
| 17 |
# Does the database have a geography type? |
| 18 |
supports_geography = False |
| 19 |
# Does the backend support storing 3D geometries? |
| 20 |
supports_3d_storage = False |
| 21 |
# Reference implementation of 3D functions is: |
| 22 |
# https://postgis.net/docs/PostGIS_Special_Functions_Index.html#PostGIS_3D_Functions |
| 23 |
supports_3d_functions = False |
| 24 |
# Does the database support SRID transform operations? |
| 25 |
supports_transform = True |
| 26 |
# Can geometry fields be null? |
| 27 |
supports_null_geometries = True |
| 28 |
# Are empty geometries supported? |
| 29 |
supports_empty_geometries = False |
| 30 |
# Can the function be applied on geodetic coordinate systems? |
| 31 |
supports_distance_geodetic = True |
| 32 |
supports_length_geodetic = True |
| 33 |
supports_perimeter_geodetic = False |
| 34 |
supports_area_geodetic = True |
| 35 |
# Is the database able to count vertices on polygons (with `num_points`)? |
| 36 |
supports_num_points_poly = True |
| 37 |
|
| 38 |
# Does the backend support expressions for specifying distance in the |
| 39 |
# dwithin lookup? |
| 40 |
supports_dwithin_distance_expr = True |
| 41 |
|
| 42 |
# Does the database have raster support? |
| 43 |
supports_raster = False |
| 44 |
|
| 45 |
# Does the database support a unique index on geometry fields? |
| 46 |
supports_geometry_field_unique_index = True |
| 47 |
|
| 48 |
# Can SchemaEditor alter geometry fields? |
| 49 |
can_alter_geometry_field = True |
| 50 |
|
| 51 |
# Do the database functions/aggregates support the tolerance parameter? |
| 52 |
supports_tolerance_parameter = False |
| 53 |
|
| 54 |
# Set of options that AsGeoJSON() doesn't support. |
| 55 |
unsupported_geojson_options = {} |
| 56 |
|
| 57 |
# Does Intersection() return None (rather than an empty GeometryCollection) |
| 58 |
# for empty results? |
| 59 |
empty_intersection_returns_none = True |
| 60 |
|
| 61 |
@property |
| 62 |
def supports_bbcontains_lookup(self): |
| 63 |
return "bbcontains" in self.connection.ops.gis_operators |
| 64 |
|
| 65 |
@property |
| 66 |
def supports_contained_lookup(self): |
| 67 |
return "contained" in self.connection.ops.gis_operators |
| 68 |
|
| 69 |
@property |
| 70 |
def supports_crosses_lookup(self): |
| 71 |
return "crosses" in self.connection.ops.gis_operators |
| 72 |
|
| 73 |
@property |
| 74 |
def supports_distances_lookups(self): |
| 75 |
return self.has_Distance_function |
| 76 |
|
| 77 |
@property |
| 78 |
def supports_dwithin_lookup(self): |
| 79 |
return "dwithin" in self.connection.ops.gis_operators |
| 80 |
|
| 81 |
@property |
| 82 |
def supports_relate_lookup(self): |
| 83 |
return "relate" in self.connection.ops.gis_operators |
| 84 |
|
| 85 |
@property |
| 86 |
def supports_isvalid_lookup(self): |
| 87 |
return self.has_IsValid_function |
| 88 |
|
| 89 |
# Is the aggregate supported by the database? |
| 90 |
@property |
| 91 |
def supports_collect_aggr(self): |
| 92 |
return models.Collect not in self.connection.ops.disallowed_aggregates |
| 93 |
|
| 94 |
@property |
| 95 |
def supports_extent_aggr(self): |
| 96 |
return models.Extent not in self.connection.ops.disallowed_aggregates |
| 97 |
|
| 98 |
@property |
| 99 |
def supports_make_line_aggr(self): |
| 100 |
return models.MakeLine not in self.connection.ops.disallowed_aggregates |
| 101 |
|
| 102 |
@property |
| 103 |
def supports_union_aggr(self): |
| 104 |
return models.Union not in self.connection.ops.disallowed_aggregates |
| 105 |
|
| 106 |
def __getattr__(self, name): |
| 107 |
m = re.match(r"has_(\w*)_function$", name) |
| 108 |
if m: |
| 109 |
func_name = m[1] |
| 110 |
return func_name not in self.connection.ops.unsupported_functions |
| 111 |
raise AttributeError |