Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update drvsupport test (PCIDSK, GMT, PDS) #902

Closed
wants to merge 7 commits into from

Conversation

rbuffat
Copy link
Contributor

@rbuffat rbuffat commented May 20, 2020

I noticed that the test to append data only looks at the number of features is not enough to test the PCIDSK driver correctly.

This PR modifies the drvsupport tests to compare the written data with the result. Ideally, the input records would be compared to the output records, but this is tricky, as some drivers add fields (e.g. the Shapefile driver adds a FID field). This PR only looks at one property (if the field type is supported), respectively checks if the coordinate is correct otherwise.

Additionally, this PR enables the OGR_PDS and OGR_GMT drivers. It looks as they were renamed with GDAL 2.x. Thus I suppose they are not often used in combination with Fiona.

from collections import OrderedDict
import pprint
import fiona
import os

schema = {'geometry': 'Point', 'properties': OrderedDict([('position', 'int')])}
records1 = [{'geometry': {'type': 'Point', 'coordinates': (0.0, float(i))}, 'properties': {'position': i}} for i in range(0, 2)]
records2 = [{'geometry': {'type': 'Point', 'coordinates': (0.0, float(i))}, 'properties': {'position': i}} for i in range(5, 10)]
filename = '/tmp/test.pix'
driver = "PCIDSK"

if os.path.exists(filename):
    os.unlink(filename)

with fiona.open(filename,
                mode='w',
                driver=driver,
                schema=schema) as out:
    out.writerecords(records1)

with fiona.open(filename,
                mode='a',
                driver=driver,
                schema=schema) as out:
    out.writerecords(records2)

with fiona.open(filename) as c:
    for f in c:
        pprint.pprint(f)

Output:

{'geometry': {'coordinates': (0.0, 5.0, 0.0), 'type': 'Point'},
 'id': '0',
 'properties': OrderedDict([('position', '5')]),
 'type': 'Feature'}
{'geometry': {'coordinates': (0.0, 6.0, 0.0), 'type': 'Point'},
 'id': '1',
 'properties': OrderedDict([('position', '6')]),
 'type': 'Feature'}
{'geometry': {'coordinates': (0.0, 7.0, 0.0), 'type': 'Point'},
 'id': '0',
 'properties': OrderedDict([('position', '7')]),
 'type': 'Feature'}
{'geometry': {'coordinates': (0.0, 8.0, 0.0), 'type': 'Point'},
 'id': '1',
 'properties': OrderedDict([('position', '8')]),
 'type': 'Feature'}
{'geometry': {'coordinates': (0.0, 9.0, 0.0), 'type': 'Point'},
 'id': '2',
 'properties': OrderedDict([('position', '9')]),
 'type': 'Feature'}
{'geometry': None,
 'id': '3',
 'properties': OrderedDict([('position', '')]),
 'type': 'Feature'}
{'geometry': None,
 'id': '4',
 'properties': OrderedDict([('position', '')]),
 'type': 'Feature'}

@coveralls
Copy link

coveralls commented May 20, 2020

Coverage Status

Coverage increased (+0.04%) to 84.266% when pulling 5e67e4e on rbuffat:update_drvsupport into a9feeb5 on Toblerity:maint-1.8.

@rbuffat
Copy link
Contributor Author

rbuffat commented May 21, 2020

Actually, to compare records would be handy, and the same code could also be used in the tests of #901

I will try to find a suitable implementation.

@rbuffat
Copy link
Contributor Author

rbuffat commented Aug 17, 2020

Included in #915

@rbuffat rbuffat closed this Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants