| 1 |
from django_filters.rest_framework import DjangoFilterBackend |
| 2 |
from rest_framework import generics |
| 3 |
|
| 4 |
from rest_framework_gis.filters import ( |
| 5 |
DistanceToPointFilter, |
| 6 |
DistanceToPointOrderingFilter, |
| 7 |
GeoFilterSet, |
| 8 |
GeometryFilter, |
| 9 |
InBBoxFilter, |
| 10 |
TMSTileFilter, |
| 11 |
) |
| 12 |
from rest_framework_gis.pagination import GeoJsonPagination |
| 13 |
|
| 14 |
from .models import ( |
| 15 |
BoxedLocation, |
| 16 |
LocatedFile, |
| 17 |
Location, |
| 18 |
Nullable, |
| 19 |
OtherSridLocation, |
| 20 |
PolygonModel, |
| 21 |
) |
| 22 |
from .serializers import ( |
| 23 |
BoxedLocationGeoFeatureSerializer, |
| 24 |
LocatedFileGeoFeatureSerializer, |
| 25 |
LocationGeoFeatureBboxSerializer, |
| 26 |
LocationGeoFeatureFalseIdSerializer, |
| 27 |
LocationGeoFeatureMethodSerializer, |
| 28 |
LocationGeoFeatureNoIdSerializer, |
| 29 |
LocationGeoFeatureSerializer, |
| 30 |
LocationGeoFeatureSlugSerializer, |
| 31 |
LocationGeoFeatureWritableIdSerializer, |
| 32 |
LocationGeoSerializer, |
| 33 |
NoGeoFeatureMethodSerializer, |
| 34 |
NoneGeoFeatureMethodSerializer, |
| 35 |
OtherSridLocationGeoSerializer, |
| 36 |
PaginatedLocationGeoSerializer, |
| 37 |
PolygonModelSerializer, |
| 38 |
) |
| 39 |
|
| 40 |
|
| 41 |
class LocationList(generics.ListCreateAPIView): |
| 42 |
model = Location |
| 43 |
serializer_class = LocationGeoSerializer |
| 44 |
queryset = Location.objects.all() |
| 45 |
pagination_class = PaginatedLocationGeoSerializer |
| 46 |
|
| 47 |
|
| 48 |
location_list = LocationList.as_view() |
| 49 |
|
| 50 |
|
| 51 |
class LocationDetails(generics.RetrieveUpdateDestroyAPIView): |
| 52 |
model = Location |
| 53 |
serializer_class = LocationGeoSerializer |
| 54 |
queryset = Location.objects.all() |
| 55 |
|
| 56 |
|
| 57 |
location_details = LocationDetails.as_view() |
| 58 |
|
| 59 |
|
| 60 |
class OtherSridLocationDetails(generics.RetrieveUpdateDestroyAPIView): |
| 61 |
model = OtherSridLocation |
| 62 |
serializer_class = OtherSridLocationGeoSerializer |
| 63 |
queryset = OtherSridLocation.objects.all() |
| 64 |
|
| 65 |
|
| 66 |
other_srid_location_details = OtherSridLocationDetails.as_view() |
| 67 |
|
| 68 |
|
| 69 |
class GeojsonLocationList(generics.ListCreateAPIView): |
| 70 |
model = Location |
| 71 |
serializer_class = LocationGeoFeatureSerializer |
| 72 |
queryset = Location.objects.all() |
| 73 |
pagination_class = GeoJsonPagination |
| 74 |
|
| 75 |
|
| 76 |
geojson_location_list = GeojsonLocationList.as_view() |
| 77 |
|
| 78 |
|
| 79 |
class GeojsonLocationWritableIdList(generics.ListCreateAPIView): |
| 80 |
model = Location |
| 81 |
serializer_class = LocationGeoFeatureWritableIdSerializer |
| 82 |
queryset = Location.objects.all() |
| 83 |
pagination_class = GeoJsonPagination |
| 84 |
|
| 85 |
|
| 86 |
geojson_location_writable_id_list = GeojsonLocationWritableIdList.as_view() |
| 87 |
|
| 88 |
|
| 89 |
class GeojsonLocationContainedInBBoxList(generics.ListAPIView): |
| 90 |
model = Location |
| 91 |
serializer_class = LocationGeoFeatureSerializer |
| 92 |
queryset = Location.objects.all() |
| 93 |
bbox_filter_field = "geometry" |
| 94 |
filter_backends = (InBBoxFilter,) |
| 95 |
|
| 96 |
|
| 97 |
geojson_location_contained_in_bbox_list = GeojsonLocationContainedInBBoxList.as_view() |
| 98 |
|
| 99 |
|
| 100 |
class GeojsonLocationOverlapsBBoxList(GeojsonLocationContainedInBBoxList): |
| 101 |
bbox_filter_include_overlapping = True |
| 102 |
|
| 103 |
|
| 104 |
geojson_location_overlaps_bbox_list = GeojsonLocationOverlapsBBoxList.as_view() |
| 105 |
|
| 106 |
|
| 107 |
class GeojsonLocationContainedInTileList(generics.ListAPIView): |
| 108 |
model = Location |
| 109 |
serializer_class = LocationGeoFeatureSerializer |
| 110 |
queryset = Location.objects.all() |
| 111 |
bbox_filter_field = "geometry" |
| 112 |
filter_backends = (TMSTileFilter,) |
| 113 |
|
| 114 |
|
| 115 |
geojson_location_contained_in_tile_list = GeojsonLocationContainedInTileList.as_view() |
| 116 |
|
| 117 |
|
| 118 |
class GeojsonLocationOverlapsTileList(GeojsonLocationContainedInTileList): |
| 119 |
bbox_filter_include_overlapping = True |
| 120 |
|
| 121 |
|
| 122 |
geojson_location_overlaps_tile_list = GeojsonLocationOverlapsTileList.as_view() |
| 123 |
|
| 124 |
|
| 125 |
class GeojsonLocationWithinDistanceOfPointList(generics.ListAPIView): |
| 126 |
model = Location |
| 127 |
serializer_class = LocationGeoFeatureSerializer |
| 128 |
distance_filter_convert_meters = True |
| 129 |
queryset = Location.objects.all() |
| 130 |
distance_filter_field = "geometry" |
| 131 |
filter_backends = (DistanceToPointFilter,) |
| 132 |
|
| 133 |
|
| 134 |
geojson_location_within_distance_of_point_list = ( |
| 135 |
GeojsonLocationWithinDistanceOfPointList.as_view() |
| 136 |
) |
| 137 |
|
| 138 |
|
| 139 |
class GeojsonLocationWithinDegreesOfPointList(GeojsonLocationWithinDistanceOfPointList): |
| 140 |
distance_filter_convert_meters = False # Default setting |
| 141 |
|
| 142 |
|
| 143 |
geojson_location_within_degrees_of_point_list = ( |
| 144 |
GeojsonLocationWithinDegreesOfPointList.as_view() |
| 145 |
) |
| 146 |
|
| 147 |
|
| 148 |
class GeojsonLocationOrderDistanceToPointList(generics.ListAPIView): |
| 149 |
model = Location |
| 150 |
serializer_class = LocationGeoFeatureSerializer |
| 151 |
queryset = Location.objects.all() |
| 152 |
distance_ordering_filter_field = "geometry" |
| 153 |
filter_backends = (DistanceToPointOrderingFilter,) |
| 154 |
|
| 155 |
|
| 156 |
geojson_location_order_distance_to_point_list = ( |
| 157 |
GeojsonLocationOrderDistanceToPointList.as_view() |
| 158 |
) |
| 159 |
|
| 160 |
|
| 161 |
class GeojsonLocationDetails(generics.RetrieveUpdateDestroyAPIView): |
| 162 |
model = Location |
| 163 |
serializer_class = LocationGeoFeatureSerializer |
| 164 |
queryset = Location.objects.all() |
| 165 |
|
| 166 |
|
| 167 |
geojson_location_details = GeojsonLocationDetails.as_view() |
| 168 |
|
| 169 |
|
| 170 |
class GeojsonLocationDetailsHidden(generics.RetrieveUpdateDestroyAPIView): |
| 171 |
model = Location |
| 172 |
serializer_class = LocationGeoFeatureMethodSerializer |
| 173 |
queryset = Location.objects.all() |
| 174 |
|
| 175 |
|
| 176 |
geojson_location_details_hidden = GeojsonLocationDetailsHidden.as_view() |
| 177 |
|
| 178 |
|
| 179 |
class GeojsonLocationDetailsNone(generics.RetrieveUpdateDestroyAPIView): |
| 180 |
model = Location |
| 181 |
serializer_class = NoneGeoFeatureMethodSerializer |
| 182 |
queryset = Location.objects.all() |
| 183 |
|
| 184 |
|
| 185 |
geojson_location_details_none = GeojsonLocationDetailsNone.as_view() |
| 186 |
|
| 187 |
|
| 188 |
class GeojsonNullableDetailsNoGeo(generics.RetrieveUpdateDestroyAPIView): |
| 189 |
model = Nullable |
| 190 |
serializer_class = NoGeoFeatureMethodSerializer |
| 191 |
queryset = Nullable.objects.all() |
| 192 |
|
| 193 |
|
| 194 |
geojson_nullable_details_nogeo = GeojsonNullableDetailsNoGeo.as_view() |
| 195 |
|
| 196 |
|
| 197 |
class GeojsonLocationSlugDetails(generics.RetrieveUpdateDestroyAPIView): |
| 198 |
model = Location |
| 199 |
lookup_field = "slug" |
| 200 |
serializer_class = LocationGeoFeatureSlugSerializer |
| 201 |
queryset = Location.objects.all() |
| 202 |
|
| 203 |
|
| 204 |
geojson_location_slug_details = GeojsonLocationSlugDetails.as_view() |
| 205 |
|
| 206 |
|
| 207 |
class GeojsonLocationFalseIdDetails(generics.RetrieveUpdateDestroyAPIView): |
| 208 |
model = Location |
| 209 |
serializer_class = LocationGeoFeatureFalseIdSerializer |
| 210 |
queryset = Location.objects.all() |
| 211 |
|
| 212 |
|
| 213 |
geojson_location_falseid_details = GeojsonLocationFalseIdDetails.as_view() |
| 214 |
|
| 215 |
|
| 216 |
class GeojsonLocationNoIdDetails(generics.RetrieveUpdateDestroyAPIView): |
| 217 |
model = Location |
| 218 |
serializer_class = LocationGeoFeatureNoIdSerializer |
| 219 |
queryset = Location.objects.all() |
| 220 |
|
| 221 |
|
| 222 |
geojson_location_noid_details = GeojsonLocationNoIdDetails.as_view() |
| 223 |
|
| 224 |
|
| 225 |
class LocationFilter(GeoFilterSet): |
| 226 |
contains_properly = GeometryFilter( |
| 227 |
field_name="geometry", lookup_expr="contains_properly" |
| 228 |
) |
| 229 |
|
| 230 |
class Meta: |
| 231 |
model = Location |
| 232 |
fields = ["contains_properly"] |
| 233 |
|
| 234 |
|
| 235 |
class GeojsonLocationContainedInGeometry(generics.ListAPIView): |
| 236 |
queryset = Location.objects.all() |
| 237 |
serializer_class = LocationGeoSerializer |
| 238 |
filterset_class = LocationFilter |
| 239 |
|
| 240 |
filter_backends = (DjangoFilterBackend,) |
| 241 |
|
| 242 |
|
| 243 |
geojson_contained_in_geometry = GeojsonLocationContainedInGeometry.as_view() |
| 244 |
|
| 245 |
|
| 246 |
class GeojsonLocatedFileDetails(generics.RetrieveUpdateDestroyAPIView): |
| 247 |
model = LocatedFile |
| 248 |
serializer_class = LocatedFileGeoFeatureSerializer |
| 249 |
queryset = LocatedFile.objects.all() |
| 250 |
|
| 251 |
|
| 252 |
geojson_located_file_details = GeojsonLocatedFileDetails.as_view() |
| 253 |
|
| 254 |
|
| 255 |
class GeojsonBoxedLocationDetails(generics.RetrieveUpdateDestroyAPIView): |
| 256 |
model = BoxedLocation |
| 257 |
serializer_class = BoxedLocationGeoFeatureSerializer |
| 258 |
queryset = BoxedLocation.objects.all() |
| 259 |
|
| 260 |
|
| 261 |
geojson_boxedlocation_details = GeojsonBoxedLocationDetails.as_view() |
| 262 |
|
| 263 |
|
| 264 |
class GeojsonBoxedLocationList(generics.ListCreateAPIView): |
| 265 |
model = BoxedLocation |
| 266 |
serializer_class = BoxedLocationGeoFeatureSerializer |
| 267 |
queryset = BoxedLocation.objects.all() |
| 268 |
|
| 269 |
|
| 270 |
geojson_boxedlocation_list = GeojsonBoxedLocationList.as_view() |
| 271 |
|
| 272 |
|
| 273 |
class GeojsonLocationBboxList(generics.ListCreateAPIView): |
| 274 |
model = Location |
| 275 |
serializer_class = LocationGeoFeatureBboxSerializer |
| 276 |
queryset = Location.objects.all() |
| 277 |
|
| 278 |
|
| 279 |
geojson_location_bbox_list = GeojsonLocationBboxList.as_view() |
| 280 |
|
| 281 |
|
| 282 |
class GeojsonNullableDetails(generics.RetrieveUpdateDestroyAPIView): |
| 283 |
model = Location |
| 284 |
serializer_class = LocationGeoFeatureSerializer |
| 285 |
queryset = Nullable.objects.all() |
| 286 |
|
| 287 |
|
| 288 |
geojson_nullable_details = GeojsonNullableDetails.as_view() |
| 289 |
|
| 290 |
|
| 291 |
class ModelViewWithPolygon(generics.RetrieveUpdateDestroyAPIView): |
| 292 |
model = PolygonModel |
| 293 |
serializer_class = PolygonModelSerializer |