0

I built a grid that includes the US map. The grid consists of latitudes and longitudes that represent small rectangles inside the US map. A small rectangle consists of many latitudes and longitudes. From a data set that contains the population, I could reside each part of data in its place on the US grid based on their latitude and longitude. enter image description here

My goal is to let the user to enter a queryBorders (inside the gird) to get the accurate population. The problem is some points' (or population)latitudes and longitudes live in the border of two neighbors, which cause these points to get counted more than one time. This gives inaccurate results.

In the illustration above, how do I get the accurate result (excluding the repeated points) for the queryBorders (a,b,c,d)?

(getting help from "How to scale down a range of numbers with a known min and max value" to get space for each block!)

Thanks in advance.

Infosunny
  • 459
  • 4
  • 17
bakursait
  • 49
  • 1
  • 8
  • Not sure how things are stored or programmed (no code). But can't you (temporary) store the queried data in a Collection so you can check if it has been counted already? – n247s Dec 02 '21 at 20:05
  • 1
    This is solved in graphics algorithms by considering the left and bottom boundaries (say) to be part of the rectangle, but not the right and top. So each boundary segment belongs to exactly one rectangle: the one to the right or above it. A point is in rect with low left corner (a,b) and upper right (c,d) if a <= x < c and b <= y < d. – Gene Dec 03 '21 at 02:48
  • @Gene, Thanks for explaining. But what if a point lies in the northmost or eastmost borders. How could we count them if we discard these borders from being part of the small block? And no other rectangles after that point!. – bakursait Dec 03 '21 at 03:42
  • 1
    If you require that a query of a rectangle count points on all borders, then you you'll need to partition the domain into interior rectangles plus border edge line segments. Then when you search, determine all the rectangles and edge segments that lie in the query rectangle to find all contained points. In your example you'd search 4 rectangles and 12 edge segments. The key idea is that the regions you partition the plane into must be disjoint. – Gene Dec 04 '21 at 03:16

0 Answers0