2

GPKG file has multiple featureclasses in it. I create a layer to a specific featureclass using QgsVectorLayer but it always points to the first FC in the gpkg file.

This is a stand alone python script, not the console under the GUI.

output_gpkg = r'W:\srm\wml\Workarea\mamcgirr\Q_universal_overlap_tool\work\qscript_outputs\one_status_common_datasets_debug_version_dqu_shape_2.gpkg |layername = Legal_OGMA'
fc_input_layer = QgsVectorLayer(output_gpkg, 'test', 'ogr')
if not fc_input_layer.isValid():
 print("layer invalid.")
else:
 print("layer valid.")
for field in fc_input_layer.fields():
 print(field.name(), field.typeName())
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 16, 2019 at 4:01
0

1 Answer 1

2

Remove space in your output_gpkg.You can try typing another layer name and you will see how the first one loads as well. for example :

output_gpkg = r'W:\srm\wml\Workarea\mamcgirr\Q_universal_overlap_tool\work\qscript_outputs\one_status_common_datasets_debug_version_dqu_shape_2.gpkg |layername = INVENT'

to load the correct layer you must remove all spaces leaving it so:

output_gpkg = r'W:\srm\wml\Workarea\mamcgirr\Q_universal_overlap_tool\work\qscript_outputs\one_status_common_datasets_debug_version_dqu_shape_2.gpkg|layername=Legal_OGMA'
answered Sep 16, 2019 at 8:54
2
  • Excellent. Removing the spaces fixed it. Thanks very much. It was driving me crazy. Commented Sep 17, 2019 at 16:07
  • 1
    Hey Mark, welcome to GIS SE. This does not really answer the question. Instead, you should upvote the question and accept it if it solved your issue. Commented Sep 17, 2019 at 16:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.