1

Following on from GDAL/OGR Geometry Type Python, what is the best way to determine if a vector geometry is any kind of line or point or whatever?

For example, I'm using this technique at the moment,

# check geom type is supported
vector_lyr = vector_ds.GetLayer()
ftr = vector_lyr.GetNextFeature()
geom = ftr.GetGeometryRef()
geom_type = geom.GetGeometryType()

if geom_type in (ogr.wkbLineString, ogr.wkbMultiLineString):
    do_line_stuff()
elif geom_type in (ogr.wkbPoint, ogr.wkbMultiPoint):
    do_point_stuff()
else:
    raise NotImplementedError(
        'Geometry Type {} is not supported'.format(geom.GetGeometryName()))

but it feels like it doesn't cover all geometry types. What if it's a curve, or a ring, or a geometry collection? Should I just list all the possible types in the if statements above, or is there a better way? There doesn't seem to be a catch-all is_line() method.

2

1 Answer 1

1

Looks like the answer is no - you have to write your own.

Your Answer

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

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