Django

Code

Changeset 5749

Show
Ignore:
Timestamp:
07/22/07 00:13:22 (1 year ago)
Author:
jbronn
Message:

gis: got rid of CamelCase module names and made minor improvements in gdal; made srid a mutable property in geos geometries

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/gdal/datasource.py

    r5478 r5749  
    55# The GDAL C library, OGR exceptions, and the Layer object. 
    66from django.contrib.gis.gdal.libgdal import lgdal 
    7 from django.contrib.gis.gdal.OGRError import OGRException, check_err 
    8 from django.contrib.gis.gdal.Layer import Layer 
    9 from django.contrib.gis.gdal.Driver import Driver 
     7from django.contrib.gis.gdal.error import OGRException, check_err 
     8from django.contrib.gis.gdal.layer import Layer 
     9from django.contrib.gis.gdal.driver import Driver 
    1010 
    1111""" 
     
    5353    "Wraps an OGR Data Source object." 
    5454 
    55     _ds = 0 # Initially NULL 
    56      
    5755    #### Python 'magic' routines #### 
    5856    def __init__(self, ds_input, ds_driver=False): 
     57 
     58        self._ds = 0 # Initially NULL 
    5959 
    6060        # Registering all the drivers, this needs to be done 
  • django/branches/gis/django/contrib/gis/gdal/driver.py

    r5478 r5749  
    55# The GDAL C library, OGR exceptions, and the Layer object. 
    66from django.contrib.gis.gdal.libgdal import lgdal 
    7 from django.contrib.gis.gdal.OGRError import OGRException 
     7from django.contrib.gis.gdal.error import OGRException 
    88 
    99# For more information, see the OGR C API source code: 
     
    1414class Driver(object): 
    1515    "Wraps an OGR Data Source Driver." 
    16  
    17     _dr = 0 # Initially NULL 
    1816 
    1917    # Case-insensitive aliases for OGR Drivers. 
     
    3028        if isinstance(input, StringType): 
    3129            # If a string name of the driver was passed in 
     30            self._dr = 0 # Initially NULL 
    3231            self._register() 
    3332 
  • django/branches/gis/django/contrib/gis/gdal/envelope.py

    r5527 r5749  
    107107        "Returns WKT representing a Polygon for this envelope." 
    108108        # 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, 
    110110                                                             self.max_x, self.max_y, self.max_x, self.min_y, 
    111111                                                             self.min_x, self.min_y) 
  • django/branches/gis/django/contrib/gis/gdal/feature.py

    r5604 r5749  
    55# The GDAL C library, OGR exception, and the Field object 
    66from django.contrib.gis.gdal.libgdal import lgdal 
    7 from django.contrib.gis.gdal.OGRError import OGRException 
    8 from django.contrib.gis.gdal.Field import Field 
    9 from django.contrib.gis.gdal.OGRGeometry import OGRGeometry, OGRGeomType 
     7from django.contrib.gis.gdal.error import OGRException 
     8from django.contrib.gis.gdal.field import Field 
     9from django.contrib.gis.gdal.geometries import OGRGeometry, OGRGeomType 
    1010 
    1111# For more information, see the OGR C API source code: 
     
    1616    "A class that wraps an OGR Feature, needs to be instantiated from a Layer object." 
    1717 
    18     _feat = 0 # Initially NULL 
    19  
    2018    #### Python 'magic' routines #### 
    2119    def __init__(self, f): 
    2220        "Needs a C pointer (Python integer in ctypes) in order to initialize." 
     21        self._feat = 0 # Initially NULL 
     22        self._fdefn = 0  
    2323        if not f: 
    2424            raise OGRException, 'Cannot create OGR Feature, invalid pointer given.' 
  • django/branches/gis/django/contrib/gis/gdal/field.py

    r5605 r5749  
    22 
    33from django.contrib.gis.gdal.libgdal import lgdal 
    4 from django.contrib.gis.gdal.OGRError import OGRException 
     4from django.contrib.gis.gdal.error import OGRException 
    55 
    66# For more information, see the OGR C API source code: 
  • django/branches/gis/django/contrib/gis/gdal/geometries.py

    r5587 r5749  
    33from ctypes import byref, string_at, c_char_p, c_double, c_int, c_void_p 
    44 
    5 # Getting the GDAL C library and error checking facilities 
     5# Getting geodjango gdal prerequisites 
    66from 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 
     7from django.contrib.gis.gdal.envelope import Envelope, OGREnvelope 
     8from django.contrib.gis.gdal.error import check_err, OGRException 
     9from django.contrib.gis.gdal.geomtype import OGRGeomType 
     10from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform 
    1011 
    1112""" 
     
    6566getz = pnt_func(lgdal.OGR_G_GetZ) 
    6667 
    67 #### OGRGeomType #### 
    68 class OGRGeomType(object): 
    69     "Encapulates OGR Geometry Types." 
    70  
    71     # Ordered array of acceptable strings and their corresponding OGRwkbGeometryType 
    72     __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._index 
    81         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"' % input 
    85             self._index = idx 
    86         elif isinstance(input, int): 
    87             if not input in self.__ogr_int: 
    88                 raise OGRException, 'Invalid OGR Integer Type: %d' % input 
    89             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 given 
    99         other OGRGeomType, the short-hand string, or the integer.""" 
    100         if isinstance(other, OGRGeomType): 
    101             return self._index == other._index 
    102         elif isinstance(other, StringType): 
    103             idx = self._has_str(self.__ogr_str, other) 
    104             if not (idx == None): return self._index == idx 
    105             return False 
    106         elif isinstance(other, int): 
    107             if not other in self.__ogr_int: return False 
    108             return self.__ogr_int.index(other) == self._index 
    109         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 i 
    117         return None 
    118  
    119     @property 
    120     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 None 
    125         else: 
    126             return s + 'Field' 
    127  
    128     @property 
    129     def num(self): 
    130         "Returns the OGRwkbGeometryType number for the OGR Type." 
    131         return self.__ogr_int[self._index] 
    132  
    13368#### OGRGeometry Class #### 
    13469class OGRGeometryIndexError(OGRException, KeyError): 
     
    14378    "Generally encapsulates an OGR geometry." 
    14479 
    145     _g = 0 # Initially NULL 
    146  
    14780    def __init__(self, input, srs=False): 
    14881        "Initializes Geometry on either WKT or an OGR pointer as input." 
     82 
     83        self._g = 0 # Initially NULL 
    14984 
    15085        if isinstance(input, StringType): 
     
    182117        self.__class__ = GEO_CLASSES[self.geom_type.num] 
    183118 
     119    def __del__(self): 
     120        "Deletes this Geometry." 
     121        if self._g: lgdal.OGR_G_DestroyGeometry(self._g) 
     122 
    184123    def _init_srs(self, srs): 
    185124        # Getting the spatial 
     
    189128            self._s = srs.clone() # cloning the given spatial reference 
    190129 
    191     def __add__(self, other): 
     130    ### Geometry set-like operations ### 
     131    # g = g1 | g2 
     132    def __or__(self, other): 
    192133        "Returns the union of the two geometries." 
    193134        return self.union(other) 
    194135 
    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) 
    198150 
    199151    def __eq__(self, other): 
    200152        "Is this Geometry equal to the other?" 
    201153        return self.equals(other) 
     154 
     155    def __ne__(self, other): 
     156        "Tests for inequality." 
     157        return not self.equals(other) 
    202158 
    203159    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 
     1from driver import Driver 
     2from envelope import Envelope 
     3from datasource import DataSource 
     4from srs import SpatialReference, CoordTransform 
     5from geometries import OGRGeometry 
     6from geomtype import OGRGeomType 
     7from error import check_err, OGRException, SRSException 
    78 
  • django/branches/gis/django/contrib/gis/gdal/layer.py

    r5633 r5749  
    66 
    77# Other GDAL imports. 
    8 from django.contrib.gis.gdal.Envelope import Envelope, OGREnvelope 
    9 from django.contrib.gis.gdal.Feature import Feature 
    10 from django.contrib.gis.gdal.OGRGeometry import OGRGeomType 
    11 from django.contrib.gis.gdal.OGRError import OGRException, check_err 
    12 from django.contrib.gis.gdal.SpatialReference import SpatialReference 
     8from django.contrib.gis.gdal.envelope import Envelope, OGREnvelope 
     9from django.contrib.gis.gdal.feature import Feature 
     10from django.contrib.gis.gdal.geometries import OGRGeomType 
     11from django.contrib.gis.gdal.error import OGRException, check_err 
     12from django.contrib.gis.gdal.srs import SpatialReference 
    1313 
    1414# For more information, see the OGR C API source code: 
     
    1717# The OGR_L_* routines are relevant here. 
    1818 
     19# function prototype for obtaining the spatial reference system 
    1920get_srs = lgdal.OGR_L_GetSpatialRef 
    2021get_srs.restype = c_void_p 
     
    2425    "A class that wraps an OGR Layer, needs to be instantiated from a DataSource object." 
    2526 
    26     _layer = 0 # Initially NULL 
    27  
    2827    #### Python 'magic' routines #### 
    2928    def __init__(self, l): 
    3029        "Needs a C pointer (Python/ctypes integer) in order to initialize." 
     30        self._layer = 0 # Initially NULL 
     31        self._ldefn = 0 
    3132        if not l: 
    3233            raise OGRException, 'Cannot create Layer, invalid pointer given' 
  • django/branches/gis/django/contrib/gis/gdal/libgdal.py

    r5510 r5749  
    11import os, sys 
    22from ctypes import CDLL 
    3 from django.contrib.gis.gdal.OGRError import OGRException 
     3from django.contrib.gis.gdal.error import OGRException 
    44 
    55if os.name == 'nt': 
     
    2121# This loads the GDAL/OGR C library 
    2222lgdal = CDLL(lib_name) 
    23                                                                              
     23 
  • django/branches/gis/django/contrib/gis/gdal/srs.py

    r5478 r5749  
    1010 
    1111# Getting the error checking routine and exceptions 
    12 from django.contrib.gis.gdal.OGRError import check_err, OGRException, SRSException 
     12from django.contrib.gis.gdal.error import check_err, OGRException, SRSException 
    1313 
    1414""" 
     
    7272    (projections and datums) and to transform between them.'""" 
    7373 
    74     _srs = 0 # Initially NULL 
    75  
    7674    # Well-Known Geographical Coordinate System Name 
    7775    _well_known = {'WGS84':4326, 'WGS72':4322, 'NAD27':4267, 'NAD83':4269} 
     
    8179    def __init__(self, input='', srs_type='wkt'): 
    8280        "Creates a spatial reference object from the given OGC Well Known Text (WKT)." 
     81 
     82        self._srs = 0 # Initially NULL 
    8383 
    8484        # Creating an initial empty string buffer. 
     
    100100                buf = c_char_p(input) 
    101101        elif isinstance(input, int): 
     102            if srs_type == 'wkt': srs_type = 'epsg' # want to try epsg if only integer provided 
    102103            if srs_type not in ('epsg', 'ogr'):  
    103104                raise SRSException, 'Integer input requires SRS type of "ogr" or "epsg".' 
     
    318319    "A coordinate system transformation object." 
    319320 
    320     _ct = 0 # Initially NULL 
    321  
    322321    def __init__(self, source, target): 
    323322        "Initializes on a source and target SpatialReference objects." 
     323        self._ct = 0 # Initially NULL  
    324324        if not isinstance(source, SpatialReference) or not isinstance(target, SpatialReference): 
    325325            raise SRSException, 'source and target must be of type SpatialReference' 
  • django/branches/gis/django/contrib/gis/geos/base.py

    r5742 r5749  
    282282 
    283283    #### SRID Routines #### 
    284     @property 
    285     def srid(self): 
     284    def get_srid(self): 
    286285        "Gets the SRID for the geometry, returns None if no SRID is set." 
    287286        s = lgeos.GEOSGetSRID(self._ptr()) 
     
    294293        "Sets the SRID for the geometry." 
    295294        lgeos.GEOSSetSRID(self._ptr(), c_int(srid)) 
    296      
     295    srid = property(get_srid, set_srid) 
     296 
    297297    #### Output Routines #### 
    298298    @property 
  • django/branches/gis/django/contrib/gis/tests/test_gdal_ds.py

    r5605 r5749  
    11import os, os.path, unittest 
    22from django.contrib.gis.gdal import DataSource, OGRException 
    3 from django.contrib.gis.gdal.Envelope import Envelope 
    4 from django.contrib.gis.gdal.Field import OFTReal, OFTInteger, OFTString 
     3from django.contrib.gis.gdal.envelope import Envelope 
     4from django.contrib.gis.gdal.field import OFTReal, OFTInteger, OFTString 
    55 
    66# Path for SHP files