Main Content

isinterior

Query geographic or planar points in polygon

    Description

    example

    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.

    [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.

    figure
    geoplot(shape)
    hold on
    geoplot(citiesAU,"mo",MarkerFaceColor="m")

    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")

    Input Arguments

    collapse all

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

    • When you specify shape as a geopolyshape object, then you must specify querypoint as an array of geopointshape objects. The GeographicCRS properties of the geopolyshape and geopointshape objects must match.

    • When you specify shape as a mappolyshape object, then you must specify querypoint as an array of mappointshape objects. The ProjectedCRS properties of the mappolyshape and mappointshape objects must match.

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

    • When you specify querypoint as an array of geopointshape objects, then you must specify shape as a geopolyshape object. The GeographicCRS properties of the geopointshape and geopolyshape objects must match.

    • When you specify querypoint as an array of mappointshape objects, then you must specify shape as a mappolyshape object. The ProjectedCRS properties of the mappointshape and mappolyshape objects must 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

    See Also

    Functions