Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

gis: geos: fixed 3d linestring constructor bug, and added tests; GEOM…

…_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...
commit fc1dbe70fe69021a182cc6fb5a7db35eddf60529 1 parent d2ca3b8
Justin Bronn authored August 09, 2007
7  django/contrib/gis/geos/base.py
@@ -12,7 +12,7 @@
12 12
 # Python and GEOS-related dependencies.
13 13
 import re
14 14
 from warnings import warn
15  
-from django.contrib.gis.geos.libgeos import lgeos, GEOSPointer, HAS_NUMPY, ISQLQuote, GEOM_FUNC_PREFIX
  15
+from django.contrib.gis.geos.libgeos import lgeos, GEOSPointer, HAS_NUMPY, ISQLQuote
16 16
 from django.contrib.gis.geos.error import GEOSException, GEOSGeometryIndexError
17 17
 from django.contrib.gis.geos.coordseq import GEOSCoordSeq, create_cs
18 18
 if HAS_NUMPY: from numpy import ndarray, array
@@ -204,9 +204,8 @@ def __conform__(self, proto):
204 204
 
205 205
     def getquoted(self):
206 206
         "Returns a properly quoted string for use in PostgresSQL/PostGIS."
207  
-        # GeomFromText() is ST_GeomFromText() in PostGIS >= 1.2.2 to correspond
208  
-        #  to SQL/MM ISO standard.
209  
-        return "%sGeomFromText('%s', %s)" % (GEOM_FUNC_PREFIX, self.wkt, self.srid or -1)
  207
+        # Using ST_GeomFromText(), corresponds to SQL/MM ISO standard.
  208
+        return "ST_GeomFromText('%s', %s)" % (self.wkt, self.srid or -1)
210 209
     
211 210
     #### Coordinate Sequence Routines ####
212 211
     @property
2  django/contrib/gis/geos/geometries.py
@@ -167,7 +167,7 @@ def __init__(self, *args, **kwargs):
167 167
             raise TypeError, 'Invalid initialization input for LineStrings.'
168 168
 
169 169
         # Creating the coordinate sequence
170  
-        cs = GEOSCoordSeq(GEOSPointer(0, create_cs(c_uint(ncoords), c_uint(ndim))))
  170
+        cs = GEOSCoordSeq(GEOSPointer(0, create_cs(c_uint(ncoords), c_uint(ndim))), z=bool(ndim==3))
171 171
 
172 172
         # Setting each point in the coordinate sequence
173 173
         for i in xrange(ncoords):
2  django/contrib/gis/geos/libgeos.py
@@ -21,10 +21,8 @@
21 21
 # Are psycopg2 and GeoDjango models being used?
22 22
 try:
23 23
     from psycopg2.extensions import ISQLQuote
24  
-    from django.contrib.gis.db.backend.postgis import GEOM_FUNC_PREFIX
25 24
 except (ImportError, EnvironmentError):
26 25
     ISQLQuote = None
27  
-    GEOM_FUNC_PREFIX = None
28 26
 
29 27
 # Setting the appropriate name for the GEOS-C library, depending on which
30 28
 # OS and POSIX platform we're running.
19  django/contrib/gis/tests/test_geos.py
@@ -594,6 +594,25 @@ def test16_mutable_geometries(self):
594 594
                 self.assertNotEqual(poly, mpoly[i])
595 595
             del mpoly
596 596
 
  597
+    
  598
+    def test17_threed(self):
  599
+        "Testing three-dimensional geometries."
  600
+        
  601
+        # Testing a 3D Point
  602
+        pnt = Point(2, 3, 8)
  603
+        self.assertEqual((2.,3.,8.), pnt.coords)
  604
+        self.assertRaises(TypeError, pnt.set_coords, (1.,2.))
  605
+        pnt.coords = (1.,2.,3.)
  606
+        self.assertEqual((1.,2.,3.), pnt.coords)
  607
+
  608
+        # Testing a 3D LineString
  609
+        ls = LineString((2., 3., 8.), (50., 250., -117.))
  610
+        self.assertEqual(((2.,3.,8.), (50.,250.,-117.)), ls.tuple)
  611
+        self.assertRaises(TypeError, ls.__setitem__, 0, (1.,2.))
  612
+        ls[0] = (1.,2.,3.)
  613
+        self.assertEqual((1.,2.,3.), ls[0])
  614
+            
  615
+
597 616
 def suite():
598 617
     s = unittest.TestSuite()
599 618
     s.addTest(unittest.makeSuite(GEOSTest))

0 notes on commit fc1dbe7

Please sign in to comment.
Something went wrong with that request. Please try again.