How can I overlay a shapefile onto a geoscatter plot?

조회 수: 12 (최근 30일)
Austin M. Weber
Austin M. Weber 2021년 11월 2일
댓글: millercommamatt 2021년 11월 4일
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.

채택된 답변

millercommamatt
millercommamatt 2021년 11월 3일
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
Austin M. Weber
Austin M. Weber 2021년 11월 4일
Thank you for the reply. Unfortunately, I still receive an error:
"Error using geoplot (line 85). Expected lat to be an array with all of the values <= 90."
millercommamatt
millercommamatt 2021년 11월 4일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by