How can I overlay a shapefile onto a geoscatter plot?

15 views (last 30 days)
I am plotting radiocarbon data for the U.S. state of Ohio using the geoscatter() function:
geoscatter(radio.Latitude,radio.Longitude,250,'.r') % Lat/Lon coordinates are from a table of radiocarbon data
geolimits([38 42.5],[-84 -81]) % [degrees N],[degrees E] => limits axes to the Ohio region
geobasemap colorterrain
The above code works perfectly. Next, I have a shape file that I want to overlay on top of my geoscatter plot. I have already tried the following:
info = shapeinfo('filename.shp'); % extract information from shapefile
crs = info.CoordinateReferenceSystem % verifies the shapefile uses latitude and longitude coordinates
S = shaperead('filename.shp','UseGeoCoords',true); % read the shapefile using geocoordinates
% Add shapefile to geoscatter plot
hold on
geoshow(S)
hold off
However, I get several errors:
  • Error using hggroup
  • Group cannot be a child of Geographic Axes
  • Error in symbolizeMapVectors>plotMapFeature (line 139)
  • hg = hggroup('Parent', get(h,'Parent'));
  • Error in symbolizeMapVectors (line 119)
  • hg = plotMapFeature(S(k), hg, props, plotfcn);
  • Error in geostructshow (line 145)
  • h = symbolizeMapVectors(S, symspec, fcn, defaultProps, otherProps);
  • Error in geoshow (line 242)
  • h = showFcn(varargin{:});
What do I need to change in order to fix this? Or is it not possible to overlay a shapefile on a geoscatter plot?
Thank you.

Accepted Answer

millercommamatt
millercommamatt on 3 Nov 2021
Plotting shapefiles on a geographic axis isn't always the best experience. You'll note that geoshow is intended for use with a standard or map axes. But, we can still make things work.
The resulting figure becomes slow to respond to mouse interactions because there are 537 seperate geoplot objects and children to the geoaxes, but this works.
ls = shaperead('landareas.shp');
fh=figure();
ah = geoaxes(fh);
hold(ah,'on');
for ii = 1:length(ls)
geoplot(ah,ls(ii).Y,ls(ii).X)
end
  2 Comments
millercommamatt
millercommamatt on 4 Nov 2021
I'd have to see the code to comment on the error. It suggests that you have Latitude values greater than 90. Check you data to make sure it's what it should be.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by