Skip to content

Instantly share code, notes, and snippets.

@ceholden
Last active March 19, 2019 22:40
Show Gist options
  • Save ceholden/84b9cd7734d5c87c8e1c7345ed332a9b to your computer and use it in GitHub Desktop.
Save ceholden/84b9cd7734d5c87c8e1c7345ed332a9b to your computer and use it in GitHub Desktop.
QGIS Python API issue test Gist
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/bin/bash
SCRIPT=./test_qgis.py
echo "Turning off error checking ('set +e')"
set +e
echo "Trying to run '$SCRIPT'"
python $SCRIPT
echo "Hey we made it despite segfault..."
echo "------------------------------"
echo "Turning on error checking ('set -e')"
set -e
echo "Trying to run '$SCRIPT' -- see you on other side?"
python $SCRIPT
echo "You won't see this..."
#!/usr/bin/env python
import os, sys
HERE = os.path.dirname(os.path.abspath(__file__))
f = os.path.join(HERE, 'ne_110m_land.geojson')
def test():
from qgis.core import QgsApplication, QgsProcessingFeedback, QgsVectorLayer
app = QgsApplication([], False)
app.initQgis()
vl = QgsVectorLayer(f)
valid = vl.isValid()
print('Valid?', valid)
if not valid:
print('Could not even validate the vector file... '
'you have bigger problems')
sys.exit(1)
else:
print('Feature count?', vl.featureCount())
app.exitQgis()
print('Ran `app.exitQgis()`')
app.exit()
print('Ran `app.exit()`')
if __name__ == '__main__':
test()
print('Will be done if it does not segfault')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment