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 Answer 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– Mark McGirr2019年09月17日 16:07:59 +00:00Commented Sep 17, 2019 at 16:07
-
1Hey 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– Marcelo Villa2019年09月17日 16:17:31 +00:00Commented Sep 17, 2019 at 16:17