SpaceGroupUCL / depthmapX

depthmapX is a multi-platform Spatial Network Analysis Software
197 stars 52 forks source link

Fix point-in-polygon problems #368

Closed pklampros closed 4 years ago

pklampros commented 4 years ago

Fixes issues when testing points in polygons.

From my understanding the algorithm used for point-in-polygon testing is a convoluted Ray-casting algorithm whereas we start from the point of interest and move in a direction to hit the sides of the polygon. If we find even sides the point is outside, odd sides within, hence the "counter % 2 != 0" checks. The algorithm is convoluted because the ShapeMap::testPointInPoly function first checks if the point is on the border and then travels left, right, up or down depending on the side and down if the point is found within the polygon. The complexity is also dut to an underlying grid for each shapemap which helps detect shapes and identify whether the point is sitting roughly within the polygon, on its border, left, right, top or bottom, but is only accurate to each cell (the size of which has been defined arbitrarily).

The two fixes provided are:

  1. Make sure the point is not treated as within if it's touching the polygon border
  2. Make sure that when the point is roughly within the polygon, then the algorithm actually checks the cells below for the shape.