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
23fbd3ff
Kaydet (Commit)
23fbd3ff
authored
Nis 19, 2016
tarafından
Nicolas Noé
Kaydeden (comit)
Tim Graham
Nis 19, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26512 -- Added tests for SpatialRefSysMixin.get_units().
üst
5402f3ab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
5 deletions
+30
-5
models.py
django/contrib/gis/db/backends/base/models.py
+3
-4
test_spatialrefsys.py
tests/gis_tests/test_spatialrefsys.py
+27
-1
No files found.
django/contrib/gis/db/backends/base/models.py
Dosyayı görüntüle @
23fbd3ff
...
@@ -164,15 +164,14 @@ class SpatialRefSysMixin(object):
...
@@ -164,15 +164,14 @@ class SpatialRefSysMixin(object):
@classmethod
@classmethod
def
get_units
(
cls
,
wkt
):
def
get_units
(
cls
,
wkt
):
"""
"""
Class method used by GeometryField on initialization to
Return a tuple of (unit_value, unit_name) for the given WKT without
retrieve the units on the given WKT, without having to use
using any of the database fields.
any of the database fields.
"""
"""
if
gdal
.
HAS_GDAL
:
if
gdal
.
HAS_GDAL
:
return
gdal
.
SpatialReference
(
wkt
)
.
units
return
gdal
.
SpatialReference
(
wkt
)
.
units
else
:
else
:
m
=
cls
.
units_regex
.
match
(
wkt
)
m
=
cls
.
units_regex
.
match
(
wkt
)
return
m
.
group
(
'unit'
),
m
.
group
(
'unit_name'
)
return
float
(
m
.
group
(
'unit'
)
),
m
.
group
(
'unit_name'
)
@classmethod
@classmethod
def
get_spheroid
(
cls
,
wkt
,
string
=
True
):
def
get_spheroid
(
cls
,
wkt
,
string
=
True
):
...
...
tests/gis_tests/test_spatialrefsys.py
Dosyayı görüntüle @
23fbd3ff
import
re
import
unittest
import
unittest
from
django.contrib.gis.gdal
import
HAS_GDAL
from
django.contrib.gis.gdal
import
HAS_GDAL
from
django.db
import
connection
from
django.db
import
connection
from
django.test
import
skipUnlessDBFeature
from
django.test
import
mock
,
skipUnlessDBFeature
from
django.utils
import
six
from
django.utils
import
six
from
.utils
import
SpatialRefSys
,
oracle
,
postgis
,
spatialite
from
.utils
import
SpatialRefSys
,
oracle
,
postgis
,
spatialite
...
@@ -20,6 +21,18 @@ test_srs = ({
...
@@ -20,6 +21,18 @@ test_srs = ({
# From proj's "cs2cs -le" and Wikipedia (semi-minor only)
# From proj's "cs2cs -le" and Wikipedia (semi-minor only)
'ellipsoid'
:
(
6378137.0
,
6356752.3
,
298.257223563
),
'ellipsoid'
:
(
6378137.0
,
6356752.3
,
298.257223563
),
'eprec'
:
(
1
,
1
,
9
),
'eprec'
:
(
1
,
1
,
9
),
'wkt'
:
re
.
sub
(
'[
\
s+]'
,
''
,
"""
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
"""
)
},
{
},
{
'srid'
:
32140
,
'srid'
:
32140
,
'auth_name'
:
(
'EPSG'
,
False
),
'auth_name'
:
(
'EPSG'
,
False
),
...
@@ -43,6 +56,19 @@ test_srs = ({
...
@@ -43,6 +56,19 @@ test_srs = ({
@skipUnlessDBFeature
(
"has_spatialrefsys_table"
)
@skipUnlessDBFeature
(
"has_spatialrefsys_table"
)
class
SpatialRefSysTest
(
unittest
.
TestCase
):
class
SpatialRefSysTest
(
unittest
.
TestCase
):
def
test_get_units
(
self
):
epsg_4326
=
next
(
f
for
f
in
test_srs
if
f
[
'srid'
]
==
4326
)
unit
,
unit_name
=
SpatialRefSys
()
.
get_units
(
epsg_4326
[
'wkt'
])
self
.
assertEqual
(
unit_name
,
'degree'
)
self
.
assertAlmostEqual
(
unit
,
0.01745329251994328
)
@mock.patch
(
'django.contrib.gis.gdal.HAS_GDAL'
,
False
)
def
test_get_units_without_gdal
(
self
):
epsg_4326
=
next
(
f
for
f
in
test_srs
if
f
[
'srid'
]
==
4326
)
unit
,
unit_name
=
SpatialRefSys
()
.
get_units
(
epsg_4326
[
'wkt'
])
self
.
assertEqual
(
unit_name
,
'degree'
)
self
.
assertAlmostEqual
(
unit
,
0.01745329251994328
)
def
test_retrieve
(
self
):
def
test_retrieve
(
self
):
"""
"""
Test retrieval of SpatialRefSys model objects.
Test retrieval of SpatialRefSys model objects.
...
...
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