- there is no error about being unable to read the file
- an error is given because states turns out to be a Polygon and there is no Color property for Polygon: you have to change the Color to FaceColor to avoid that problem
- an error is given because geoshow() creates a patch object in a traditional (non-geographic) axes, but geoplot() is for plotting in a geographic axes. At the moment I do not know how to handle this (sorry, I don't use the Mapping toolbox much)
Plot markers on map
16 次查看(过去 30 天)
显示 更早的评论
Dear all,
I require help as I am new at this. How do I do the following?
- I have plotted the map of Malaysia and it's districts. The districts are obtained from the shapefile "polbnda_mys.shp". However, there is plenty of excess empty space surrounding the map. How do I get the red box in the figure?
- I would like to plot a marker at a lat and lon. I use geoplot for this but I am getting an error "Unable to read 'polbnda_mys.shp'. Format may not be supported, file may be corrupt, or a supporting file may have been specified." I am confused about this error as "geoshow" managed to plot the shapefile.
I have attached the figure for your reference.
Thank you very much!
% % Part 1 ========================================
figure;
worldmap('Malaysia');
geoshow("polbnda_mys.shp");
% % Part 2 ========================================
hold on;
states = readgeotable("polbnda_mys.shp");
geoplot(states,Color=[1 0 0]);
geoplot(2.6028,103.0569,'r');
1 个评论
Walter Roberson
2023-9-21
When I test in R2023b:
回答(1 个)
R
2023-11-15
编辑:R
2023-11-21
Hi Eli,
I understand that you are facing issue while plotting data from a .SHP file.
To resolve the error "Unable to read 'polbnda_mys.shp'", ensure that all the files from the downloaded .ZIP file "data.zip" are present in your working directory. The "polbnda_mys.shp" files also needs "polbnda_mys.shx" and other supporting files. You can execute the following code after you unzip all the supporting files in your current working folder:
states = readgeotable("polbnda_mys.shp");
geoplot(states,FaceColor=[1 0 0]);
hold on;
geoplot(2.6028,103.0569,"om",MarkerFaceColor="r");
hold off;
Additionally, to plot the red box, refer to the following example from the "geoplot" documentation:
Hope this helps!
3 个评论
Walter Roberson
2023-11-21
编辑:Walter Roberson
2023-11-21
%but unfortunately Raghvi's code does not solve one of the two major
%problems
sourcefile = "https://stacks.stanford.edu/file/druid:zd362bc5680/data.zip";
TD = tempdir();
unzip(sourcefile, TD)
shpfile = fullfile(TD, "polbnda_mys.shp");
% % Part 1 ========================================
figure;
worldmap('Malaysia');
geoshow(shpfile);
% % Part 2 ========================================
hold on;
states = readgeotable( shpfile );
geoplot(states,FaceColor=[1 0 0]);
hold on;
geoplot(2.6028,103.0569,"om",MarkerFaceColor="r");
hold off;
Walter Roberson
2023-11-21
That is, I identified two problems in the original code, https://www.mathworks.com/matlabcentral/answers/2024182-plot-markers-on-map#comment_2895567
- That FaceColor needed to be used instead of Color. You made this change in your code
- That geoplot() needs an axes that is incompatible with the existing axes created by geoshow(). You do not address that in your post.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geographic Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!