I want the points that located in a certain polygon

조회 수: 15 (최근 30일)
BN
BN 2020년 3월 30일
댓글: BN 2020년 4월 4일
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