1

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())
1

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'
  • Excellent. Removing the spaces fixed it. Thanks very much. It was driving me crazy. – Mark McGirr Sep 17 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. – Marcelo Villa Sep 17 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.