library(ggplot2)
# Point components
pcp1 <- create_component("POINT(0 0)", 0.3)
pcp2 <- create_component("MULTIPOINT((2 2), (2 4), (2 0))", 0.5)
pcp3 <- create_component("MULTIPOINT((1 1), (3 1), (1 3), (3 3))", 0.9)
pcp4 <- create_component("MULTIPOINT((2 2), (2 4), (3 2))", 1)
pcp5 <- create_component("MULTIPOINT((0 0), (2 3))", 0.7)
pcp6 <- create_component("MULTIPOINT((0 1), (3 3))", 0.85)
pcp7 <- create_component("MULTIPOINT((1 0), (4 2))", 0.4)
# Line components
lcp1 <- create_component("LINESTRING(0 0, 1 1.5)", 0.2)
lcp2 <- create_component("LINESTRING(1 3, 1 2, 2 0.5)", 0.5)
lcp3 <- create_component("LINESTRING(2 1.2, 3 1.6, 4 4)", 0.7)
lcp4 <- create_component("LINESTRING(1 1.5, 2 1.2)", 1.0)
lcp5 <- create_component("LINESTRING(-1 1, 2 2)", 0.9)
# Polygon components
rcp1 <- create_component("POLYGON((0 0, 1 4, 2 2, 0 0))", 0.4)
rcp2 <- create_component("POLYGON((2 0.5, 4 1, 4 0, 2 0.5))", 0.8)
# Creating plateau point objects
ppoint1 <- create_pgeometry(list(pcp1, pcp2, pcp3), "PLATEAUPOINT")
ppoint2 <- create_pgeometry(list(pcp4, pcp5, pcp6, pcp7), "PLATEAUPOINT")
# Creating plateau line objects
pline1 <- create_pgeometry(list(lcp1, lcp2, lcp3), "PLATEAULINE")
pline2 <- create_pgeometry(list(lcp4, lcp5), "PLATEAULINE")
# Creating a plateau region objects
pregion <- create_pgeometry(list(rcp1, rcp2), "PLATEAUREGION")
# Defining a wrapper to combine plots side by side, for convenience
combine_plots <- function(plot1, plot2, plot3) {
# setting the same range of coordinates and removing the legend of plot1 and plot2
plot1 <- plot1 + coord_sf(xlim = c(0, 4), ylim = c(0, 4)) + theme(legend.position = "none")
plot2 <- plot2 + coord_sf(xlim = c(0, 4), ylim = c(0, 4)) + theme(legend.position = "none")
plot3 <- plot3 + coord_sf(xlim = c(0, 4), ylim = c(0, 4))
ggplot() +
annotation_custom(ggplotGrob(plot1), xmin = 0, xmax = 0.5, ymin = 0.5, ymax = 1) +
annotation_custom(ggplotGrob(plot2), xmin = 0.5, xmax = 1, ymin = 0.5, ymax = 1) +
annotation_custom(ggplotGrob(plot3), xmin = 0, xmax = 1, ymin = 0, ymax = 0.5) +
coord_cartesian(xlim = c(0, 1), ylim = c(0, 1)) +
theme_void()
}
plot_ppoint1 <- plot(ppoint1) + ggtitle("Plateau point 1")
plot_ppoint2 <- plot(ppoint2) + ggtitle("Plateau point 2")
plot_pline1 <- plot(pline1) + ggtitle("Plateau line 1")
plot_pline2 <- plot(pline2) + ggtitle("Plateau line 2")
plot_pregion <- plot(pregion) + ggtitle("Plateau region")
# Computing the intersection
ppoints_intersec <- spa_intersection(ppoint1, ppoint2)
plot_inter <- plot(ppoints_intersec) + ggtitle("Intersection")
combine_plots(plot_ppoint1, plot_ppoint2, plot_inter)
if (FALSE) {
# varying the t-norm
ppoints_intersec <- spa_intersection(ppoint1, ppoint2, itype = "prod")
plot_inter <- plot(ppoints_intersec) + ggtitle("Intersection (prod)")
combine_plots(plot_ppoint1, plot_ppoint2, plot_inter)
plines_intersec <- spa_intersection(pline1, pline2)
plot_inter <- plot(plines_intersec) + ggtitle("Intersection")
combine_plots(plot_pline1, plot_pline2, plot_inter)
pregion_pline_intersec <- spa_intersection(pline1, pregion)
plot_inter <- plot(pregion_pline_intersec) + ggtitle("Intersection")
combine_plots(plot_pline1, plot_pregion, plot_inter)
# Computing the union
ppoints_union <- spa_union(ppoint1, ppoint2)
plot_union <- plot(ppoints_union) + ggtitle("Union")
combine_plots(plot_ppoint1, plot_ppoint2, plot_union)
plines_union <- spa_union(pline1, pline2)
plot_union <- plot(plines_union) + ggtitle("Union")
combine_plots(plot_pline1, plot_pline2, plot_union)
pregion_pline_union <- spa_union(pline1, pregion)
plot_union <- plot(pregion_pline_union) + ggtitle("Union")
combine_plots(plot_pline1, plot_pregion, plot_union)
# Computing the difference
ppoints_diff <- spa_difference(ppoint1, ppoint2)
plot_diff <- plot(ppoints_diff) + ggtitle("Difference")
combine_plots(plot_ppoint1, plot_ppoint2, plot_diff)
plines_diff <- spa_difference(pline1, pline2)
plot_diff <- plot(plines_diff) + ggtitle("Difference")
combine_plots(plot_pline1, plot_pline2, plot_diff)
pregion_pline_diff <- spa_difference(pline1, pregion)
plot_diff <- plot(pregion_pline_diff) + ggtitle("Difference")
combine_plots(plot_pline1, plot_pregion, plot_diff)
}
Run the code above in your browser using DataLab