Changeset 11099

Show
Ignore:
Timestamp:
03/30/07 16:06:24 (2 years ago)
Author:
hobu
Message:

backport Didrik's Geometry constructor patch for 1.4 in the old-gen bindings (#1255)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.4/gdal/pymod/ogr.py

    r9458 r11099  
    2929#  
    3030# $Log$ 
    31 # Revision 1.57  2006/04/02 18:33:14  fwarmerdam 
    32 # added OFTTime and OFTDateTime. 
    33 
    34 # Revision 1.56  2006/02/15 04:21:29  fwarmerdam 
    35 # added OFTDate support 
    36 
    37 # Revision 1.55  2006/01/27 16:16:54  fwarmerdam 
    38 # use internal OGRGetDriverByName 
    39 
    40 # Revision 1.54  2005/10/25 20:00:53  fwarmerdam 
    41 # driver tracking on datasource now in core 
    42 
    43 # Revision 1.53  2005/09/18 15:26:00  fwarmerdam 
    44 # added Distance method. 
    45 
    46 # Revision 1.52  2005/07/20 02:34:52  fwarmerdam 
    47 # fixed up AddPoint to default z 
    48 
    49 # Revision 1.51  2005/07/20 01:46:51  fwarmerdam 
    50 # ogr coordinate dimension upgrades 
    51 
    52 # Revision 1.50  2005/05/05 22:45:33  fwarmerdam 
    53 # Fixed Empty call ... only one argument. 
    54 
    55 # Revision 1.49  2005/03/02 17:42:46  hobu 
    56 # First pass at a __setattr__ for Feature 
    57 
    58 # Revision 1.48  2005/02/23 20:32:56  hobu 
    59 # retract slicing for Layers as implemented. 
    60 
    61 # Revision 1.47  2005/02/08 15:54:12  hobu 
    62 # Added more docstrings 
    63 
    64 # Revision 1.46  2005/02/07 21:37:06  hobu 
    65 # Docstring added to __getattr__ for Feature 
    66 
    67 # Revision 1.45  2005/02/07 16:52:28  hobu 
    68 # Added a __copy__ method for Geometry. 
    69 # Added capabilities constants for Driver, DataSource, 
    70 # and Layer.  Docstrings on the TestCapability methods 
    71 # for each as well. 
    72 
    73 # Revision 1.44  2005/02/05 18:38:42  hobu 
    74 # Added some more docstrings 
    75 
    76 # Revision 1.43  2005/02/05 18:11:53  hobu 
    77 # Allow the Geometry constructor to take in 
    78 # gml, wkt, wkb, and srs as keyword argmuments.  There 
    79 # was already a wkt argument, but no implementation behind it. 
    80 # The srs is used in the wkb and wkt contructors, otherwise it 
    81 # is not used 
    82 
    83 # Revision 1.42  2005/02/05 04:57:24  hobu 
    84 # Implemented __copy__ and a basic 
    85 # __getattr__ for Feature.  No special handling 
    86 # is done for wonky field name characters at this point. 
    87 
    88 # Revision 1.41  2005/02/03 14:22:16  fwarmerdam 
    89 # Added __str__ method on Geometry. 
    90 
    91 # Revision 1.40  2005/02/02 04:36:53  fwarmerdam 
    92 # Default index to 0 in geometry GetX/Y/Z. 
    93 # Added GetFeaturesRead() and SetNextByIndex() methods on layer. 
    94 
    95 # Revision 1.39  2005/01/22 23:47:06  hobu 
    96 # Support for slicing and index access on DataSources and Layers: 
    97 # for layer in ds: 
    98 #    do something 
    99 
    100 # for feature in layer: 
    101 #    do something 
    102 
    103 # This also means that we get list comprehension support 
    104 # [i.GetName() for i in ds[0:4]] 
    105 # or 
    106 # [i..GetFID() for feature in layer[0:]] 
    107 
    108 # *Note*-- some datasources do not always have sequential 
    109 # feature ids and slicing may not work as expected for all 
    110 # datasources. 
    111 
    112 # Support for len(ds) or len(layer) to return the number of 
    113 # layers in the datasource or features in the layer (these are 
    114 # simple wrappers around GetLayerCount() and GetFeatureCount()) 
    115 
    116 # A custom exception, OGRError, is now raised in many cases 
    117 # instead of generic IndexErrors or ValueErrors when the error 
    118 # is really coming from OGR not being able to read something. 
    119 
    120 # Reworked DataSource.GetLayer() to check the types of the input 
    121 # value (int or string) and call the appropriate OGR function to do so. 
    122 # __getitem__ in DataSource uses this function instead of switching 
    123 # between it and GetLayerByName(). 
    124 
    125 # Revision 1.38  2005/01/22 18:52:16  hobu 
    126 # passing _obj instead of obj in GetSpatialFilter in the Geometry 
    127 # constructor at the end of the function. 
    128 
    129 # Revision 1.37  2005/01/22 18:30:58  hobu 
    130 # typo in Layer::GetSpatialFilter 
    131 
    132 # Revision 1.36  2005/01/22 06:14:57  fwarmerdam 
    133 # added thisown support for geometry and feature 
    134 
    135 # Revision 1.35  2005/01/03 22:19:09  fwarmerdam 
    136 # added OGRLayer::SetSpatialFilterRect() 
    137 
    138 # Revision 1.34  2004/12/16 22:13:27  hobu 
    139 # typo in the Clone() method of Feature 
    140 
    141 # Revision 1.33  2004/11/25 20:16:30  fwarmerdam 
    142 # Fixed TransformTo() (bug 685). 
    143 
    144 # Revision 1.32  2004/10/27 18:27:33  fwarmerdam 
    145 # Fixed last fix? 
    146 
    147 # Revision 1.31  2004/10/25 10:07:41  dron 
    148 # Indentation problem fixed. 
    149 
    150 # Revision 1.30  2004/10/04 21:02:07  fwarmerdam 
    151 # Added Centroid() method 
    152 
    153 # Revision 1.29  2004/09/17 15:07:57  fwarmerdam 
    154 # added getArea 
    155 
    156 # Revision 1.28  2004/08/19 14:08:28  warmerda 
    157 # watch for NULL return values too in geos functions 
    158 
    159 # Revision 1.27  2004/07/12 15:10:56  warmerda 
    160 # Fix error case in CreateLayer(). 
    161 
    162 # Revision 1.26  2004/07/10 07:08:39  warmerda 
    163 # added new GEOS methods 
    164 
    165 # Revision 1.25  2004/07/10 05:05:24  warmerda 
    166 # added closerings 
    167 
    168 # Revision 1.24  2004/03/31 15:34:06  warmerda 
    169 # Added "name" parameter for FeatureDefn constructor. 
    170 
    171 # Revision 1.23  2004/03/18 18:55:53  warmerda 
    172 # Avoid using hex constants for large 25D geometry type values as it causes 
    173 # warnings on Python 2.3 and may have compatibility issues.   See: 
    174 # http://bugzilla.remotesensing.org/show_bug.cgi?id=521 
    175 
    176 # Revision 1.22  2004/02/25 15:14:59  warmerda 
    177 # added GetEnvelope() method on Geometry 
    178 
    179 # Revision 1.21  2004/01/06 18:18:53  warmerda 
    180 # improved error checking in geometry creation methods 
    181 
    182 # Revision 1.20  2003/12/09 20:09:59  warmerda 
    183 # No such function as OGR_Fld_GetName()! 
    184 
    185 # Revision 1.19  2003/12/05 18:01:24  warmerda 
    186 # added GetDriver() support on Datasource 
    187 
    188 # Revision 1.18  2003/10/09 15:27:53  warmerda 
    189 # added OGRLayer::DeleteFeature() support 
    190 
    191 # Revision 1.17  2003/10/06 22:28:54  warmerda 
    192 # Added support for GetExtent(). 
    193 
    194 # Revision 1.16  2003/09/22 05:48:50  warmerda 
    195 # added GML geometry support 
    196 
    197 # Revision 1.15  2003/09/13 04:57:06  warmerda 
    198 # fixed up NULL support for spatial references 
    199 
    200 # Revision 1.14  2003/08/27 15:40:06  warmerda 
    201 # added OGRSetGenerate_DB2_V72_BYTE_ORDER() 
    202 
    203 # Revision 1.13  2003/06/10 14:43:33  warmerda 
    204 # fixed NULL support in GetGeometryRef() 
    205 
    206 # Revision 1.12  2003/04/22 17:28:55  warmerda 
    207 # added SyncToDisk, fix DumpReadable 
    208 
    209 # Revision 1.11  2003/04/08 22:13:00  warmerda 
    210 # added new entry poins, and listtostringlist support 
    211 
    212 # Revision 1.10  2003/04/03 19:27:55  warmerda 
    213 # added nullable string support, fixed ogr.Layer.SetAttributeFilter() 
    214 
    215 # Revision 1.9  2003/03/20 17:53:30  warmerda 
    216 # added OGR OpenShared and reference coutnting stuff 
    217 
    218 # Revision 1.8  2003/03/07 16:28:55  warmerda 
    219 # lots of 'NULL' fixes 
    220 
    221 # Revision 1.7  2003/03/03 05:16:11  warmerda 
    222 # added DeleteLayer and DeleteDataSource methods 
    223 
    224 # Revision 1.6  2003/03/03 02:46:05  warmerda 
    225 # added ogr.Driver class 
    226 
    227 # Revision 1.5  2003/01/08 18:15:48  warmerda 
    228 # added loads of stuff 
    229 
    230 # Revision 1.4  2003/01/02 21:41:07  warmerda 
    231 # added GetField(), and BuildPolygonFromEdges methods 
    232 
    233 # Revision 1.3  2002/10/24 20:37:18  warmerda 
    234 # fixed srs support in CreateFrom functions 
    235 
    236 # Revision 1.2  2002/10/24 16:51:17  warmerda 
    237 # added lots of OGRGeometryH support 
    238 
    239 # Revision 1.1  2002/09/26 18:14:32  warmerda 
    240 # New 
    241 
    242 
     31 
    24332 
    24433import _gdal 
     
    1025814            self.thisown = 1 
    1026815        elif wkt: 
    1027             if srs
    1028                 return CreateGeometryFromWkt(wkt, srs) 
     816            if srs is None
     817                srs = '' 
    1029818            else: 
    1030                 return CreateGeometryFromWkt(wkt) 
     819                srs = srs._o 
     820            _obj = _gdal.OGR_G_CreateFromWkt(wkt, srs) 
     821            if _obj is not None and _obj != 'NULL': 
     822                self._o = _obj 
     823                self.thisown = 1 
    1031824        elif wkb: 
    1032             if srs
    1033                 return CreateGeometryFromWkb(wkb, srs) 
     825            if srs is None
     826                srs = '' 
    1034827            else: 
    1035                 return CreateGeometryFromWkb(wkb) 
     828                srs = srs._o 
     829            _obj = _gdal.OGR_G_CreateFromWkb(wkb, srs) 
     830            if _obj is not None and _obj != 'NULL': 
     831                self._o = _obj 
     832                self.thisown = 1 
    1036833        elif gml: 
    1037             return CreateGeometryFromGML(gml) 
     834            _obj = _gdal.OGR_G_CreateFromWkb(gml) 
     835            if _obj is not None and _obj != 'NULL': 
     836                self._o = _obj 
     837                self.thisown = 1 
    1038838        else: 
    1039839            raise OGRError, 'OGRGeometry may not be directly instantiated.'