# How to find points inside Singapore?

6 views (last 30 days)
Shunan Sheng on 13 Jan 2022
Commented: Adam Danz on 18 Jan 2022
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 CommentsShowHide 1 older comment
Shunan Sheng on 14 Jan 2022
Thank you so much for the reply! Do you know places where I can find precise border for small countries like Singapore?

Cris LaPierre on 13 Jan 2022
Edited: Cris LaPierre on 13 Jan 2022
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;
Sean de Wolski on 14 Jan 2022
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.

Adam Danz on 14 Jan 2022
Edited: Adam Danz on 14 Jan 2022
> 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 CommentsShowHide 1 older comment
Adam Danz on 18 Jan 2022
Thanks for the tips, @Sean de Wolski