4

I'm trying to cut and delete some lines in a shapefile with QGIS. The output of this edit is the input to the Basemap.readshapefile function in matplotlib.

My edited shapefile does not work well. It complains about this: ValueError: readshapefile can only handle a single shape type per file

After many trials and some research, I noticed using the ogrinfo tool that the problem might be these "dataless" features (I attach a screenshot with vimdiff between the raw shp file and the edited one):

enter image description here

There are some features that lack the LINESTRING data. How can I delete these features all together? Currently I'm just select the line by selection all the nodes with the vertex tool and then deleting the nodes.

4
  • How do you go about deleting features from your dataset?
    – Erik
    Dec 4, 2023 at 9:39
  • 1
    I select the features with the vertex tool and then I delete the nodes. I'm not sure what you mean...
    – Pythonist
    Dec 4, 2023 at 9:40
  • 2
    That will not delete the feature. It deletes the feature's geometry only. The feature will still exist with a null geometry. To delete a feature completely, first select it and then delete it.
    – Matt
    Dec 4, 2023 at 9:44
  • 1
    OK, dump question... how do I select a feature?
    – Pythonist
    Dec 4, 2023 at 9:45

1 Answer 1

8

Using the vertex tool to delete feature vertices will not delete the feature. It deletes the feature's geometry only. It will no longer appear on the map canvas, however, the feature will still exist with a null geometry.

To delete a feature completely, first select it and then delete it.

There are various ways to make selections, including:

The Selection Toolbar (View > Toolbars > Selection Toolbar):

enter image description here

The Select by expression tool (Processing toolbox > Vector Selection > Select by expression)
with an expression such as:

enter image description here

code = 'A' or code in ('C', 'D')

Where code is a field name and the letters represent attribute values you are interested in.

enter image description here

Here the selected features are coloured yellow.

2
  • 2
    Alternatively, if one can't come up with an easy data-driven rule by which to select features, one can select feature by clicking on the or drawing a frame around them using the left-most tool of the toolbar.
    – Erik
    Dec 4, 2023 at 10:11
  • Thanks, this was indeed the problem I was facing.
    – Pythonist
    Dec 4, 2023 at 10:27

Your Answer

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

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