Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
082f5bfd
Kaydet (Commit)
082f5bfd
authored
Agu 15, 2016
tarafından
Daniel Wiesmann
Kaydeden (comit)
Tim Graham
Eyl 03, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added error messages for GIS DB functions when used with rasters.
üst
d6b9aab3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletion
+22
-1
functions.py
django/contrib/gis/db/models/functions.py
+6
-1
test_rasterfield.py
tests/gis_tests/rasterapp/test_rasterfield.py
+16
-0
No files found.
django/contrib/gis/db/models/functions.py
Dosyayı görüntüle @
082f5bfd
from
decimal
import
Decimal
from
django.contrib.gis.db.models.fields
import
GeometryField
from
django.contrib.gis.db.models.fields
import
GeometryField
,
RasterField
from
django.contrib.gis.db.models.sql
import
AreaField
from
django.contrib.gis.geometry.backend
import
Geometry
from
django.contrib.gis.measure
import
(
Area
as
AreaMeasure
,
Distance
as
DistanceMeasure
,
)
...
...
@@ -40,6 +41,8 @@ class GeoFunc(Func):
def
as_sql
(
self
,
compiler
,
connection
):
if
self
.
function
is
None
:
self
.
function
=
connection
.
ops
.
spatial_function_name
(
self
.
name
)
if
any
(
isinstance
(
field
,
RasterField
)
for
field
in
self
.
get_source_fields
()):
raise
TypeError
(
"Geometry functions not supported for raster fields."
)
return
super
(
GeoFunc
,
self
)
.
as_sql
(
compiler
,
connection
)
def
resolve_expression
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -87,6 +90,8 @@ class GeomValue(Value):
class
GeoFuncWithGeoParam
(
GeoFunc
):
def
__init__
(
self
,
expression
,
geom
,
*
expressions
,
**
extra
):
if
not
isinstance
(
geom
,
Geometry
):
raise
TypeError
(
"Please provide a geometry object."
)
if
not
hasattr
(
geom
,
'srid'
)
or
not
geom
.
srid
:
raise
ValueError
(
"Please provide a geometry attribute with a defined SRID."
)
super
(
GeoFuncWithGeoParam
,
self
)
.
__init__
(
expression
,
GeomValue
(
geom
),
*
expressions
,
**
extra
)
...
...
tests/gis_tests/rasterapp/test_rasterfield.py
Dosyayı görüntüle @
082f5bfd
import
json
from
django.contrib.gis.db.models.functions
import
Distance
from
django.contrib.gis.db.models.lookups
import
(
DistanceLookupBase
,
gis_lookups
,
)
...
...
@@ -326,3 +327,18 @@ class RasterFieldTest(TransactionTestCase):
msg
=
"Couldn't create spatial object from lookup value '
%
s'."
%
obj
with
self
.
assertRaisesMessage
(
ValueError
,
msg
):
RasterModel
.
objects
.
filter
(
geom__intersects
=
obj
)
def
test_db_function_errors
(
self
):
"""
Errors are raised when using DB functions with raster content.
"""
point
=
GEOSGeometry
(
"SRID=3086;POINT (-697024.9213808845 683729.1705516104)"
)
rast
=
GDALRaster
(
json
.
loads
(
JSON_RASTER
))
msg
=
"Please provide a geometry object."
with
self
.
assertRaisesMessage
(
TypeError
,
msg
):
RasterModel
.
objects
.
annotate
(
distance_from_point
=
Distance
(
"geom"
,
rast
))
with
self
.
assertRaisesMessage
(
TypeError
,
msg
):
RasterModel
.
objects
.
annotate
(
distance_from_point
=
Distance
(
"rastprojected"
,
rast
))
msg
=
"Geometry functions not supported for raster fields."
with
self
.
assertRaisesMessage
(
TypeError
,
msg
):
RasterModel
.
objects
.
annotate
(
distance_from_point
=
Distance
(
"rastprojected"
,
point
))
.
count
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment