#!/usr/bin/env python
###############################################################################
# $Id$
#
# Project:  GDAL/OGR Test Suite
# Purpose:  Test GPX driver functionality.
# Author:   Even Rouault <even dot rouault at mines dash paris dot org>
# 
###############################################################################
# Copyright (c) 2007, Even Rouault <even dot rouault at mines dash paris dot org>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
###############################################################################

import os
import sys
import string

sys.path.append( '../pymod' )

import gdaltest
import ogrtest
import ogr
import osr
import gdal

def ogr_gpx_init():
    gdaltest.gpx_ds = None

    try:
        gdaltest.gpx_ds = ogr.Open( 'data/test.gpx' )
    except:
        gdaltest.gpx_ds = None

    if gdaltest.gpx_ds is None:
        gdaltest.have_gpx = 0
    else:
        gdaltest.have_gpx = 1

    if not gdaltest.have_gpx:
        return 'skip'

    if gdaltest.gpx_ds.GetLayerCount() != 5:
        gdaltest.post_reason( 'wrong number of layers' )
        return 'fail'

    return 'success'

###############################################################################
# Test waypoints gpx layer.

def ogr_gpx_1():
    if not gdaltest.have_gpx:
        return 'skip'
    
    if gdaltest.gpx_ds is None:
        return 'fail'

    lyr = gdaltest.gpx_ds.GetLayerByName( 'waypoints' )
    
    expect = [2, None]

    tr = ogrtest.check_features_against_list( lyr, 'ele', expect )
    if not tr:
        return 'fail'
    
    lyr.ResetReading()
    
    expect = ['waypoint name', None]

    tr = ogrtest.check_features_against_list( lyr, 'name', expect )
    if not tr:
        return 'fail'
    
    lyr.ResetReading()
    
    expect = ['href', None]

    tr = ogrtest.check_features_against_list( lyr, 'link1_href', expect )
    if not tr:
        return 'fail'
    
    lyr.ResetReading()
    
    expect = ['text', None]

    tr = ogrtest.check_features_against_list( lyr, 'link1_text', expect )
    if not tr:
        return 'fail'
    
    lyr.ResetReading()
    
    expect = ['type', None]

    tr = ogrtest.check_features_against_list( lyr, 'link1_type', expect )
    if not tr:
        return 'fail'
    
    lyr.ResetReading()
    
    expect = ['href2', None]

    tr = ogrtest.check_features_against_list( lyr, 'link2_href', expect )
    if not tr:
        return 'fail'
    
    lyr.ResetReading()
    
    expect = ['text2', None]

    tr = ogrtest.check_features_against_list( lyr, 'link2_text', expect )
    if not tr:
        return 'fail'
    
    lyr.ResetReading()
    
    expect = ['type2', None]

    tr = ogrtest.check_features_against_list( lyr, 'link2_type', expect )
    if not tr:
        return 'fail'
    
    lyr.ResetReading()
    
    expect = ['2007/11/25 17:58:00+01', None]

    tr = ogrtest.check_features_against_list( lyr, 'time', expect )
    if not tr:
        return 'fail'

    lyr.ResetReading()
    feat = lyr.GetNextFeature()
    if ogrtest.check_feature_geometry( feat, 'POINT (1 0)',
                                       max_error = 0.0001 ) != 0:
        return 'fail'
    feat.Destroy()
    
    feat = lyr.GetNextFeature()
    if ogrtest.check_feature_geometry( feat, 'POINT (4 3)',
                                       max_error = 0.0001 ) != 0:
        return 'fail'
    feat.Destroy()
    
    return 'success'

###############################################################################
# Test routes gpx layer.

def ogr_gpx_2():
    if not gdaltest.have_gpx:
        return 'skip'
    
    if gdaltest.gpx_ds is None:
        return 'fail'

    lyr = gdaltest.gpx_ds.GetLayerByName( 'routes' )

    lyr.ResetReading()
    feat = lyr.GetNextFeature()
    if ogrtest.check_feature_geometry( feat, 'LINESTRING (6 5,9 8,12 11)', max_error = 0.0001 ) != 0:
        return 'fail'
    feat.Destroy()
    
    feat = lyr.GetNextFeature()
    if ogrtest.check_feature_geometry( feat, 'LINESTRING EMPTY', max_error = 0.0001 ) != 0:
        return 'fail'
    feat.Destroy()
    
    return 'success'


###############################################################################
# Test route_points gpx layer.

def ogr_gpx_3():
    if not gdaltest.have_gpx:
        return 'skip'
    
    if gdaltest.gpx_ds is None:
        return 'fail'

    lyr = gdaltest.gpx_ds.GetLayerByName( 'route_points' )

    expect = ['route point name', None, None]

    tr = ogrtest.check_features_against_list( lyr, 'name', expect )
    
    lyr.ResetReading()
    feat = lyr.GetNextFeature()
    if ogrtest.check_feature_geometry( feat, 'POINT (6 5)', max_error = 0.0001 ) != 0:
        return 'fail'
    feat.Destroy()
    
    return 'success'

###############################################################################
# Test tracks gpx layer.

def ogr_gpx_4():
    if not gdaltest.have_gpx:
        return 'skip'

    if gdaltest.gpx_ds is None:
        return 'fail'

    lyr = gdaltest.gpx_ds.GetLayerByName( 'tracks' )

    lyr.ResetReading()
    feat = lyr.GetNextFeature()
    if ogrtest.check_feature_geometry( feat, 'MULTILINESTRING ((15 14,18 17),(21 20,24 23))', max_error = 0.0001 ) != 0:
        return 'fail'
    feat.Destroy()
    
    feat = lyr.GetNextFeature()
    if ogrtest.check_feature_geometry( feat, 'MULTILINESTRING EMPTY', max_error = 0.0001 ) != 0:
        return 'fail'
    feat.Destroy()
    
    feat = lyr.GetNextFeature()
    f_geom = feat.GetGeometryRef()
    if f_geom.ExportToWkt()!= 'MULTILINESTRING EMPTY':
        return 'fail'
    feat.Destroy()
    
    return 'success'

###############################################################################
# Test route_points gpx layer.

def ogr_gpx_5():
    if not gdaltest.have_gpx:
        return 'skip'
    
    if gdaltest.gpx_ds is None:
        return 'fail'

    lyr = gdaltest.gpx_ds.GetLayerByName( 'track_points' )

    expect = ['track point name', None, None, None]

    tr = ogrtest.check_features_against_list( lyr, 'name', expect )
    
    lyr.ResetReading()
    feat = lyr.GetNextFeature()
    if ogrtest.check_feature_geometry( feat, 'POINT (15 14)', max_error = 0.0001 ) != 0:
        return 'fail'
    feat.Destroy()
    
    return 'success'

###############################################################################
# Copy our small gpx file to a new gpx file. 

def ogr_gpx_6():
    if not gdaltest.have_gpx:
        return 'skip'
    
    if gdaltest.gpx_ds is None:
        return 'skip'
    
    try:
        gdal.PushErrorHandler( 'CPLQuietErrorHandler' )
        ogr.GetDriverByName('CSV').DeleteDataSource( 'tmp/gpx.gpx' )
        gdal.PopErrorHandler()
    except:
        pass

    co_opts = [ ]
    
    # Duplicate waypoints
    gpx_lyr = gdaltest.gpx_ds.GetLayerByName( 'waypoints' )

    gpx2_ds = ogr.GetDriverByName('GPX').CreateDataSource('tmp/gpx.gpx',
                                                          options = co_opts )

    gpx2_lyr = gpx2_ds.CreateLayer( 'waypoints', geom_type = ogr.wkbPoint )

    gpx_lyr.ResetReading()

    dst_feat = ogr.Feature( feature_def = gpx2_lyr.GetLayerDefn() )
    
    feat = gpx_lyr.GetNextFeature()
    while feat is not None:
        dst_feat.SetFrom( feat )
        if gpx2_lyr.CreateFeature( dst_feat ) != 0:
            gdaltest.post_reason('CreateFeature failed.')
            return 'fail'

        feat = gpx_lyr.GetNextFeature()

    dst_feat.Destroy()

    # Duplicate routes
    gpx_lyr = gdaltest.gpx_ds.GetLayerByName( 'routes' )

    gpx2_lyr = gpx2_ds.CreateLayer( 'routes', geom_type = ogr.wkbLineString )

    gpx_lyr.ResetReading()

    dst_feat = ogr.Feature( feature_def = gpx2_lyr.GetLayerDefn() )
    
    feat = gpx_lyr.GetNextFeature()
    while feat is not None:
        dst_feat.SetFrom( feat )
        if gpx2_lyr.CreateFeature( dst_feat ) != 0:
            gdaltest.post_reason('CreateFeature failed.')
            return 'fail'

        feat = gpx_lyr.GetNextFeature()

    dst_feat.Destroy()
    
    # Duplicate tracks
    gpx_lyr = gdaltest.gpx_ds.GetLayerByName( 'tracks' )

    gpx2_lyr = gpx2_ds.CreateLayer( 'tracks', geom_type = ogr.wkbMultiLineString )

    gpx_lyr.ResetReading()

    dst_feat = ogr.Feature( feature_def = gpx2_lyr.GetLayerDefn() )
    
    feat = gpx_lyr.GetNextFeature()
    while feat is not None:
        dst_feat.SetFrom( feat )
        if gpx2_lyr.CreateFeature( dst_feat ) != 0:
            gdaltest.post_reason('CreateFeature failed.')
            return 'fail'

        feat = gpx_lyr.GetNextFeature()

    dst_feat.Destroy()
    
    gpx_lyr = None
    gpx2_lyr = None

    # Explicit destroy is required for old-gen python bindings
    gpx2_ds.Destroy()
    gdaltest.gpx_ds.Destroy()

    gdaltest.gpx_ds = ogr.Open( 'tmp/gpx.gpx' )

    return 'success'

###############################################################################
# Output extra fields as <extensions>. 

def ogr_gpx_7():
    if not gdaltest.have_gpx:
        return 'skip'

    if gdaltest.gpx_ds is not None:
        gdaltest.gpx_ds.Destroy()
    gdaltest.gpx_ds = None
    
    bna_ds = ogr.Open( 'data/bna_for_gpx.bna' )
    
    try:
        os.remove ('tmp/gpx.gpx')
    except:
        pass

    co_opts = [ 'GPX_USE_EXTENSIONS=yes' ]

    # Duplicate waypoints
    bna_lyr = bna_ds.GetLayerByName( 'bna_for_gpx_points' )

    gdaltest.gpx_ds = ogr.GetDriverByName('GPX').CreateDataSource('tmp/gpx.gpx',
                                                          options = co_opts )

    gpx_lyr = gdaltest.gpx_ds.CreateLayer( 'waypoints', geom_type = ogr.wkbPoint )

    bna_lyr.ResetReading()

    for i in range(bna_lyr.GetLayerDefn().GetFieldCount()):
        field_defn = bna_lyr.GetLayerDefn().GetFieldDefn(i)
        gpx_lyr.CreateField( field_defn )

    dst_feat = ogr.Feature( feature_def = gpx_lyr.GetLayerDefn() )

    feat = bna_lyr.GetNextFeature()
    while feat is not None:
        dst_feat.SetFrom( feat )
        if gpx_lyr.CreateFeature( dst_feat ) != 0:
            gdaltest.post_reason('CreateFeature failed.')
            return 'fail'

        feat = bna_lyr.GetNextFeature()

    dst_feat.Destroy()

    bna_ds.Destroy()
    gdaltest.gpx_ds.Destroy()
    gdaltest.gpx_ds = None
    
#Now check that the extensions fields have been well written
    gdaltest.gpx_ds = ogr.Open('tmp/gpx.gpx')
    gpx_lyr = gdaltest.gpx_ds.GetLayerByName( 'waypoints' )
    
    expect = ['PID1', 'PID2']

    tr = ogrtest.check_features_against_list( gpx_lyr, 'ogr_Primary_ID', expect )
    if not tr:
        return 'fail'
    
    gpx_lyr.ResetReading()
    
    expect = ['SID1', 'SID2']

    tr = ogrtest.check_features_against_list( gpx_lyr, 'ogr_Secondary_ID', expect )
    if not tr:
        return 'fail'
    
    gpx_lyr.ResetReading()
    
    expect = ['TID1', None]

    tr = ogrtest.check_features_against_list( gpx_lyr, 'ogr_Third_ID', expect )
    if not tr:
        return 'fail'

    return 'success'

###############################################################################
# Output extra fields as <extensions>. 

def ogr_gpx_8():
    if not gdaltest.have_gpx:
        return 'skip'

    if gdaltest.gpx_ds is not None:
        gdaltest.gpx_ds.Destroy()
    gdaltest.gpx_ds = None

    try:
        os.remove ('tmp/gpx.gpx')
    except:
        pass

    gdaltest.gpx_ds = ogr.GetDriverByName('GPX').CreateDataSource('tmp/gpx.gpx', options = ['LINEFORMAT=LF'])

    lyr = gdaltest.gpx_ds.CreateLayer( 'route_points', geom_type = ogr.wkbPoint )

    feat = ogr.Feature(lyr.GetLayerDefn())
    geom = ogr.CreateGeometryFromWkt('POINT(2 49)')
    feat.SetField('route_name', 'ROUTE_NAME')
    feat.SetField('route_fid', 0)
    feat.SetGeometry(geom)
    lyr.CreateFeature(feat)

    feat = ogr.Feature(lyr.GetLayerDefn())
    geom = ogr.CreateGeometryFromWkt('POINT(3 50)')
    feat.SetField('route_name', '--ignored--')
    feat.SetField('route_fid', 0)
    feat.SetGeometry(geom)
    lyr.CreateFeature(feat)

    feat = ogr.Feature(lyr.GetLayerDefn())
    geom = ogr.CreateGeometryFromWkt('POINT(3 51)')
    feat.SetField('route_name', 'ROUTE_NAME2')
    feat.SetField('route_fid', 1)
    feat.SetGeometry(geom)
    lyr.CreateFeature(feat)

    feat = ogr.Feature(lyr.GetLayerDefn())
    geom = ogr.CreateGeometryFromWkt('POINT(3 49)')
    feat.SetField('route_fid', 1)
    feat.SetGeometry(geom)
    lyr.CreateFeature(feat)

    lyr = gdaltest.gpx_ds.CreateLayer( 'track_points', geom_type = ogr.wkbPoint )

    feat = ogr.Feature(lyr.GetLayerDefn())
    geom = ogr.CreateGeometryFromWkt('POINT(2 49)')
    feat.SetField('track_name', 'TRACK_NAME')
    feat.SetField('track_fid', 0)
    feat.SetField('track_seg_id', 0)
    feat.SetGeometry(geom)
    lyr.CreateFeature(feat)

    feat = ogr.Feature(lyr.GetLayerDefn())
    geom = ogr.CreateGeometryFromWkt('POINT(3 50)')
    feat.SetField('track_name', '--ignored--')
    feat.SetField('track_fid', 0)
    feat.SetField('track_seg_id', 0)
    feat.SetGeometry(geom)
    lyr.CreateFeature(feat)

    feat = ogr.Feature(lyr.GetLayerDefn())
    geom = ogr.CreateGeometryFromWkt('POINT(3 51)')
    feat.SetField('track_fid', 0)
    feat.SetField('track_seg_id', 1)
    feat.SetGeometry(geom)
    lyr.CreateFeature(feat)

    feat = ogr.Feature(lyr.GetLayerDefn())
    geom = ogr.CreateGeometryFromWkt('POINT(3 49)')
    feat.SetField('track_name', 'TRACK_NAME2')
    feat.SetField('track_fid', 1)
    feat.SetField('track_seg_id', 0)
    feat.SetGeometry(geom)
    lyr.CreateFeature(feat)

    gdaltest.gpx_ds.Destroy()
    gdaltest.gpx_ds = None

    f = open('tmp/gpx.gpx','rb')
    f_ref = open('data/ogr_gpx_8_ref.txt','rb')
    f_content = f.read()
    f_ref_content = f_ref.read()
    f.close()
    f_ref.close()

    if f_content.find(f_ref_content) == -1:
        gdaltest.post_reason('did not get expected result')
        print(f_content)
        return 'fail'

    return 'success'

###############################################################################
# 

def ogr_gpx_cleanup():

    if gdaltest.gpx_ds is not None:
        gdaltest.gpx_ds.Destroy()
    gdaltest.gpx_ds = None
    try:
        os.remove ('tmp/gpx.gpx')
    except:
        pass
    return 'success'

gdaltest_list = [ 
    ogr_gpx_init,
    ogr_gpx_1,
    ogr_gpx_2,
    ogr_gpx_3,
    ogr_gpx_4,
    ogr_gpx_5,
    ogr_gpx_6,
# Rerun test 1, 2 and 4 with generated tmp/tmp.gpx
    ogr_gpx_1,
    ogr_gpx_2,
    ogr_gpx_4,
    ogr_gpx_7,
    ogr_gpx_8,
    ogr_gpx_cleanup ]

if __name__ == '__main__':

    gdaltest.setup_run( 'ogr_gpx' )

    gdaltest.run_tests( gdaltest_list )

    gdaltest.summarize()


[((35, 0, 35, 29), 'sys.path.append', 'sys.path.append', ({(35, 17, 35, 27): '"""../pymod"""'}, {}), "('../pymod')", False, 'import sys\n'), ((75, 10, 75, 55), 'gdaltest.gpx_ds.GetLayerByName', 'gdaltest.gpx_ds.GetLayerByName', ({(75, 42, 75, 53): '"""waypoints"""'}, {}), "('waypoints')", False, 'import gdaltest\n'), ((79, 9, 79, 66), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(79, 46, 79, 49): 'lyr', (79, 51, 79, 56): '"""ele"""', (79, 58, 79, 64): 'expect'}, {}), "(lyr, 'ele', expect)", False, 'import ogrtest\n'), ((87, 9, 87, 67), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(87, 46, 87, 49): 'lyr', (87, 51, 87, 57): '"""name"""', (87, 59, 87, 65): 'expect'}, {}), "(lyr, 'name', expect)", False, 'import ogrtest\n'), ((95, 9, 95, 73), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(95, 46, 95, 49): 'lyr', (95, 51, 95, 63): '"""link1_href"""', (95, 65, 95, 71): 'expect'}, {}), "(lyr, 'link1_href', expect)", False, 'import ogrtest\n'), ((103, 9, 103, 73), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(103, 46, 103, 49): 'lyr', (103, 51, 103, 63): '"""link1_text"""', (103, 65, 103, 71): 'expect'}, {}), "(lyr, 'link1_text', expect)", False, 'import ogrtest\n'), ((111, 9, 111, 73), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(111, 46, 111, 49): 'lyr', (111, 51, 111, 63): '"""link1_type"""', (111, 65, 111, 71): 'expect'}, {}), "(lyr, 'link1_type', expect)", False, 'import ogrtest\n'), ((119, 9, 119, 73), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(119, 46, 119, 49): 'lyr', (119, 51, 119, 63): '"""link2_href"""', (119, 65, 119, 71): 'expect'}, {}), "(lyr, 'link2_href', expect)", False, 'import ogrtest\n'), ((127, 9, 127, 73), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(127, 46, 127, 49): 'lyr', (127, 51, 127, 63): '"""link2_text"""', (127, 65, 127, 71): 'expect'}, {}), "(lyr, 'link2_text', expect)", False, 'import ogrtest\n'), ((135, 9, 135, 73), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(135, 46, 135, 49): 'lyr', (135, 51, 135, 63): '"""link2_type"""', (135, 65, 135, 71): 'expect'}, {}), "(lyr, 'link2_type', expect)", False, 'import ogrtest\n'), ((143, 9, 143, 67), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(143, 46, 143, 49): 'lyr', (143, 51, 143, 57): '"""time"""', (143, 59, 143, 65): 'expect'}, {}), "(lyr, 'time', expect)", False, 'import ogrtest\n'), ((172, 10, 172, 52), 'gdaltest.gpx_ds.GetLayerByName', 'gdaltest.gpx_ds.GetLayerByName', ({(172, 42, 172, 50): '"""routes"""'}, {}), "('routes')", False, 'import gdaltest\n'), ((198, 10, 198, 58), 'gdaltest.gpx_ds.GetLayerByName', 'gdaltest.gpx_ds.GetLayerByName', ({(198, 42, 198, 56): '"""route_points"""'}, {}), "('route_points')", False, 'import gdaltest\n'), ((202, 9, 202, 67), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(202, 46, 202, 49): 'lyr', (202, 51, 202, 57): '"""name"""', (202, 59, 202, 65): 'expect'}, {}), "(lyr, 'name', expect)", False, 'import ogrtest\n'), ((222, 10, 222, 52), 'gdaltest.gpx_ds.GetLayerByName', 'gdaltest.gpx_ds.GetLayerByName', ({(222, 42, 222, 50): '"""tracks"""'}, {}), "('tracks')", False, 'import gdaltest\n'), ((253, 10, 253, 58), 'gdaltest.gpx_ds.GetLayerByName', 'gdaltest.gpx_ds.GetLayerByName', ({(253, 42, 253, 56): '"""track_points"""'}, {}), "('track_points')", False, 'import gdaltest\n'), ((257, 9, 257, 67), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(257, 46, 257, 49): 'lyr', (257, 51, 257, 57): '"""name"""', (257, 59, 257, 65): 'expect'}, {}), "(lyr, 'name', expect)", False, 'import ogrtest\n'), ((287, 14, 287, 59), 'gdaltest.gpx_ds.GetLayerByName', 'gdaltest.gpx_ds.GetLayerByName', ({(287, 46, 287, 57): '"""waypoints"""'}, {}), "('waypoints')", False, 'import gdaltest\n'), ((310, 14, 310, 56), 'gdaltest.gpx_ds.GetLayerByName', 'gdaltest.gpx_ds.GetLayerByName', ({(310, 46, 310, 54): '"""routes"""'}, {}), "('routes')", False, 'import gdaltest\n'), ((330, 14, 330, 56), 'gdaltest.gpx_ds.GetLayerByName', 'gdaltest.gpx_ds.GetLayerByName', ({(330, 46, 330, 54): '"""tracks"""'}, {}), "('tracks')", False, 'import gdaltest\n'), ((354, 4, 354, 29), 'gdaltest.gpx_ds.Destroy', 'gdaltest.gpx_ds.Destroy', ({}, {}), '()', False, 'import gdaltest\n'), ((356, 22, 356, 47), 'ogr.Open', 'ogr.Open', ({(356, 32, 356, 45): '"""tmp/gpx.gpx"""'}, {}), "('tmp/gpx.gpx')", False, 'import ogr\n'), ((371, 13, 371, 47), 'ogr.Open', 'ogr.Open', ({(371, 23, 371, 45): '"""data/bna_for_gpx.bna"""'}, {}), "('data/bna_for_gpx.bna')", False, 'import ogr\n'), ((386, 14, 386, 82), 'gdaltest.gpx_ds.CreateLayer', 'gdaltest.gpx_ds.CreateLayer', (), '', False, 'import gdaltest\n'), ((408, 4, 408, 29), 'gdaltest.gpx_ds.Destroy', 'gdaltest.gpx_ds.Destroy', ({}, {}), '()', False, 'import gdaltest\n'), ((412, 22, 412, 45), 'ogr.Open', 'ogr.Open', ({(412, 31, 412, 44): '"""tmp/gpx.gpx"""'}, {}), "('tmp/gpx.gpx')", False, 'import ogr\n'), ((413, 14, 413, 59), 'gdaltest.gpx_ds.GetLayerByName', 'gdaltest.gpx_ds.GetLayerByName', ({(413, 46, 413, 57): '"""waypoints"""'}, {}), "('waypoints')", False, 'import gdaltest\n'), ((417, 9, 417, 81), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(417, 46, 417, 53): 'gpx_lyr', (417, 55, 417, 71): '"""ogr_Primary_ID"""', (417, 73, 417, 79): 'expect'}, {}), "(gpx_lyr, 'ogr_Primary_ID', expect)", False, 'import ogrtest\n'), ((425, 9, 425, 83), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(425, 46, 425, 53): 'gpx_lyr', (425, 55, 425, 73): '"""ogr_Secondary_ID"""', (425, 75, 425, 81): 'expect'}, {}), "(gpx_lyr, 'ogr_Secondary_ID', expect)", False, 'import ogrtest\n'), ((433, 9, 433, 79), 'ogrtest.check_features_against_list', 'ogrtest.check_features_against_list', ({(433, 46, 433, 53): 'gpx_lyr', (433, 55, 433, 69): '"""ogr_Third_ID"""', (433, 71, 433, 77): 'expect'}, {}), "(gpx_lyr, 'ogr_Third_ID', expect)", False, 'import ogrtest\n'), ((457, 10, 457, 81), 'gdaltest.gpx_ds.CreateLayer', 'gdaltest.gpx_ds.CreateLayer', (), '', False, 'import gdaltest\n'), ((460, 11, 460, 51), 'ogr.CreateGeometryFromWkt', 'ogr.CreateGeometryFromWkt', ({(460, 37, 460, 50): '"""POINT(2 49)"""'}, {}), "('POINT(2 49)')", False, 'import ogr\n'), ((467, 11, 467, 51), 'ogr.CreateGeometryFromWkt', 'ogr.CreateGeometryFromWkt', ({(467, 37, 467, 50): '"""POINT(3 50)"""'}, {}), "('POINT(3 50)')", False, 'import ogr\n'), ((474, 11, 474, 51), 'ogr.CreateGeometryFromWkt', 'ogr.CreateGeometryFromWkt', ({(474, 37, 474, 50): '"""POINT(3 51)"""'}, {}), "('POINT(3 51)')", False, 'import ogr\n'), ((481, 11, 481, 51), 'ogr.CreateGeometryFromWkt', 'ogr.CreateGeometryFromWkt', ({(481, 37, 481, 50): '"""POINT(3 49)"""'}, {}), "('POINT(3 49)')", False, 'import ogr\n'), ((486, 10, 486, 81), 'gdaltest.gpx_ds.CreateLayer', 'gdaltest.gpx_ds.CreateLayer', (), '', False, 'import gdaltest\n'), ((489, 11, 489, 51), 'ogr.CreateGeometryFromWkt', 'ogr.CreateGeometryFromWkt', ({(489, 37, 489, 50): '"""POINT(2 49)"""'}, {}), "('POINT(2 49)')", False, 'import ogr\n'), ((497, 11, 497, 51), 'ogr.CreateGeometryFromWkt', 'ogr.CreateGeometryFromWkt', ({(497, 37, 497, 50): '"""POINT(3 50)"""'}, {}), "('POINT(3 50)')", False, 'import ogr\n'), ((505, 11, 505, 51), 'ogr.CreateGeometryFromWkt', 'ogr.CreateGeometryFromWkt', ({(505, 37, 505, 50): '"""POINT(3 51)"""'}, {}), "('POINT(3 51)')", False, 'import ogr\n'), ((512, 11, 512, 51), 'ogr.CreateGeometryFromWkt', 'ogr.CreateGeometryFromWkt', ({(512, 37, 512, 50): '"""POINT(3 49)"""'}, {}), "('POINT(3 49)')", False, 'import ogr\n'), ((519, 4, 519, 29), 'gdaltest.gpx_ds.Destroy', 'gdaltest.gpx_ds.Destroy', ({}, {}), '()', False, 'import gdaltest\n'), ((568, 4, 568, 35), 'gdaltest.setup_run', 'gdaltest.setup_run', ({(568, 24, 568, 33): '"""ogr_gpx"""'}, {}), "('ogr_gpx')", False, 'import gdaltest\n'), ((570, 4, 570, 39), 'gdaltest.run_tests', 'gdaltest.run_tests', ({(570, 24, 570, 37): 'gdaltest_list'}, {}), '(gdaltest_list)', False, 'import gdaltest\n'), ((572, 4, 572, 24), 'gdaltest.summarize', 'gdaltest.summarize', ({}, {}), '()', False, 'import gdaltest\n'), ((47, 26, 47, 53), 'ogr.Open', 'ogr.Open', ({(47, 36, 47, 51): '"""data/test.gpx"""'}, {}), "('data/test.gpx')", False, 'import ogr\n'), ((59, 7, 59, 38), 'gdaltest.gpx_ds.GetLayerCount', 'gdaltest.gpx_ds.GetLayerCount', ({}, {}), '()', False, 'import gdaltest\n'), ((60, 8, 60, 56), 'gdaltest.post_reason', 'gdaltest.post_reason', ({(60, 30, 60, 54): '"""wrong number of layers"""'}, {}), "('wrong number of layers')", False, 'import gdaltest\n'), ((149, 7, 150, 59), 'ogrtest.check_feature_geometry', 'ogrtest.check_feature_geometry', (), '', False, 'import ogrtest\n'), ((155, 7, 156, 59), 'ogrtest.check_feature_geometry', 'ogrtest.check_feature_geometry', (), '', False, 'import ogrtest\n'), ((176, 7, 176, 95), 'ogrtest.check_feature_geometry', 'ogrtest.check_feature_geometry', (), '', False, 'import ogrtest\n'), ((181, 7, 181, 85), 'ogrtest.check_feature_geometry', 'ogrtest.check_feature_geometry', (), '', False, 'import ogrtest\n'), ((206, 7, 206, 80), 'ogrtest.check_feature_geometry', 'ogrtest.check_feature_geometry', (), '', False, 'import ogrtest\n'), ((226, 7, 226, 114), 'ogrtest.check_feature_geometry', 'ogrtest.check_feature_geometry', (), '', False, 'import ogrtest\n'), ((231, 7, 231, 90), 'ogrtest.check_feature_geometry', 'ogrtest.check_feature_geometry', (), '', False, 'import ogrtest\n'), ((261, 7, 261, 82), 'ogrtest.check_feature_geometry', 'ogrtest.check_feature_geometry', (), '', False, 'import ogrtest\n'), ((278, 8, 278, 55), 'gdal.PushErrorHandler', 'gdal.PushErrorHandler', ({(278, 31, 278, 53): '"""CPLQuietErrorHandler"""'}, {}), "('CPLQuietErrorHandler')", False, 'import gdal\n'), ((280, 8, 280, 30), 'gdal.PopErrorHandler', 'gdal.PopErrorHandler', ({}, {}), '()', False, 'import gdal\n'), ((368, 8, 368, 33), 'gdaltest.gpx_ds.Destroy', 'gdaltest.gpx_ds.Destroy', ({}, {}), '()', False, 'import gdaltest\n'), ((374, 8, 374, 33), 'os.remove', 'os.remove', ({(374, 19, 374, 32): '"""tmp/gpx.gpx"""'}, {}), "('tmp/gpx.gpx')", False, 'import os\n'), ((447, 8, 447, 33), 'gdaltest.gpx_ds.Destroy', 'gdaltest.gpx_ds.Destroy', ({}, {}), '()', False, 'import gdaltest\n'), ((451, 8, 451, 33), 'os.remove', 'os.remove', ({(451, 19, 451, 32): '"""tmp/gpx.gpx"""'}, {}), "('tmp/gpx.gpx')", False, 'import os\n'), ((530, 8, 530, 59), 'gdaltest.post_reason', 'gdaltest.post_reason', ({(530, 29, 530, 58): '"""did not get expected result"""'}, {}), "('did not get expected result')", False, 'import gdaltest\n'), ((542, 8, 542, 33), 'gdaltest.gpx_ds.Destroy', 'gdaltest.gpx_ds.Destroy', ({}, {}), '()', False, 'import gdaltest\n'), ((545, 8, 545, 33), 'os.remove', 'os.remove', ({(545, 19, 545, 32): '"""tmp/gpx.gpx"""'}, {}), "('tmp/gpx.gpx')", False, 'import os\n'), ((289, 14, 289, 40), 'ogr.GetDriverByName', 'ogr.GetDriverByName', ({(289, 34, 289, 39): '"""GPX"""'}, {}), "('GPX')", False, 'import ogr\n'), ((302, 12, 302, 57), 'gdaltest.post_reason', 'gdaltest.post_reason', ({(302, 33, 302, 56): '"""CreateFeature failed."""'}, {}), "('CreateFeature failed.')", False, 'import gdaltest\n'), ((322, 12, 322, 57), 'gdaltest.post_reason', 'gdaltest.post_reason', ({(322, 33, 322, 56): '"""CreateFeature failed."""'}, {}), "('CreateFeature failed.')", False, 'import gdaltest\n'), ((342, 12, 342, 57), 'gdaltest.post_reason', 'gdaltest.post_reason', ({(342, 33, 342, 56): '"""CreateFeature failed."""'}, {}), "('CreateFeature failed.')", False, 'import gdaltest\n'), ((383, 22, 383, 48), 'ogr.GetDriverByName', 'ogr.GetDriverByName', ({(383, 42, 383, 47): '"""GPX"""'}, {}), "('GPX')", False, 'import ogr\n'), ((400, 12, 400, 57), 'gdaltest.post_reason', 'gdaltest.post_reason', ({(400, 33, 400, 56): '"""CreateFeature failed."""'}, {}), "('CreateFeature failed.')", False, 'import gdaltest\n'), ((455, 22, 455, 48), 'ogr.GetDriverByName', 'ogr.GetDriverByName', ({(455, 42, 455, 47): '"""GPX"""'}, {}), "('GPX')", False, 'import ogr\n'), ((279, 8, 279, 34), 'ogr.GetDriverByName', 'ogr.GetDriverByName', ({(279, 28, 279, 33): '"""CSV"""'}, {}), "('CSV')", False, 'import ogr\n')]