I want the points that located in a certain polygon

16 次查看(过去 30 天)
Hey,
I have 92 points. Each point has latitude and longitude. On the other hand, I have a shape file consist of six different polygons. I want to know which point located in which polygon. For example, I want to have all points located in the first polygon.
filename ='Basin1_waterse_ir.shp'
S = shaperead(filename)
S =
6×1 struct array with fields:
Geometry
BoundingBox
X
Y
DEGREE1
HECTARES
AREA
PERIMETER
x0xE40xC70xE3
ACRES
Thank you all.
  4 个评论
darova
darova 2020-3-31
You have points of 1e+5 scale. What are units of them? How to rescale them to lat/long?
BN
BN 2020-4-1
Dear darova,
I searched a lot and downloaded a new shapefile with latitude and longitude scales. I uploaded it here in this comment.
After running the modified code below, using this new shapefile I have some points in the polygon but I don't know how to select them because all inon cells are zero.
filename ='subbas_degree1.shp'
S = shaperead(filename);
polygon1_y = S(1).X; % for example, I want to find all points in polygon number one
polygon1_x = S(1).Y;
polygon1_x = polygon1_x.';
polygon1_y = polygon1_y.';
lat = Points.lat;
lon = Points.lon;
[in,on] = inpolygon(lon,lat,polygon1_x,polygon1_y); % Logical Matrix
inon = in | on; % Combine ‘in’ And ‘on’
idx = find(inon(:)); % Linear Indices Of ‘inon’ Points
latcoord = lat(idx); % X-Coordinates Of ‘inon’ Points
loncoord = lon(idx); % Y-Coordinates Of ‘inon’ Points
figure(1)
plot(lon, lat, '.') % Plot All Points
hold on
plot(polygon1_y, polygon1_x, '.') % Plot Polygon
plot(latcoord, loncoord, 'gp') % Overplot ‘inon’ Points
hold off
I would like to index inside polygon points in order to choose them from Points.mat
Thank you again

请先登录,再进行评论。

采纳的回答

darova
darova 2020-4-1
You use different order of lan/lot. Change places in red squares

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by