0

The documentation at https://shapely.readthedocs.io/en/latest/reference/shapely.get_type_id.html lists possible return values of get_type_id() function, e.g. MULTIPOINT is 4. Is MULTIPOINT identifier or something similar available, so I don't have to write cryptic code like:

if get_type_id(geometry) == 4:

in order to test if geometry is a MultiPoint?

2 Answers 2

4

You can use .geom_type, to get the name in plain text:

from shapely.geometry import MultiPoint, Point

mp = MultiPoint([(0,0), (1,1)])
pnt = Point((2,2))

#What methods are available for a multipoint object
for m in dir(mp):
    if "type" in m.lower(): #If "type" is in the method name
        print(m)
# geom_type
# geometryType
# type

#print(mp.geom_type)
#'MultiPoint'

for geom in [mp, pnt]:
    if geom.geom_type.lower()=="multipoint":
        print(geom)
#MULTIPOINT ((0 0), (1 1))
3

You can use the standard python way to determine the class type.

Something like this:

import shapely

if isinstance(geometry, shapely.MultiPoint):

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.