I want the points that located in a certain polygon

14 visualizaciones (últimos 30 días)
BN
BN el 30 de Mzo. de 2020
Comentada: BN el 4 de Abr. de 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 comentarios
darova
darova el 31 de Mzo. de 2020
You have points of 1e+5 scale. What are units of them? How to rescale them to lat/long?
BN
BN el 1 de Abr. de 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

Iniciar sesión para comentar.

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by