1

I have a ton of files of orbit paths which each contain a list of 63,000 latitude and longitude coordinates which make up an orbit path like this.

The files are HDF files and contain two lists, one of 63k latitude points and one of 63k longitude points in sequential order. Here is a sample file.

To select the latitude and longitude coordinates use this code:

hdf = SD(FILEPATH, SDC.READ)
lat = hdf.select('Latitude')
lon = hdf.select('Longitude')

I need to be able to filter out these files so that I only have files whose orbit paths intersect the country Greenland.

Currently I'm doing this extremely inefficiently, my solution right now goes through each point of the path of each file and checking if that point falls within Greenland, and if it does I add it to a list of files. This can take hours to do, here's what the code essentially boils down to at the moment.

#poly is a polygon around Greenland. 
coords = [(-55, 59.5), (-55,67.5), (-60,67.5), (-60,75), (-73.25,75), (-73.25,79.2),
        (-67.5,79.2), (-67.5,80.82), (-65.34,80.82), (-65.34,81.23), (-62,81.23),
        (-62,82), (-60.25,82), (-60.25,84), (-10,84), (-10,75), (-17,75), (-17,67.5),
        (-30,67.5), (-30,59.5)]
poly = Polygon(coords)
latlon = zip(latitude, longitude)
for index, lalo in enumerate(latlon):
     if (poly.contains(Point(lalo[1], lalo[0]))):
          greenland_files.append(f)
          break

Any ideas?

iraz
  • 11
  • 2
  • 1
    what do these files look like (please give us some sample). how are they sorted (if). Also,How is `poly` (from your snippet) actually represented in your code? – Tibebes. M Oct 26 '20 at 18:48
  • 1
    Thank you @Tibebes.M I've updated the post with the info. – iraz Oct 26 '20 at 19:14
  • It almost sounds like you need something like a k-d tree. You have 3 dimensions. Longitude, Latitude, and Timestamp. You can search for ranges in the latitude and longitude, (basically a bounding box) and that should be able to narrow down the search. From there you can do line-line or polygon-line intersection to refine to only the paths that intersect. – Alex Shirley Oct 26 '20 at 19:27

1 Answers1

1

If the points of your orbit are sorted sequentially (which I'm assuming they must be), you might try some sort of search technique. For example, if all of your orbit points proceed east-to-west (or vice versa, but consistent) and if you can find a point guaranteed to be east of Greenland and guaranteed to be west of Greenland, you should be able to search between those points.

I realize that the cases get weird because any point on earth is simultaneously west and east of Greenland if you go far enough, but I also don't know how your orbit paths are structured (is the starting point the same every time? do they always proceed east-to-west or vice versa? etc).

EDIT: To quickly find the intersection between two polygons, you might use the following algorithm: https://dl.acm.org/doi/abs/10.1145/800141.804662

Jace
  • 177
  • 6
  • Thank you for the comment! I thought to try this but the orbit points do not start at the same point every time and vary over long periods. Should've mentioned that in the post, will edit it. Thank you! – iraz Oct 26 '20 at 19:08
  • This will likely be a PITA to implement, but here is a method for determining the intersection of two polygons quickly: https://dl.acm.org/doi/abs/10.1145/800141.804662 – Jace Oct 26 '20 at 19:14