# How to find points inside Singapore?

6 ビュー (過去 30 日間)
Shunan Sheng 2022 年 1 月 13 日
コメント済み: Adam Danz 2022 年 1 月 18 日
I have generated a set of geographical points with latitude and longtitude, I want to pick up the points residing inside the border of Singapore. There are similar answers in https://www.mathworks.com/matlabcentral/answers/311766-how-to-mask-data-points-outside-a-border-using-geoshow and https://www.mathworks.com/matlabcentral/answers/444653-how-can-i-remove-the-region-outside-of-the-vector-data-when-i-combine-the-vector-and-raster-data-on. However. I failde to replicate the code as it seems that shaperead does not contain information about Singapore . Where can I find the border information needed?
'Selector',{@(name) strcmp(name,'Singapore'), 'Name'}); % the original code is "Australia"
##### 2 件のコメント表示非表示 1 件の古いコメント
Shunan Sheng 2022 年 1 月 14 日
Thank you so much for the reply! Do you know places where I can find precise border for small countries like Singapore?

サインインしてコメントする。

### 採用された回答

Cris LaPierre 2022 年 1 月 13 日

You are correct, landareas does not contain a shape with the name 'Singapore'.
figure;
axesm('miller','MapLatLimit',[-1 4],'MapLonLimit',[100 108]);
geoshow(landareas)
find(strcmp({landareas.Name},'Singapore'))
ans = 1×0 empty double row vector
If you want to capture the polygon here that may represent Singapore in landareas.shp, you will have to find it manually.
figure
geoshow(landareas(372));
You can extract the associated lat and lon values, and use inpolygon to search for points that are within the shape.
singLat = landareas(372).Lat;
singLon = landareas(372).Lon;
##### 4 件のコメント表示非表示 3 件の古いコメント
Sean de Wolski 2022 年 1 月 14 日
inpolygon will not work unless you project the coordinates from lat/lon to a cartesian coordinate system. In R2021b, there's a new class geopolyshape that has an isinterior method that makes this much easier than it used to be.

サインインしてコメントする。

### その他の回答 (1 件)

Adam Danz 2022 年 1 月 14 日

> Do you know places where I can find precise border for small countries like Singapore?
Search the internet for shp files containing information about Singapore. I briefly searched data.gov.sg and found 294 shp files on Singapore from census data, municiple planning areas, and lots of different maps.
Here's a demo using the 2010 Singapore Region Census.
3. Run the code below to see the map produced below. Note, these data break Singapore into Central, West, North, North-East, and East regions but is also includes at least some of the island borders.
First let's look at the shape info
info = shapeinfo('Region_Census2010.shp')
info =
struct with fields:
Filename: [3×108 char]
ShapeType: 'Polygon'
BoundingBox: [2×2 double]
NumFeatures: 5
Attributes: [8×1 struct]
CoordinateReferenceSystem: [1×1 projcrs]
info.CoordinateReferenceSystem
ans =
projcrs with properties:
Name: "SVY21"
GeographicCRS: [1×1 geocrs]
ProjectionMethod: "Transverse Mercator"
LengthUnit: "meter"
ProjectionParameters: [1×1 map.crs.ProjectionParameters]
The ProjectionMethod is "Transverse Mercator" which is "tranmerc" in Matlab if you choose to use map axes (eg, axesm('tranmerc')).
The coordinate reference system is not a geocrs object so this dataset does not use geographical coordinates (lat/lon) as described here. If you need Lat/Lon you'll either need to find a different sph file or perhaps these values can be converted.
Plot singapore
% Note that S is a 5x1 structure: 1 for each region of singapore
% Plot regions
axes()
hold on
for i = 1:numel(S)
plot(S(i).Lon, S(i).Lat)
end
axis equal
##### 2 件のコメント表示非表示 1 件の古いコメント
Adam Danz 2022 年 1 月 18 日
Thanks for the tips, @Sean de Wolski

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by