主要内容

isinterior

R2026b

Query geographic or planar points in polygon

Since R2022a

    Description

    inpoly = isinterior(shape,querypoint) returns a logical array whose elements are 1 (true) when the corresponding geographic or planar points in querypoint are in the polygon shape. A point is in the polygon shape if it is either inside a solid region or on one of the boundaries.

    example

    [inpoly,onboundary] = isinterior(shape,querypoint) returns an additional logical array whose elements are 1 (true) when the corresponding points are on a boundary of the polygon shape.

    Examples

    collapse all

    Read worldwide land areas into the workspace as a geospatial table. Extract the polygon shape for Australia.

    GT = readgeotable("landareas.shp");
    australia = GT(GT.Name == "Australia",:);
    shape = australia.Shape;

    Read the coordinates of world cities as a geospatial table. Extract the point shapes.

    cities = readgeotable("worldcities.shp");
    querypoint = cities.Shape;

    Create an array of cities in Australia.

    inpoly = isinterior(shape,querypoint);
    citiesAU = cities(inpoly,:);

    Compare the number of world cities to the number of cities in Australia.

    height(querypoint)
    ans = 
    318
    
    height(citiesAU)
    ans = 
    6
    

    Display Australia and the cities in Australia on a map. Zoom out by changing the geographic limits.

    figure
    geoplot(shape)
    hold on
    geoplot(citiesAU,"mo",MarkerFaceColor="m")
    geolimits([-42.2 -9.5],[104.0 162.8])

    Read hydrography data into the workspace as a geospatial table. Extract the polygon shape for a pond.

    GT = readgeotable("concord_hydro_area.shp");
    pond = GT(14,:);
    shape = pond.Shape;

    Specify the coordinates of the query points using the same projected CRS as the hydrography data.

    xq = [207768  208399  208218  208044  207879  208210  208076];
    yq = [912697  912324  912290  912453  912476  912542  912127];
    querypoint = mappointshape(xq,yq);
    querypoint.ProjectedCRS = shape.ProjectedCRS;

    Determine which points are in the pond.

    inpoly = isinterior(shape,querypoint)
    inpoly = 1×7 logical array
    
        0    0    1    0    1    0    0
    
    

    Display the pond and all points on a map. Use green for points inside the pond and magenta for points outside the pond.

    figure
    geoplot(pond)
    hold on
    geoplot(querypoint(inpoly),"*g")
    geoplot(querypoint(~inpoly),"*m")

    Zoom out by changing the geographic limits.

    geolimits([42.4568 42.4662],[-71.4113 -71.3919])

    Input Arguments

    collapse all

    Polygon shape, specified as a geopolyshape object or a mappolyshape object.

    Point shapes to query, specified as an array of geopointshape or mappointshape objects.

    • When querypoint is an array of geopointshape objects, shape must be a geopolyshape object. The 2-D CRSs stored in the GeographicCRS properties must match. The function does not require the vertical CRSs to match.

    • When querypoint is an array of mappointshape objects, shape must be a mappolyshape object. The 2-D CRSs stored in the ProjectedCRS properties must match. The function does not require the vertical CRSs to match.

    Output Arguments

    collapse all

    Indicator for points inside or on the boundary of the polygon, returned as a logical array. The size of inpoly matches the size of querypoint.

    • A logical 1 (true) indicates that the corresponding query point is inside the polygon or on the boundary.

    • A logical 0 (false) indicates that the corresponding query point is outside the polygon.

    You can identify query points of interest by using inpoly to index into querypoint.

    Points of InterestExample Code
    Query points inside or on the boundary of the polygonquerypoint(inpoly)
    Query points outside the polygonquerypoint(~inpoly)

    If a query point is a multipoint, then the isinterior function returns 1 (true) only when all points of the multipoint are inside the polygon or on the boundary.

    If a query point does not contain coordinate data, then the isinterior function returns 0 (false).

    Indicator for points on the boundary of the polygon, returned as a logical array. The size of onboundary matches the size of querypoint.

    • A logical 1 (true) indicates that the corresponding query point is on the polygon boundary.

    • A logical 0 (false) indicates that the corresponding query point is inside or outside the polygon boundary.

    You can identify query points of interest by using onboundary to index into querypoint.

    Points of InterestExample Code
    Query points on the polygon boundaryquerypoint(onboundary)
    Query points inside or outside the polygon boundaryquerypoint(~onboundary)
    Query points strictly inside the polygonal regionquerypoint(inpoly&~onboundary)

    If a query point is a multipoint, then the isinterior function returns 1 (true) only when all points of the multipoint are on the polygon boundary.

    If a query point does not contain coordinate data, then the isinterior function returns 0 (false).

    Tips

    • If your polygon shape is in planar coordinates (a mappointshape object) and your query points are in geographic coordinates, first project the points by using the projfwd function. Then, create a point shape from the projected coordinates by using the mappointshape function.

    Version History

    Introduced in R2022a