isinterior
Description
returns a logical array whose elements are inpoly
= isinterior(shape
,querypoint
)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.
[
returns an additional logical array whose elements are inpoly
,onboundary
] = isinterior(shape
,querypoint
)1
(true
) when the corresponding points are on a boundary of the polygon
shape
.
Examples
Query Points in Polygon Using Geographic Coordinates
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")
Query Points in Polygon Using Planar Coordinates
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
shape
— Polygon shape
geopolyshape
object | mappolyshape
object
Polygon shape, specified as a geopolyshape
object or a mappolyshape
object.
When you specify
shape
as ageopolyshape
object, then you must specifyquerypoint
as an array ofgeopointshape
objects. TheGeographicCRS
properties of thegeopolyshape
andgeopointshape
objects must match.When you specify
shape
as amappolyshape
object, then you must specifyquerypoint
as an array ofmappointshape
objects. TheProjectedCRS
properties of themappolyshape
andmappointshape
objects must match.
querypoint
— Point shapes to query
array of geopointshape
objects | array of mappointshape
objects
Point shapes to query, specified as an array of geopointshape
or mappointshape
objects.
When you specify
querypoint
as an array ofgeopointshape
objects, then you must specifyshape
as ageopolyshape
object. TheGeographicCRS
properties of thegeopointshape
andgeopolyshape
objects must match.When you specify
querypoint
as an array ofmappointshape
objects, then you must specifyshape
as amappolyshape
object. TheProjectedCRS
properties of themappointshape
andmappolyshape
objects must match.
Output Arguments
inpoly
— Indicator for points inside or on boundary of polygon
logical array
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 Interest | Example Code |
---|---|
Query points inside or on the boundary of the polygon | querypoint(inpoly) |
Query points outside the polygon | querypoint(~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
).
onboundary
— Indicator for points on boundary of polygon
logical array
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 Interest | Example Code |
---|---|
Query points on the polygon boundary | querypoint(onboundary) |
Query points inside or outside the polygon boundary | querypoint(~onboundary) |
Query points strictly inside the polygonal region | querypoint(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 theprojfwd
function. Then, create a point shape from the projected coordinates by using themappointshape
function.
Version History
Introduced in R2022a
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)