| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
import os |
|---|
| 32 |
import sys |
|---|
| 33 |
import string |
|---|
| 34 |
|
|---|
| 35 |
sys.path.append( '../pymod' ) |
|---|
| 36 |
|
|---|
| 37 |
import gdaltest |
|---|
| 38 |
import ogrtest |
|---|
| 39 |
import ogr |
|---|
| 40 |
import gdal |
|---|
| 41 |
import osr; |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
def ogr_gxt_1(): |
|---|
| 47 |
|
|---|
| 48 |
gdaltest.gxt_ds = ogr.Open('data/expected_000_GRD.gxt' ) |
|---|
| 49 |
|
|---|
| 50 |
if gdaltest.gxt_ds is None: |
|---|
| 51 |
return 'fail' |
|---|
| 52 |
|
|---|
| 53 |
if gdaltest.gxt_ds.GetLayerCount() != 1: |
|---|
| 54 |
gdaltest.post_reason( 'Got wrong layer count.' ) |
|---|
| 55 |
return 'fail' |
|---|
| 56 |
|
|---|
| 57 |
lyr = gdaltest.gxt_ds.GetLayer(0) |
|---|
| 58 |
if lyr.GetName() != '000_GRD.000_GRD': |
|---|
| 59 |
gdaltest.post_reason( 'got unexpected layer name.' ) |
|---|
| 60 |
return 'fail' |
|---|
| 61 |
|
|---|
| 62 |
if lyr.GetFeatureCount() != 10: |
|---|
| 63 |
gdaltest.post_reason( 'got wrong feature count.' ) |
|---|
| 64 |
return 'fail' |
|---|
| 65 |
|
|---|
| 66 |
expect = [ '000-2007-0050-7130-LAMB93', |
|---|
| 67 |
'000-2007-0595-7130-LAMB93', |
|---|
| 68 |
'000-2007-0595-6585-LAMB93', |
|---|
| 69 |
'000-2007-1145-6250-LAMB93', |
|---|
| 70 |
'000-2007-0050-6585-LAMB93', |
|---|
| 71 |
'000-2007-0050-7130-LAMB93', |
|---|
| 72 |
'000-2007-0595-7130-LAMB93', |
|---|
| 73 |
'000-2007-0595-6585-LAMB93', |
|---|
| 74 |
'000-2007-1145-6250-LAMB93', |
|---|
| 75 |
'000-2007-0050-6585-LAMB93' ] |
|---|
| 76 |
|
|---|
| 77 |
tr = ogrtest.check_features_against_list( lyr, 'idSel', expect ) |
|---|
| 78 |
if not tr: |
|---|
| 79 |
return 'fail' |
|---|
| 80 |
|
|---|
| 81 |
lyr.ResetReading() |
|---|
| 82 |
|
|---|
| 83 |
feat = lyr.GetNextFeature() |
|---|
| 84 |
|
|---|
| 85 |
if ogrtest.check_feature_geometry(feat, |
|---|
| 86 |
'MULTIPOLYGON (((50000 7130000,600000 7130000,600000 6580000,50000 6580000,50000 7130000)))', |
|---|
| 87 |
max_error = 0.000000001 ) != 0: |
|---|
| 88 |
return 'fail' |
|---|
| 89 |
|
|---|
| 90 |
srs = osr.SpatialReference() |
|---|
| 91 |
srs.SetFromUserInput('PROJCS["Lambert 93",GEOGCS["unnamed",DATUM["ITRS-89",SPHEROID["GRS 80",6378137,298.257222099657],TOWGS84[0,0,0,0,0,0,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",44],PARAMETER["standard_parallel_2",49],PARAMETER["latitude_of_origin",46.5],PARAMETER["central_meridian",3],PARAMETER["false_easting",700000],PARAMETER["false_northing",6600000]]') |
|---|
| 92 |
|
|---|
| 93 |
if not lyr.GetSpatialRef().IsSame(srs): |
|---|
| 94 |
gdaltest.post_reason('SRS is not the one expected.') |
|---|
| 95 |
return 'fail' |
|---|
| 96 |
|
|---|
| 97 |
return 'success' |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
def ogr_gxt_2(): |
|---|
| 103 |
|
|---|
| 104 |
gdaltest.gxt_ds = ogr.Open('data/expected_000_GRD_TAB.txt' ) |
|---|
| 105 |
|
|---|
| 106 |
if gdaltest.gxt_ds is None: |
|---|
| 107 |
return 'fail' |
|---|
| 108 |
|
|---|
| 109 |
if gdaltest.gxt_ds.GetLayerCount() != 1: |
|---|
| 110 |
gdaltest.post_reason( 'Got wrong layer count.' ) |
|---|
| 111 |
return 'fail' |
|---|
| 112 |
|
|---|
| 113 |
lyr = gdaltest.gxt_ds.GetLayer(0) |
|---|
| 114 |
if lyr.GetName() != '000_GRD.000_GRD': |
|---|
| 115 |
gdaltest.post_reason( 'got unexpected layer name.' ) |
|---|
| 116 |
return 'fail' |
|---|
| 117 |
|
|---|
| 118 |
if lyr.GetFeatureCount() != 5: |
|---|
| 119 |
gdaltest.post_reason( 'got wrong feature count.' ) |
|---|
| 120 |
return 'fail' |
|---|
| 121 |
|
|---|
| 122 |
expect = [ '000-2007-0050-7130-LAMB93', |
|---|
| 123 |
'000-2007-0595-7130-LAMB93', |
|---|
| 124 |
'000-2007-0595-6585-LAMB93', |
|---|
| 125 |
'000-2007-1145-6250-LAMB93', |
|---|
| 126 |
'000-2007-0050-6585-LAMB93' ] |
|---|
| 127 |
|
|---|
| 128 |
tr = ogrtest.check_features_against_list( lyr, 'idSel', expect ) |
|---|
| 129 |
if not tr: |
|---|
| 130 |
return 'fail' |
|---|
| 131 |
|
|---|
| 132 |
lyr.ResetReading() |
|---|
| 133 |
|
|---|
| 134 |
feat = lyr.GetNextFeature() |
|---|
| 135 |
|
|---|
| 136 |
if ogrtest.check_feature_geometry(feat, |
|---|
| 137 |
'MULTIPOLYGON (((50000 7130000,600000 7130000,600000 6580000,50000 6580000,50000 7130000)))', |
|---|
| 138 |
max_error = 0.000000001 ) != 0: |
|---|
| 139 |
return 'fail' |
|---|
| 140 |
|
|---|
| 141 |
return 'success' |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
def ogr_gxt_3(): |
|---|
| 147 |
|
|---|
| 148 |
if gdaltest.gxt_ds is not None: |
|---|
| 149 |
gdaltest.gxt_ds.Destroy() |
|---|
| 150 |
gdaltest.gxt_ds = None |
|---|
| 151 |
|
|---|
| 152 |
src_ds = ogr.Open( 'data/points.gxt' ) |
|---|
| 153 |
|
|---|
| 154 |
try: |
|---|
| 155 |
os.remove ('tmp/tmp.gxt') |
|---|
| 156 |
except: |
|---|
| 157 |
pass |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
src_lyr = src_ds.GetLayerByName( 'points.points' ) |
|---|
| 161 |
|
|---|
| 162 |
gdaltest.gxt_ds = ogr.GetDriverByName('Geoconcept').CreateDataSource('tmp/tmp.gxt') |
|---|
| 163 |
|
|---|
| 164 |
srs = osr.SpatialReference() |
|---|
| 165 |
srs.SetWellKnownGeogCS( 'WGS84' ) |
|---|
| 166 |
|
|---|
| 167 |
gxt_lyr = gdaltest.gxt_ds.CreateLayer( 'points', srs, geom_type = ogr.wkbPoint ) |
|---|
| 168 |
|
|---|
| 169 |
src_lyr.ResetReading() |
|---|
| 170 |
|
|---|
| 171 |
for i in range(src_lyr.GetLayerDefn().GetFieldCount()): |
|---|
| 172 |
field_defn = src_lyr.GetLayerDefn().GetFieldDefn(i) |
|---|
| 173 |
gxt_lyr.CreateField( field_defn ) |
|---|
| 174 |
|
|---|
| 175 |
dst_feat = ogr.Feature( feature_def = gxt_lyr.GetLayerDefn() ) |
|---|
| 176 |
|
|---|
| 177 |
feat = src_lyr.GetNextFeature() |
|---|
| 178 |
while feat is not None: |
|---|
| 179 |
dst_feat.SetFrom( feat ) |
|---|
| 180 |
if gxt_lyr.CreateFeature( dst_feat ) != 0: |
|---|
| 181 |
gdaltest.post_reason('CreateFeature failed.') |
|---|
| 182 |
return 'fail' |
|---|
| 183 |
|
|---|
| 184 |
feat = src_lyr.GetNextFeature() |
|---|
| 185 |
|
|---|
| 186 |
dst_feat.Destroy() |
|---|
| 187 |
|
|---|
| 188 |
src_ds.Destroy() |
|---|
| 189 |
gdaltest.gxt_ds.Destroy() |
|---|
| 190 |
gdaltest.gxt_ds = None |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
gdaltest.gxt_ds = ogr.Open('tmp/tmp.gxt') |
|---|
| 195 |
gxt_lyr = gdaltest.gxt_ds.GetLayerByName( 'points.points' ) |
|---|
| 196 |
|
|---|
| 197 |
if not gxt_lyr.GetSpatialRef().IsSame(srs): |
|---|
| 198 |
gdaltest.post_reason('Output SRS is not the one expected.') |
|---|
| 199 |
return 'fail' |
|---|
| 200 |
|
|---|
| 201 |
expect = ['PID1', 'PID2'] |
|---|
| 202 |
|
|---|
| 203 |
tr = ogrtest.check_features_against_list( gxt_lyr, 'Primary_ID', expect ) |
|---|
| 204 |
if not tr: |
|---|
| 205 |
return 'fail' |
|---|
| 206 |
|
|---|
| 207 |
gxt_lyr.ResetReading() |
|---|
| 208 |
|
|---|
| 209 |
expect = ['SID1', 'SID2'] |
|---|
| 210 |
|
|---|
| 211 |
tr = ogrtest.check_features_against_list( gxt_lyr, 'Secondary_ID', expect ) |
|---|
| 212 |
if not tr: |
|---|
| 213 |
return 'fail' |
|---|
| 214 |
|
|---|
| 215 |
gxt_lyr.ResetReading() |
|---|
| 216 |
|
|---|
| 217 |
expect = ['TID1', None] |
|---|
| 218 |
|
|---|
| 219 |
tr = ogrtest.check_features_against_list( gxt_lyr, 'Third_ID', expect ) |
|---|
| 220 |
if not tr: |
|---|
| 221 |
return 'fail' |
|---|
| 222 |
|
|---|
| 223 |
gxt_lyr.ResetReading() |
|---|
| 224 |
|
|---|
| 225 |
feat = gxt_lyr.GetNextFeature() |
|---|
| 226 |
|
|---|
| 227 |
if ogrtest.check_feature_geometry(feat,'POINT(0 1)', |
|---|
| 228 |
max_error = 0.000000001 ) != 0: |
|---|
| 229 |
return 'fail' |
|---|
| 230 |
|
|---|
| 231 |
feat = gxt_lyr.GetNextFeature() |
|---|
| 232 |
|
|---|
| 233 |
if ogrtest.check_feature_geometry(feat,'POINT(2 3)', |
|---|
| 234 |
max_error = 0.000000001 ) != 0: |
|---|
| 235 |
return 'fail' |
|---|
| 236 |
|
|---|
| 237 |
return 'success' |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
def ogr_gxt_cleanup(): |
|---|
| 244 |
|
|---|
| 245 |
if gdaltest.gxt_ds is not None: |
|---|
| 246 |
gdaltest.gxt_ds.Destroy() |
|---|
| 247 |
gdaltest.gxt_ds = None |
|---|
| 248 |
try: |
|---|
| 249 |
os.remove ('tmp/tmp.gxt') |
|---|
| 250 |
except: |
|---|
| 251 |
pass |
|---|
| 252 |
return 'success' |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
gdaltest_list = [ |
|---|
| 256 |
ogr_gxt_1, |
|---|
| 257 |
ogr_gxt_2, |
|---|
| 258 |
ogr_gxt_3, |
|---|
| 259 |
ogr_gxt_cleanup, |
|---|
| 260 |
None ] |
|---|
| 261 |
|
|---|
| 262 |
if __name__ == '__main__': |
|---|
| 263 |
|
|---|
| 264 |
gdaltest.setup_run( 'ogr_gxt' ) |
|---|
| 265 |
|
|---|
| 266 |
gdaltest.run_tests( gdaltest_list ) |
|---|
| 267 |
|
|---|
| 268 |
gdaltest.summarize() |
|---|
| 269 |
|
|---|