Changeset 14393

Show
Ignore:
Timestamp:
05/08/08 09:28:50 (2 months ago)
Author:
rouault
Message:

Test FORMAT=WKT/WKB layer creation option, and SRID

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/autotest/ogr/ogr_sqlite.py

    r14262 r14393  
    420420     
    421421############################################################################### 
     422# Test FORMAT=WKB creation option 
     423 
     424def ogr_sqlite_11(): 
     425 
     426    if gdaltest.sl_ds is None: 
     427        return 'skip' 
     428 
     429    ###################################################### 
     430    # Create Layer with WKB geometry 
     431    gdaltest.sl_lyr = gdaltest.sl_ds.CreateLayer( 'geomwkb', options = [ 'FORMAT=WKB' ] ) 
     432 
     433    geom = ogr.CreateGeometryFromWkt( 'POINT(0 1)' ) 
     434    dst_feat = ogr.Feature( feature_def = gdaltest.sl_lyr.GetLayerDefn() ) 
     435    dst_feat.SetGeometry( geom ) 
     436    gdaltest.sl_lyr.CreateFeature( dst_feat ) 
     437    dst_feat.Destroy() 
     438 
     439    ###################################################### 
     440    # Reopen DB 
     441    gdaltest.sl_ds.Destroy() 
     442    gdaltest.sl_ds = ogr.Open( 'tmp/sqlite_test.db'  ) 
     443    gdaltest.sl_lyr = gdaltest.sl_ds.GetLayerByName('geomwkb') 
     444 
     445    feat_read = gdaltest.sl_lyr.GetNextFeature() 
     446    if ogrtest.check_feature_geometry(feat_read,geom,max_error = 0.001 ) != 0: 
     447        return 'fail' 
     448    feat_read.Destroy() 
     449 
     450    gdaltest.sl_lyr.ResetReading() 
     451 
     452    return 'success' 
     453 
     454############################################################################### 
     455# Test FORMAT=WKT creation option 
     456 
     457def ogr_sqlite_12(): 
     458 
     459    if gdaltest.sl_ds is None: 
     460        return 'skip' 
     461 
     462    ###################################################### 
     463    # Create Layer with WKB geometry 
     464    gdaltest.sl_lyr = gdaltest.sl_ds.CreateLayer( 'geomwkt', options = [ 'FORMAT=WKT' ] ) 
     465 
     466    geom = ogr.CreateGeometryFromWkt( 'POINT(0 1)' ) 
     467    dst_feat = ogr.Feature( feature_def = gdaltest.sl_lyr.GetLayerDefn() ) 
     468    dst_feat.SetGeometry( geom ) 
     469    gdaltest.sl_lyr.CreateFeature( dst_feat ) 
     470    dst_feat.Destroy() 
     471 
     472    ###################################################### 
     473    # Reopen DB 
     474    gdaltest.sl_ds.Destroy() 
     475    gdaltest.sl_ds = ogr.Open( 'tmp/sqlite_test.db'  ) 
     476    gdaltest.sl_lyr = gdaltest.sl_ds.GetLayerByName('geomwkt') 
     477 
     478    feat_read = gdaltest.sl_lyr.GetNextFeature() 
     479    if ogrtest.check_feature_geometry(feat_read,geom,max_error = 0.001 ) != 0: 
     480        return 'fail' 
     481    feat_read.Destroy() 
     482 
     483    gdaltest.sl_lyr.ResetReading() 
     484 
     485    sql_lyr = gdaltest.sl_ds.ExecuteSQL( "select * from geomwkt" ) 
     486 
     487    feat_read = gdaltest.sl_lyr.GetNextFeature() 
     488    if ogrtest.check_feature_geometry(feat_read,geom,max_error = 0.001 ) != 0: 
     489        return 'fail' 
     490    feat_read.Destroy() 
     491 
     492    gdaltest.sl_ds.ReleaseResultSet( sql_lyr ) 
     493 
     494    return 'success' 
     495 
     496############################################################################### 
     497# Test SRID support 
     498 
     499def ogr_sqlite_13(): 
     500 
     501    if gdaltest.sl_ds is None: 
     502        return 'skip' 
     503 
     504    ###################################################### 
     505    # Create Layer with EPSG:4326 
     506    srs = osr.SpatialReference() 
     507    srs.ImportFromEPSG( 4326 ) 
     508    gdaltest.sl_lyr = gdaltest.sl_ds.CreateLayer( 'wgs84layer', srs = srs ) 
     509 
     510    ###################################################### 
     511    # Reopen DB 
     512    gdaltest.sl_ds.Destroy() 
     513    gdaltest.sl_ds = ogr.Open( 'tmp/sqlite_test.db'  ) 
     514    gdaltest.sl_lyr = gdaltest.sl_ds.GetLayerByName('wgs84layer') 
     515 
     516    if not gdaltest.sl_lyr.GetSpatialRef().IsSame(srs): 
     517        gdaltest.post_reason('SRS is not the one expected.') 
     518        return 'fail' 
     519 
     520    ###################################################### 
     521    # Create second layer with very approximative EPSG:4326 
     522    srs = osr.SpatialReference('GEOGCS["WGS 84",AUTHORITY["EPSG","4326"]]') 
     523    gdaltest.sl_lyr = gdaltest.sl_ds.CreateLayer( 'wgs84layer_approx', srs = srs ) 
     524 
     525    # Must still be 1 
     526    sql_lyr = gdaltest.sl_ds.ExecuteSQL("SELECT COUNT(*) AS count FROM spatial_ref_sys"); 
     527    feat = sql_lyr.GetNextFeature() 
     528    if  feat.GetFieldAsInteger('count') != 1: 
     529        return 'fail' 
     530    gdaltest.sl_ds.ReleaseResultSet(sql_lyr) 
     531 
     532    return 'success' 
     533 
     534 
     535############################################################################### 
    422536#  
    423537 
     
    428542 
    429543    gdaltest.sl_ds.ExecuteSQL( 'DELLAYER:tpoly' ) 
     544    gdaltest.sl_ds.ExecuteSQL( 'DELLAYER:geomwkb' ) 
     545    gdaltest.sl_ds.ExecuteSQL( 'DELLAYER:geomwkt' ) 
     546    gdaltest.sl_ds.ExecuteSQL( 'DELLAYER:wgs84layer' ) 
     547    gdaltest.sl_ds.ExecuteSQL( 'DELLAYER:wgs84layer_approx' ) 
    430548 
    431549    gdaltest.sl_ds.Destroy() 
     
    450568    ogr_sqlite_9, 
    451569    ogr_sqlite_10, 
     570    ogr_sqlite_11, 
     571    ogr_sqlite_12, 
     572    ogr_sqlite_13, 
    452573    ogr_sqlite_cleanup ] 
    453574