This example estimates the spatial density of volcanic crater locations in western Uganda using kernel density estimation. Since the study region has an irregular, non-convex boundary, the density visualization is restricted to the polygon using a compiled point-in-polygon test.
The boundary is highly irregular and non-convex, which makes simple rectangular plotting ranges inadequate. This visualization motivates the need for an explicit region membership test in the subsequent density plot
Define a test function that determines whether a given point lies inside the boundary. This is later used to restrict the density plot to the valid geographic region. The test is implemented using winding numbers and compiled for efficiency, since it will be evaluated repeatedly during plotting: