MATLAB Answers

I want the points that located in a certain polygon

조회 수: 13(최근 30일)
Behzad Navidi
Behzad Navidi 30 Mar 2020
댓글: Behzad Navidi 4 Apr 2020
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

표시 이전 댓글 수: 1
Behzad Navidi
Behzad Navidi 30 Mar 2020
Dear darova,
I used inpolygon, here is my code, but I don't know what my mistake is; because I can't index any point in polygon 1 for example. Do you know what I do wrong?
clear; clc;
filename ='Basin1_waterse_ir.shp'
S = shaperead(filename);
polygon1_x = S(1).X; % for example, I want to find all points in polygon number one
polygon1_y = S(1).Y;
polygon1_x = polygon1_x.';
polygon1_y = polygon1_y.';
lat = Points.lat;
lon = Points.lon;
[in,on] = inpolygon(lat,lon, 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(lat, lon, 'bp') % Plot All Points
hold on
plot(polygon1_x, polygon1_y, '-r') % Plot Polygon
plot(latcoord, loncoord, 'gp') % Overplot ‘inon’ Points
hold off
Thank you
darova
darova 31 Mar 2020
You have points of 1e+5 scale. What are units of them? How to rescale them to lat/long?
Behzad Navidi
Behzad Navidi 1 Apr 2020
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

로그인 to comment.

채택된 답변

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

  댓글 수: 1

Behzad Navidi
Behzad Navidi 4 Apr 2020
Thank you so much

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그

제품


릴리스

R2018b

Translated by