- polybool: https://www.mathworks.com/help/map/ref/polybool.html
- polyshape: https://www.mathworks.com/help/matlab/ref/polyshape.html
- geoshape: https://www.mathworks.com/help/map/ref/geoshape.html
how to do union of geopolyshape?
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I made several geopolyshapes in geoplot. but I want to merge every geopolyshape to one geopolyshape,
I've used union of plot, but it didn't work for geoplot
This is my code for plotting the first image.
for i = 1:length(dep_xl)-1
shape1 = geopolyshape([dep_lat(i,1),dep_lat(i,2),dep_lat(i,3),dep_lat(i,4)],[dep_lon(i,1),dep_lon(i,2),dep_lon(i,3),dep_lon(i,4)]);
shape2 = geopolyshape([dep_lat(i+1,1), dep_lat(i+1,2), dep_lat(i+1,3) ,dep_lat(i+1,4)],[dep_lon(i+1,1),dep_lon(i+1,2), dep_lon(i+1,3) ,dep_lon(i+1,4)]);
geoplot(shape1)
hold on
geoplot(shape2)
end
and this is what i tried.
for i = 1:length(dep_xl)-1
shape1 = geopolyshape([dep_lat(i,1),dep_lat(i,2),dep_lat(i,3),dep_lat(i,4)],[dep_lon(i,1),dep_lon(i,2),dep_lon(i,3),dep_lon(i,4)]);
shape2 = geopolyshape([dep_lat(i+1,1), dep_lat(i+1,2), dep_lat(i+1,3) ,dep_lat(i+1,4)],[dep_lon(i+1,1),dep_lon(i+1,2), dep_lon(i+1,3) ,dep_lon(i+1,4)]);
polyout = union(shape1,shap2)
geoplot(polyout)
hold on
end
Thanks!
0 Commenti
Risposte (1)
Jaynik
il 6 Ott 2023
Hi Sierra,
According to my understanding you want to find the union of shapes of type "geopolyshape". Currently, we cannot find the union for "geopolyshape" type directly. Instead of using "geopolyshape", you can try using the "geoshape" type with the "polybool" function for union. Following is a sample code to perform the union of two "geoshape" type variables:
geoShape1 = geoshape([dep_lat(i,1),dep_lat(i,2),dep_lat(i,3),dep_lat(i,4)],[dep_lon(i,1),dep_lon(i,2),dep_lon(i,3),dep_lon(i,4)]);
geoShape2 = geoshape([dep_lat(i+1,1), dep_lat(i+1,2), dep_lat(i+1,3) ,dep_lat(i+1,4)],[dep_lon(i+1,1),dep_lon(i+1,2), dep_lon(i+1,3) ,dep_lon(i+1,4)]);
[lat, lon] = polybool('union', geoShape1.Latitude, geoShape1.Longitude, geoShape2.Latitude, geoShape2.Longitude);
% Convert the resulting latitude and longitude arrays back to geopolyshape object
polyout = geopolyshape(lat, lon);
geoplot(polyout);
You can also use "polyshape" instead of "geoshape" to directly use the "union" function like this:
geoShape1 = polyshape([dep_lat(i,1),dep_lat(i,2),dep_lat(i,3),dep_lat(i,4)],[dep_lon(i,1),dep_lon(i,2),dep_lon(i,3),dep_lon(i,4)]);
geoShape2 = polyshape([dep_lat(i+1,1), dep_lat(i+1,2), dep_lat(i+1,3) ,dep_lat(i+1,4)],[dep_lon(i+1,1),dep_lon(i+1,2), dep_lon(i+1,3) ,dep_lon(i+1,4)]);
ans = union(geoShape1, geoShape2);
geopoly = geopolyshape(ans.Vertices(:, 1), ans.Vertices(:, 2));
geoplot(geopoly);
You can read more about these functions here:
Hope this helps!
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!