Changeset 5749
- Timestamp:
- 07/22/07 00:13:22 (1 year ago)
- Files:
-
- django/branches/gis/django/contrib/gis/gdal/datasource.py (moved) (moved from django/branches/gis/django/contrib/gis/gdal/DataSource.py) (2 diffs)
- django/branches/gis/django/contrib/gis/gdal/driver.py (moved) (moved from django/branches/gis/django/contrib/gis/gdal/Driver.py) (3 diffs)
- django/branches/gis/django/contrib/gis/gdal/envelope.py (moved) (moved from django/branches/gis/django/contrib/gis/gdal/Envelope.py) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/error.py (moved) (moved from django/branches/gis/django/contrib/gis/gdal/OGRError.py)
- django/branches/gis/django/contrib/gis/gdal/feature.py (moved) (moved from django/branches/gis/django/contrib/gis/gdal/Feature.py) (2 diffs)
- django/branches/gis/django/contrib/gis/gdal/field.py (moved) (moved from django/branches/gis/django/contrib/gis/gdal/Field.py) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/geometries.py (moved) (moved from django/branches/gis/django/contrib/gis/gdal/OGRGeometry.py) (5 diffs)
- django/branches/gis/django/contrib/gis/gdal/geomtype.py (added)
- django/branches/gis/django/contrib/gis/gdal/__init__.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/layer.py (moved) (moved from django/branches/gis/django/contrib/gis/gdal/Layer.py) (3 diffs)
- django/branches/gis/django/contrib/gis/gdal/libgdal.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/gdal/srs.py (moved) (moved from django/branches/gis/django/contrib/gis/gdal/SpatialReference.py) (5 diffs)
- django/branches/gis/django/contrib/gis/geos/base.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/tests/test_gdal_ds.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/datasource.py
r5478 r5749 5 5 # The GDAL C library, OGR exceptions, and the Layer object. 6 6 from django.contrib.gis.gdal.libgdal import lgdal 7 from django.contrib.gis.gdal. OGRError import OGRException, check_err8 from django.contrib.gis.gdal. Layer import Layer9 from django.contrib.gis.gdal. Driver import Driver7 from django.contrib.gis.gdal.error import OGRException, check_err 8 from django.contrib.gis.gdal.layer import Layer 9 from django.contrib.gis.gdal.driver import Driver 10 10 11 11 """ … … 53 53 "Wraps an OGR Data Source object." 54 54 55 _ds = 0 # Initially NULL56 57 55 #### Python 'magic' routines #### 58 56 def __init__(self, ds_input, ds_driver=False): 57 58 self._ds = 0 # Initially NULL 59 59 60 60 # Registering all the drivers, this needs to be done django/branches/gis/django/contrib/gis/gdal/driver.py
r5478 r5749 5 5 # The GDAL C library, OGR exceptions, and the Layer object. 6 6 from django.contrib.gis.gdal.libgdal import lgdal 7 from django.contrib.gis.gdal. OGRError import OGRException7 from django.contrib.gis.gdal.error import OGRException 8 8 9 9 # For more information, see the OGR C API source code: … … 14 14 class Driver(object): 15 15 "Wraps an OGR Data Source Driver." 16 17 _dr = 0 # Initially NULL18 16 19 17 # Case-insensitive aliases for OGR Drivers. … … 30 28 if isinstance(input, StringType): 31 29 # If a string name of the driver was passed in 30 self._dr = 0 # Initially NULL 32 31 self._register() 33 32 django/branches/gis/django/contrib/gis/gdal/envelope.py
r5527 r5749 107 107 "Returns WKT representing a Polygon for this envelope." 108 108 # TODO: Fix significant figures. 109 return 'POLYGON((% f %f,%f %f,%f %f,%f %f,%f %f))' % (self.min_x, self.min_y, self.min_x, self.max_y,109 return 'POLYGON((%s %s,%s %s,%s %s,%s %s,%s %s))' % (self.min_x, self.min_y, self.min_x, self.max_y, 110 110 self.max_x, self.max_y, self.max_x, self.min_y, 111 111 self.min_x, self.min_y) django/branches/gis/django/contrib/gis/gdal/feature.py
r5604 r5749 5 5 # The GDAL C library, OGR exception, and the Field object 6 6 from django.contrib.gis.gdal.libgdal import lgdal 7 from django.contrib.gis.gdal. OGRError import OGRException8 from django.contrib.gis.gdal. Field import Field9 from django.contrib.gis.gdal. OGRGeometryimport OGRGeometry, OGRGeomType7 from django.contrib.gis.gdal.error import OGRException 8 from django.contrib.gis.gdal.field import Field 9 from django.contrib.gis.gdal.geometries import OGRGeometry, OGRGeomType 10 10 11 11 # For more information, see the OGR C API source code: … … 16 16 "A class that wraps an OGR Feature, needs to be instantiated from a Layer object." 17 17 18 _feat = 0 # Initially NULL19 20 18 #### Python 'magic' routines #### 21 19 def __init__(self, f): 22 20 "Needs a C pointer (Python integer in ctypes) in order to initialize." 21 self._feat = 0 # Initially NULL 22 self._fdefn = 0 23 23 if not f: 24 24 raise OGRException, 'Cannot create OGR Feature, invalid pointer given.' django/branches/gis/django/contrib/gis/gdal/field.py
r5605 r5749 2 2 3 3 from django.contrib.gis.gdal.libgdal import lgdal 4 from django.contrib.gis.gdal. OGRError import OGRException4 from django.contrib.gis.gdal.error import OGRException 5 5 6 6 # For more information, see the OGR C API source code: django/branches/gis/django/contrib/gis/gdal/geometries.py
r5587 r5749 3 3 from ctypes import byref, string_at, c_char_p, c_double, c_int, c_void_p 4 4 5 # Getting the GDAL C library and error checking facilities5 # Getting geodjango gdal prerequisites 6 6 from django.contrib.gis.gdal.libgdal import lgdal 7 from django.contrib.gis.gdal.Envelope import Envelope, OGREnvelope 8 from django.contrib.gis.gdal.OGRError import check_err, OGRException 9 from django.contrib.gis.gdal.SpatialReference import SpatialReference, CoordTransform 7 from django.contrib.gis.gdal.envelope import Envelope, OGREnvelope 8 from django.contrib.gis.gdal.error import check_err, OGRException 9 from django.contrib.gis.gdal.geomtype import OGRGeomType 10 from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform 10 11 11 12 """ … … 65 66 getz = pnt_func(lgdal.OGR_G_GetZ) 66 67 67 #### OGRGeomType ####68 class OGRGeomType(object):69 "Encapulates OGR Geometry Types."70 71 # Ordered array of acceptable strings and their corresponding OGRwkbGeometryType72 __ogr_str = ['Point', 'LineString', 'Polygon', 'MultiPoint',73 'MultiLineString', 'MultiPolygon', 'GeometryCollection',74 'LinearRing']75 __ogr_int = [1, 2, 3, 4, 5, 6, 7, 101]76 77 def __init__(self, input):78 "Figures out the correct OGR Type based upon the input."79 if isinstance(input, OGRGeomType):80 self._index = input._index81 elif isinstance(input, StringType):82 idx = self._has_str(self.__ogr_str, input)83 if idx == None:84 raise OGRException, 'Invalid OGR String Type "%s"' % input85 self._index = idx86 elif isinstance(input, int):87 if not input in self.__ogr_int:88 raise OGRException, 'Invalid OGR Integer Type: %d' % input89 self._index = self.__ogr_int.index(input)90 else:91 raise TypeError, 'Invalid OGR Input type given!'92 93 def __str__(self):94 "Returns a short-hand string form of the OGR Geometry type."95 return self.__ogr_str[self._index]96 97 def __eq__(self, other):98 """Does an equivalence test on the OGR type with the given99 other OGRGeomType, the short-hand string, or the integer."""100 if isinstance(other, OGRGeomType):101 return self._index == other._index102 elif isinstance(other, StringType):103 idx = self._has_str(self.__ogr_str, other)104 if not (idx == None): return self._index == idx105 return False106 elif isinstance(other, int):107 if not other in self.__ogr_int: return False108 return self.__ogr_int.index(other) == self._index109 else:110 raise TypeError, 'Cannot compare with type: %s' % str(type(other))111 112 def _has_str(self, arr, s):113 "Case-insensitive search of the string array for the given pattern."114 s_low = s.lower()115 for i in xrange(len(arr)):116 if s_low == arr[i].lower(): return i117 return None118 119 @property120 def django(self):121 "Returns the Django GeometryField for this OGR Type."122 s = self.__ogr_str[self._index]123 if s in ('Unknown', 'LinearRing'):124 return None125 else:126 return s + 'Field'127 128 @property129 def num(self):130 "Returns the OGRwkbGeometryType number for the OGR Type."131 return self.__ogr_int[self._index]132 133 68 #### OGRGeometry Class #### 134 69 class OGRGeometryIndexError(OGRException, KeyError): … … 143 78 "Generally encapsulates an OGR geometry." 144 79 145 _g = 0 # Initially NULL146 147 80 def __init__(self, input, srs=False): 148 81 "Initializes Geometry on either WKT or an OGR pointer as input." 82 83 self._g = 0 # Initially NULL 149 84 150 85 if isinstance(input, StringType): … … 182 117 self.__class__ = GEO_CLASSES[self.geom_type.num] 183 118 119 def __del__(self): 120 "Deletes this Geometry." 121 if self._g: lgdal.OGR_G_DestroyGeometry(self._g) 122 184 123 def _init_srs(self, srs): 185 124 # Getting the spatial … … 189 128 self._s = srs.clone() # cloning the given spatial reference 190 129 191 def __add__(self, other): 130 ### Geometry set-like operations ### 131 # g = g1 | g2 132 def __or__(self, other): 192 133 "Returns the union of the two geometries." 193 134 return self.union(other) 194 135 195 def __del__(self): 196 "Deletes this Geometry." 197 if self._g: lgdal.OGR_G_DestroyGeometry(self._g) 136 # g = g1 & g2 137 def __and__(self, other): 138 "Returns the intersection of this Geometry and the other." 139 return self.intersection(other) 140 141 # g = g1 - g2 142 def __sub__(self, other): 143 "Return the difference this Geometry and the other." 144 return self.difference(other) 145 146 # g = g1 ^ g2 147 def __xor__(self, other): 148 "Return the symmetric difference of this Geometry and the other." 149 return self.sym_difference(other) 198 150 199 151 def __eq__(self, other): 200 152 "Is this Geometry equal to the other?" 201 153 return self.equals(other) 154 155 def __ne__(self, other): 156 "Tests for inequality." 157 return not self.equals(other) 202 158 203 159 def __str__(self): django/branches/gis/django/contrib/gis/gdal/__init__.py
r5527 r5749 1 from Driver import Driver 2 from Envelope import Envelope 3 from DataSource import DataSource 4 from SpatialReference import SpatialReference, CoordTransform 5 from OGRGeometry import OGRGeometry, OGRGeomType 6 from OGRError import check_err, OGRException, SRSException 1 from driver import Driver 2 from envelope import Envelope 3 from datasource import DataSource 4 from srs import SpatialReference, CoordTransform 5 from geometries import OGRGeometry 6 from geomtype import OGRGeomType 7 from error import check_err, OGRException, SRSException 7 8 django/branches/gis/django/contrib/gis/gdal/layer.py
r5633 r5749 6 6 7 7 # Other GDAL imports. 8 from django.contrib.gis.gdal. Envelope import Envelope, OGREnvelope9 from django.contrib.gis.gdal. Feature import Feature10 from django.contrib.gis.gdal. OGRGeometryimport OGRGeomType11 from django.contrib.gis.gdal. OGRError import OGRException, check_err12 from django.contrib.gis.gdal. SpatialReferenceimport SpatialReference8 from django.contrib.gis.gdal.envelope import Envelope, OGREnvelope 9 from django.contrib.gis.gdal.feature import Feature 10 from django.contrib.gis.gdal.geometries import OGRGeomType 11 from django.contrib.gis.gdal.error import OGRException, check_err 12 from django.contrib.gis.gdal.srs import SpatialReference 13 13 14 14 # For more information, see the OGR C API source code: … … 17 17 # The OGR_L_* routines are relevant here. 18 18 19 # function prototype for obtaining the spatial reference system 19 20 get_srs = lgdal.OGR_L_GetSpatialRef 20 21 get_srs.restype = c_void_p … … 24 25 "A class that wraps an OGR Layer, needs to be instantiated from a DataSource object." 25 26 26 _layer = 0 # Initially NULL27 28 27 #### Python 'magic' routines #### 29 28 def __init__(self, l): 30 29 "Needs a C pointer (Python/ctypes integer) in order to initialize." 30 self._layer = 0 # Initially NULL 31 self._ldefn = 0 31 32 if not l: 32 33 raise OGRException, 'Cannot create Layer, invalid pointer given' django/branches/gis/django/contrib/gis/gdal/libgdal.py
r5510 r5749 1 1 import os, sys 2 2 from ctypes import CDLL 3 from django.contrib.gis.gdal. OGRError import OGRException3 from django.contrib.gis.gdal.error import OGRException 4 4 5 5 if os.name == 'nt': … … 21 21 # This loads the GDAL/OGR C library 22 22 lgdal = CDLL(lib_name) 23 23 django/branches/gis/django/contrib/gis/gdal/srs.py
r5478 r5749 10 10 11 11 # Getting the error checking routine and exceptions 12 from django.contrib.gis.gdal. OGRError import check_err, OGRException, SRSException12 from django.contrib.gis.gdal.error import check_err, OGRException, SRSException 13 13 14 14 """ … … 72 72 (projections and datums) and to transform between them.'""" 73 73 74 _srs = 0 # Initially NULL75 76 74 # Well-Known Geographical Coordinate System Name 77 75 _well_known = {'WGS84':4326, 'WGS72':4322, 'NAD27':4267, 'NAD83':4269} … … 81 79 def __init__(self, input='', srs_type='wkt'): 82 80 "Creates a spatial reference object from the given OGC Well Known Text (WKT)." 81 82 self._srs = 0 # Initially NULL 83 83 84 84 # Creating an initial empty string buffer. … … 100 100 buf = c_char_p(input) 101 101 elif isinstance(input, int): 102 if srs_type == 'wkt': srs_type = 'epsg' # want to try epsg if only integer provided 102 103 if srs_type not in ('epsg', 'ogr'): 103 104 raise SRSException, 'Integer input requires SRS type of "ogr" or "epsg".' … … 318 319 "A coordinate system transformation object." 319 320 320 _ct = 0 # Initially NULL321 322 321 def __init__(self, source, target): 323 322 "Initializes on a source and target SpatialReference objects." 323 self._ct = 0 # Initially NULL 324 324 if not isinstance(source, SpatialReference) or not isinstance(target, SpatialReference): 325 325 raise SRSException, 'source and target must be of type SpatialReference' django/branches/gis/django/contrib/gis/geos/base.py
r5742 r5749 282 282 283 283 #### SRID Routines #### 284 @property 285 def srid(self): 284 def get_srid(self): 286 285 "Gets the SRID for the geometry, returns None if no SRID is set." 287 286 s = lgeos.GEOSGetSRID(self._ptr()) … … 294 293 "Sets the SRID for the geometry." 295 294 lgeos.GEOSSetSRID(self._ptr(), c_int(srid)) 296 295 srid = property(get_srid, set_srid) 296 297 297 #### Output Routines #### 298 298 @property django/branches/gis/django/contrib/gis/tests/test_gdal_ds.py
r5605 r5749 1 1 import os, os.path, unittest 2 2 from django.contrib.gis.gdal import DataSource, OGRException 3 from django.contrib.gis.gdal. Envelope import Envelope4 from django.contrib.gis.gdal. Field import OFTReal, OFTInteger, OFTString3 from django.contrib.gis.gdal.envelope import Envelope 4 from django.contrib.gis.gdal.field import OFTReal, OFTInteger, OFTString 5 5 6 6 # Path for SHP files
