1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

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
This commit is contained in:
Justin Bronn 2007-08-09 03:07:02 +00:00
parent d2ca3b8b8f
commit fc1dbe70fe
4 changed files with 23 additions and 7 deletions

View File

@ -12,7 +12,7 @@ from types import StringType, UnicodeType, IntType, FloatType
# Python and GEOS-related dependencies.
import re
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.coordseq import GEOSCoordSeq, create_cs
if HAS_NUMPY: from numpy import ndarray, array
@ -204,9 +204,8 @@ class GEOSGeometry(object):
def getquoted(self):
"Returns a properly quoted string for use in PostgresSQL/PostGIS."
# GeomFromText() is ST_GeomFromText() in PostGIS >= 1.2.2 to correspond
# to SQL/MM ISO standard.
return "%sGeomFromText('%s', %s)" % (GEOM_FUNC_PREFIX, self.wkt, self.srid or -1)
# Using ST_GeomFromText(), corresponds to SQL/MM ISO standard.
return "ST_GeomFromText('%s', %s)" % (self.wkt, self.srid or -1)
#### Coordinate Sequence Routines ####
@property

View File

@ -167,7 +167,7 @@ class LineString(GEOSGeometry):
raise TypeError, 'Invalid initialization input for LineStrings.'
# 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
for i in xrange(ncoords):

View File

@ -21,10 +21,8 @@ except ImportError:
# Are psycopg2 and GeoDjango models being used?
try:
from psycopg2.extensions import ISQLQuote
from django.contrib.gis.db.backend.postgis import GEOM_FUNC_PREFIX
except (ImportError, EnvironmentError):
ISQLQuote = None
GEOM_FUNC_PREFIX = None
# Setting the appropriate name for the GEOS-C library, depending on which
# OS and POSIX platform we're running.

View File

@ -594,6 +594,25 @@ class GEOSTest(unittest.TestCase):
self.assertNotEqual(poly, mpoly[i])
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():
s = unittest.TestSuite()
s.addTest(unittest.makeSuite(GEOSTest))