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
5ccbcc5b
Kaydet (Commit)
5ccbcc5b
authored
Tem 25, 2017
tarafından
Sergey Fedoseev
Kaydeden (comit)
Tim Graham
Tem 26, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28433 -- Made GEOSGeometry.__eq__() work correctly with non-canonical EWKT string.
üst
c3622285
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
8 deletions
+47
-8
geometry.py
django/contrib/gis/geos/geometry.py
+28
-8
test_geos.py
tests/gis_tests/geos_tests/test_geos.py
+19
-0
No files found.
django/contrib/gis/geos/geometry.py
Dosyayı görüntüle @
5ccbcc5b
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
This module contains the 'base' GEOSGeometry object -- all GEOS Geometries
This module contains the 'base' GEOSGeometry object -- all GEOS Geometries
inherit from this object.
inherit from this object.
"""
"""
import
re
from
ctypes
import
addressof
,
byref
,
c_double
from
ctypes
import
addressof
,
byref
,
c_double
from
django.contrib.gis
import
gdal
from
django.contrib.gis
import
gdal
...
@@ -54,7 +55,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
...
@@ -54,7 +55,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
# Handling WKT input.
# Handling WKT input.
if
wkt_m
.
group
(
'srid'
):
if
wkt_m
.
group
(
'srid'
):
input_srid
=
int
(
wkt_m
.
group
(
'srid'
))
input_srid
=
int
(
wkt_m
.
group
(
'srid'
))
g
=
wkt_r
()
.
read
(
force_bytes
(
wkt_m
.
group
(
'wkt'
)))
g
=
self
.
_from_wkt
(
force_bytes
(
wkt_m
.
group
(
'wkt'
)))
elif
hex_regex
.
match
(
geo_input
):
elif
hex_regex
.
match
(
geo_input
):
# Handling HEXEWKB input.
# Handling HEXEWKB input.
g
=
wkb_r
()
.
read
(
force_bytes
(
geo_input
))
g
=
wkb_r
()
.
read
(
force_bytes
(
geo_input
))
...
@@ -163,6 +164,27 @@ class GEOSGeometry(GEOSBase, ListMixin):
...
@@ -163,6 +164,27 @@ class GEOSGeometry(GEOSBase, ListMixin):
def
_from_wkb
(
cls
,
wkb
):
def
_from_wkb
(
cls
,
wkb
):
return
wkb_r
()
.
read
(
wkb
)
return
wkb_r
()
.
read
(
wkb
)
@staticmethod
def
from_ewkt
(
ewkt
):
ewkt
=
force_bytes
(
ewkt
)
srid
=
None
parts
=
ewkt
.
split
(
b
';'
,
1
)
if
len
(
parts
)
==
2
:
srid_part
,
wkt
=
parts
match
=
re
.
match
(
b
'SRID=(?P<srid>
\
-?
\
d+)'
,
srid_part
)
if
not
match
:
raise
ValueError
(
'EWKT has invalid SRID part.'
)
srid
=
int
(
match
.
group
(
'srid'
))
else
:
wkt
=
ewkt
if
not
wkt
:
raise
ValueError
(
'Expected WKT but got an empty string.'
)
return
GEOSGeometry
(
GEOSGeometry
.
_from_wkt
(
wkt
),
srid
=
srid
)
@staticmethod
def
_from_wkt
(
wkt
):
return
wkt_r
()
.
read
(
wkt
)
@classmethod
@classmethod
def
from_gml
(
cls
,
gml_string
):
def
from_gml
(
cls
,
gml_string
):
return
gdal
.
OGRGeometry
.
from_gml
(
gml_string
)
.
geos
return
gdal
.
OGRGeometry
.
from_gml
(
gml_string
)
.
geos
...
@@ -174,13 +196,11 @@ class GEOSGeometry(GEOSBase, ListMixin):
...
@@ -174,13 +196,11 @@ class GEOSGeometry(GEOSBase, ListMixin):
or an EWKT representation.
or an EWKT representation.
"""
"""
if
isinstance
(
other
,
str
):
if
isinstance
(
other
,
str
):
if
other
.
startswith
(
'SRID=0;'
):
try
:
return
self
.
ewkt
==
other
[
7
:]
# Test only WKT part of other
other
=
GEOSGeometry
.
from_ewkt
(
other
)
return
self
.
ewkt
==
other
except
(
ValueError
,
GEOSException
):
elif
isinstance
(
other
,
GEOSGeometry
):
return
False
return
self
.
srid
==
other
.
srid
and
self
.
equals_exact
(
other
)
return
isinstance
(
other
,
GEOSGeometry
)
and
self
.
srid
==
other
.
srid
and
self
.
equals_exact
(
other
)
else
:
return
False
# ### Geometry set-like operations ###
# ### Geometry set-like operations ###
# Thanks to Sean Gillies for inspiration:
# Thanks to Sean Gillies for inspiration:
...
...
tests/gis_tests/geos_tests/test_geos.py
Dosyayı görüntüle @
5ccbcc5b
...
@@ -179,6 +179,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
...
@@ -179,6 +179,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
ls
=
fromstr
(
'LINESTRING(0 0, 1 1, 5 5)'
)
ls
=
fromstr
(
'LINESTRING(0 0, 1 1, 5 5)'
)
self
.
assertEqual
(
ls
,
ls
.
wkt
)
self
.
assertEqual
(
ls
,
ls
.
wkt
)
self
.
assertNotEqual
(
p
,
'bar'
)
self
.
assertNotEqual
(
p
,
'bar'
)
self
.
assertEqual
(
p
,
'POINT(5.0 23.0)'
)
# Error shouldn't be raise on equivalence testing with
# Error shouldn't be raise on equivalence testing with
# an invalid type.
# an invalid type.
for
g
in
(
p
,
ls
):
for
g
in
(
p
,
ls
):
...
@@ -1322,6 +1323,24 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
...
@@ -1322,6 +1323,24 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
),
),
)
)
def
test_from_ewkt
(
self
):
self
.
assertEqual
(
GEOSGeometry
.
from_ewkt
(
'SRID=1;POINT(1 1)'
),
Point
(
1
,
1
,
srid
=
1
))
self
.
assertEqual
(
GEOSGeometry
.
from_ewkt
(
'POINT(1 1)'
),
Point
(
1
,
1
))
def
test_from_ewkt_empty_string
(
self
):
msg
=
'Expected WKT but got an empty string.'
with
self
.
assertRaisesMessage
(
ValueError
,
msg
):
GEOSGeometry
.
from_ewkt
(
''
)
with
self
.
assertRaisesMessage
(
ValueError
,
msg
):
GEOSGeometry
.
from_ewkt
(
'SRID=1;'
)
def
test_from_ewkt_invalid_srid
(
self
):
msg
=
'EWKT has invalid SRID part.'
with
self
.
assertRaisesMessage
(
ValueError
,
msg
):
GEOSGeometry
.
from_ewkt
(
'SRUD=1;POINT(1 1)'
)
with
self
.
assertRaisesMessage
(
ValueError
,
msg
):
GEOSGeometry
.
from_ewkt
(
'SRID=WGS84;POINT(1 1)'
)
def
test_normalize
(
self
):
def
test_normalize
(
self
):
g
=
MultiPoint
(
Point
(
0
,
0
),
Point
(
2
,
2
),
Point
(
1
,
1
))
g
=
MultiPoint
(
Point
(
0
,
0
),
Point
(
2
,
2
),
Point
(
1
,
1
))
self
.
assertIsNone
(
g
.
normalize
())
self
.
assertIsNone
(
g
.
normalize
())
...
...
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