I want the points that located in a certain polygon

14 vues (au cours des 30 derniers jours)
BN
BN le 30 Mar 2020
Commenté : BN le 4 Avr 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 commentaires
darova
darova le 31 Mar 2020
You have points of 1e+5 scale. What are units of them? How to rescale them to lat/long?
BN
BN le 1 Avr 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

Connectez-vous pour commenter.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Elementary Polygons dans Help Center et File Exchange

Tags

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by