0

I am trying to work on a use case in my workplace which show data points that are located within Polygon Shape (eg. Hexagon, Circle, Pentagon, etc). Apologies as the data are all in my workplace, I can only explain the concept here. Currently, I am able to filter more straightforward polygons like Square (ie. SQL statement WHERE Latitude BETWEEN xx to xx AND Longitude BETWEEN xx to xx). However, I am having trouble with these types of 'weird' shapes. But I figured it should require some Python coding as well.

eg. Polygon over  - Angel island state park

Sample data:

Time                               Latitude        Longitude

18-7-23 00:00:00                   37.8651,        -122.4048         < outside state park (filter this)

18-7-23 00:00:00                   37.8627,        -122.4319         < within state park  (show this)

In this example, I should be just seeing the second data row after querying from SQL (pyodbc lib). Appreciate if anyone can help out or explain the concept on how to approach this. Thank you.

panzer
  • 11
  • 3
  • Does this answer your question? [What's the fastest way of checking if a point is inside a polygon in python](https://stackoverflow.com/questions/36399381/whats-the-fastest-way-of-checking-if-a-point-is-inside-a-polygon-in-python) – Daviid Jul 18 '23 at 14:15
  • I assume you have all the points of the polygon? – Daviid Jul 18 '23 at 14:15
  • Hi @Daviid, not exactly... my idea is to use SQL statement to filter out the relevant rows. which then I will further process this list of data rows. For polygon I'm trying to tackle 'weird' shapes like hexagon/circle/pentagon/etc. – panzer Jul 19 '23 at 12:48
  • I believe that's the wrong way to go about it, if I understood correctly you want to filter out at the SQL step, this will only make things more difficult, get all the rows, then filter out in python. – Daviid Jul 20 '23 at 07:36

0 Answers0