I am collecting satellite weather data and plotting it on a Mercator projection Earth map. I need to determine how long it takes to cover the entire sea area of the Earth with these scan patches. I create a polyshape for each satellite scan, and then merge all of the polys into a single, overall polyshape which I compare against the "coastlines" poly, comparing the number of holes in each. When the hole numbers match, I assume that I have covered the whole Earth (land or water). Here is a depiction of my scan with a single scan polyshape:
When the scan is complete, I will have filled in the entire water area of the Earth. Any holes in the polyshape will represent continents and islands. The "coastlines" polyshape has 221 regions and 22 holes. My merged polyshape should match this.
Here is a simplified version of my code:
coast = polyshape(coastlon,coastlat);
srcfiles = dir(filepath);
filename = srcFiles(i).name;
lat = ncread(filename,'Latitude');
lon = ncread(filename,'Longitude');
k = boundary(lat(:),lon(:));
pgon = polyshape(lon(k),lat(k));
pgon_land = intersect(coast,pgon);
pgon_sea = xor(pgon,pgon_land);
pgon_merge = union(pgon_sea,pgon);
disp(strcat("patch holes = ",num2str(pgon_merge.NumHoles)));
In order to plot just the land areas, I do an intersect on the coast poly and the latest scan poly. Conversely, to keep just the water areas, I do a "xor" on the latest scan poly and the land areas. Then I do a "union" to combine that poly with the growing merge_poly.
This works, up to a point, but after several hundred merges I start to get strange lines sweeping across the merged polyshape. I suspect these are artifacts of the merge process, where lat/lon points from one poly are combined with points from the merged poly in unexpected ways.
(Note: this is a hand-drawn depiction of what I'm seeing, not the actual image)
The extraneous lines are breaking up the interior land areas into multiple regions, which skews my total hole count to upwards of 270, instead of 221.
I researched all of the polyshape functions, looking for a way to clean up the data - such as "polybuffer" and "simplify". Apparently "simplify" runs by default when you do a merge. Perhaps my "exclusive or" is part of the problem? I tried zooming in on the line endpoints, looking for a Mandelbrot-like pocket or something, but even down to a thousandth of a degree resolution I see nothing. What do you suggest? It appears I am pushing the polyshape merge process beyond the normal limit.