Main Content

isShapeMultipart

Determine if line or polygon has multiple parts

    Description

    tf = isShapeMultipart(x,y) returns 1 (true) when the specified line or polygon has multiple parts that are separated by NaN values. A line with multiple parts has multiple line segments. A polygon with multiple parts has inner rings or nonintersecting regions. If the specified line or polygon consists of a single part, the function returns a logical 0 (false).

    example

    Examples

    collapse all

    Specify the latitude and longitude coordinates of a line. Verify that the line does not contain multiple parts.

    lat1 = [65 62 53 66];
    lon1 = [4 59 121 98];
    tf1 = isShapeMultipart(lat1,lon1) 
    tf1 = logical
       0
    
    

    Specify the latitude and longitude coordinates of a line with multiple parts. Separate the parts using NaN values. Verify that the line contains multiple parts.

    lat2 = [55 34 18 NaN 14 19 42 26];
    lon2 = [78 56 63 NaN 83 106 104 126];
    tf2 = isShapeMultipart(lat2,lon2)
    tf2 = logical
       1
    
    

    Read a shapefile containing hydrographic data into the workspace as a structure array. The shapefile represents the data using polygons in planar coordinates.

    hydro = shaperead("concord_hydro_area.shp");

    Extract a polygon that represents a pond.

    pond = hydro(14);

    Extract the xy-coordinates from the polygon. Then, determine if the polygon has multiple parts.

    x = pond.X;
    y = pond.Y;
    tf = isShapeMultipart(pond.X,pond.Y)
    tf = logical
       1
    
    

    The result indicates that the polygon has multiple parts. Verify the result by displaying the polygon on a map. Note that the polygon has multiple holes.

    mapshow(pond)

    Figure contains an axes object. The axes object contains an object of type patch.

    Input Arguments

    collapse all

    First coordinate, specified as a numeric vector. This argument typically specifies x-coordinates or latitude coordinates.

    The sizes of x and y must match. The NaN values in x must correspond to the NaN values in y.

    Second coordinate, specified as a numeric vector. This argument typically specifies y-coordinates or longitude coordinates.

    The sizes of x and y must match. The NaN values in x must correspond to the NaN values in y.

    Output Arguments

    collapse all

    Indicator for a shape with multiple parts, returned as one of these values.

    • A 1 of data type logical indicates that the line or polygon has multiple parts.

    • A 0 of data type logical indicates that the line or polygon does not have multiple parts.

    Version History

    Introduced in R2006a