I could use some assistance with a new scripting project on iterating through two tables of lat/lon coordinates, comparing distances, and aggregating closest points. /u/MarineBiomancer Python Education

So, I’m performing an analysis to compare locations of a group of accidents to locations of hospitals to get a sum of how many accidents each hospital is closest to. I’ve been digging around in some resources all day, but I haven’t had any luck yet. I feel like I have a lot of the pieces (or at least ideas of the pieces), but I’m not sure how to put them together and could use some directed guidance.

What I think I need is:

– an import of two separate tables (accidents and hospitals)

– a way to iterate through a table and measure the distance from its features to all the features in the other table, so all the features in one table will have a distance measurement to every feature in the other table

– a way to examine what the closest hospital was for a given accident

– a way to sum the total number of times a given hospital was the closest to an accident

So far all I really have is one bit of code that performs the distance calculation, which I could incorporate into the loop doing to distance calculation between the tables, after some modifications:

def haversine_distance(origin, destination): lat1, lon1 = origin lat2, lon2 = destination radius = 6371000 dlat = math.radians(lat2-lat1) dlon = math.radians(lon2-lon1) a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1))  * math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2) c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) distance = radius * c return distance 

Source: https://courses.spatialthoughts.com/python-foundation.html#tuples

submitted by /u/MarineBiomancer
[link] [comments]

​r/learnpython So, I’m performing an analysis to compare locations of a group of accidents to locations of hospitals to get a sum of how many accidents each hospital is closest to. I’ve been digging around in some resources all day, but I haven’t had any luck yet. I feel like I have a lot of the pieces (or at least ideas of the pieces), but I’m not sure how to put them together and could use some directed guidance. What I think I need is: – an import of two separate tables (accidents and hospitals) – a way to iterate through a table and measure the distance from its features to all the features in the other table, so all the features in one table will have a distance measurement to every feature in the other table – a way to examine what the closest hospital was for a given accident – a way to sum the total number of times a given hospital was the closest to an accident So far all I really have is one bit of code that performs the distance calculation, which I could incorporate into the loop doing to distance calculation between the tables, after some modifications: def haversine_distance(origin, destination): lat1, lon1 = origin lat2, lon2 = destination radius = 6371000 dlat = math.radians(lat2-lat1) dlon = math.radians(lon2-lon1) a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2) c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) distance = radius * c return distance Source: https://courses.spatialthoughts.com/python-foundation.html#tuples submitted by /u/MarineBiomancer [link] [comments] 

So, I’m performing an analysis to compare locations of a group of accidents to locations of hospitals to get a sum of how many accidents each hospital is closest to. I’ve been digging around in some resources all day, but I haven’t had any luck yet. I feel like I have a lot of the pieces (or at least ideas of the pieces), but I’m not sure how to put them together and could use some directed guidance.

What I think I need is:

– an import of two separate tables (accidents and hospitals)

– a way to iterate through a table and measure the distance from its features to all the features in the other table, so all the features in one table will have a distance measurement to every feature in the other table

– a way to examine what the closest hospital was for a given accident

– a way to sum the total number of times a given hospital was the closest to an accident

So far all I really have is one bit of code that performs the distance calculation, which I could incorporate into the loop doing to distance calculation between the tables, after some modifications:

def haversine_distance(origin, destination): lat1, lon1 = origin lat2, lon2 = destination radius = 6371000 dlat = math.radians(lat2-lat1) dlon = math.radians(lon2-lon1) a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1))  * math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2) c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) distance = radius * c return distance 

Source: https://courses.spatialthoughts.com/python-foundation.html#tuples

submitted by /u/MarineBiomancer
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *