I accomplished it using the following command:
ogrinfo -al myshapefile.shp | grep POLYGON | sed 's/$/,/' | tr -d -c "," | wc
This begins by printing the shapefile contents to stdout, including all of the geometry. (
ogrinfo -al myshapefile.shp)
Next, we extract only the lines containing geometry (
This results in a list of points of the form, for a multipolygon, of:
(((34 43,22 10,70 5),(23 43,54 1,89 2)),((23 43,43 2)))
Notice that each point is followed by a comma, except the last one.
Therefore, we add a comma to the end of the line. (
Finally, we eliminate every character that is not a comma (
tr -d -c ",") and count the commas (
wc) which gives the number of points.