Skip to content

Commit

Permalink
gis: geos: fixed 3d linestring constructor bug, and added tests; GEOM…
Browse files Browse the repository at this point in the history
…_FUNC_PREFIX no longer needed, since ST_Transform used.

git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@5832 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jbronn committed Aug 9, 2007
1 parent d2ca3b8 commit fc1dbe7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
7 changes: 3 additions & 4 deletions django/contrib/gis/geos/base.py
Expand Up @@ -12,7 +12,7 @@
# Python and GEOS-related dependencies. # Python and GEOS-related dependencies.
import re import re
from warnings import warn from warnings import warn
from django.contrib.gis.geos.libgeos import lgeos, GEOSPointer, HAS_NUMPY, ISQLQuote, GEOM_FUNC_PREFIX from django.contrib.gis.geos.libgeos import lgeos, GEOSPointer, HAS_NUMPY, ISQLQuote
from django.contrib.gis.geos.error import GEOSException, GEOSGeometryIndexError from django.contrib.gis.geos.error import GEOSException, GEOSGeometryIndexError
from django.contrib.gis.geos.coordseq import GEOSCoordSeq, create_cs from django.contrib.gis.geos.coordseq import GEOSCoordSeq, create_cs
if HAS_NUMPY: from numpy import ndarray, array if HAS_NUMPY: from numpy import ndarray, array
Expand Down Expand Up @@ -204,9 +204,8 @@ def __conform__(self, proto):


def getquoted(self): def getquoted(self):
"Returns a properly quoted string for use in PostgresSQL/PostGIS." "Returns a properly quoted string for use in PostgresSQL/PostGIS."
# GeomFromText() is ST_GeomFromText() in PostGIS >= 1.2.2 to correspond # Using ST_GeomFromText(), corresponds to SQL/MM ISO standard.
# to SQL/MM ISO standard. return "ST_GeomFromText('%s', %s)" % (self.wkt, self.srid or -1)
return "%sGeomFromText('%s', %s)" % (GEOM_FUNC_PREFIX, self.wkt, self.srid or -1)


#### Coordinate Sequence Routines #### #### Coordinate Sequence Routines ####
@property @property
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/geos/geometries.py
Expand Up @@ -167,7 +167,7 @@ def __init__(self, *args, **kwargs):
raise TypeError, 'Invalid initialization input for LineStrings.' raise TypeError, 'Invalid initialization input for LineStrings.'


# Creating the coordinate sequence # Creating the coordinate sequence
cs = GEOSCoordSeq(GEOSPointer(0, create_cs(c_uint(ncoords), c_uint(ndim)))) cs = GEOSCoordSeq(GEOSPointer(0, create_cs(c_uint(ncoords), c_uint(ndim))), z=bool(ndim==3))


# Setting each point in the coordinate sequence # Setting each point in the coordinate sequence
for i in xrange(ncoords): for i in xrange(ncoords):
Expand Down
2 changes: 0 additions & 2 deletions django/contrib/gis/geos/libgeos.py
Expand Up @@ -21,10 +21,8 @@
# Are psycopg2 and GeoDjango models being used? # Are psycopg2 and GeoDjango models being used?
try: try:
from psycopg2.extensions import ISQLQuote from psycopg2.extensions import ISQLQuote
from django.contrib.gis.db.backend.postgis import GEOM_FUNC_PREFIX
except (ImportError, EnvironmentError): except (ImportError, EnvironmentError):
ISQLQuote = None ISQLQuote = None
GEOM_FUNC_PREFIX = None


# Setting the appropriate name for the GEOS-C library, depending on which # Setting the appropriate name for the GEOS-C library, depending on which
# OS and POSIX platform we're running. # OS and POSIX platform we're running.
Expand Down
19 changes: 19 additions & 0 deletions django/contrib/gis/tests/test_geos.py
Expand Up @@ -594,6 +594,25 @@ def test16_mutable_geometries(self):
self.assertNotEqual(poly, mpoly[i]) self.assertNotEqual(poly, mpoly[i])
del mpoly del mpoly



def test17_threed(self):
"Testing three-dimensional geometries."

# Testing a 3D Point
pnt = Point(2, 3, 8)
self.assertEqual((2.,3.,8.), pnt.coords)
self.assertRaises(TypeError, pnt.set_coords, (1.,2.))
pnt.coords = (1.,2.,3.)
self.assertEqual((1.,2.,3.), pnt.coords)

# Testing a 3D LineString
ls = LineString((2., 3., 8.), (50., 250., -117.))
self.assertEqual(((2.,3.,8.), (50.,250.,-117.)), ls.tuple)
self.assertRaises(TypeError, ls.__setitem__, 0, (1.,2.))
ls[0] = (1.,2.,3.)
self.assertEqual((1.,2.,3.), ls[0])


def suite(): def suite():
s = unittest.TestSuite() s = unittest.TestSuite()
s.addTest(unittest.makeSuite(GEOSTest)) s.addTest(unittest.makeSuite(GEOSTest))
Expand Down

0 comments on commit fc1dbe7

Please sign in to comment.