0

I am working with a pandas data frame where I have 4 columns of lats and langs. You can call these as pickup and drop off points. I have identify lat and lang of a central location and figured the radius (1000FT)of the circle. I want to select all the pickup and drop off points within this circle. Potentially create a column in the data frame with a flag.

(Pdb) x.dtypes
Pickup_longitude     float64
Pickup_latitude      float64
Dropoff_longitude    float64
Dropoff_latitude     float64
dtype: object

Pickup_longitude,Pickup_latitude,Dropoff_longitude,Dropoff_latitude
-73.97948455810547,40.68495559692383,-73.97943115234375,40.685020446777344
-74.01079559326173,40.91221618652344,-74.01078033447266,40.91221237182617
-73.92140960693358,40.76670837402344,-73.91441345214845,40.764686584472656
-73.92138671875,40.76667785644531,-73.93142700195312,40.771583557128906
-73.95548248291014,40.71404647827149,-73.94441223144531,40.71472930908203
-73.94529724121094,40.80818557739258,-73.93766784667969,40.821197509765625
-73.89087677001955,40.7464256286621,-73.87692260742188,40.75630569458008
-73.94670104980467,40.79732131958008,-73.9376449584961,40.80451583862305
-73.96315002441406,40.69382858276367,-73.956787109375,40.680530548095696
-73.89682006835938,40.74612808227539,-73.88862609863281,40.752723693847656
-73.82991790771484,40.713768005371094,-73.83494567871094,40.70729064941406
-73.9055404663086,40.77252578735352,-73.8953628540039,40.76896286010742
-73.941650390625,40.81829452514648,-73.950927734375,40.82603073120117
-73.93252563476562,40.85680389404297,-73.93136596679686,40.856117248535156
-73.95282745361328,40.808353424072266,-73.94914245605469,40.80290985107422
-73.904052734375,40.87870788574219,-73.89696502685547,40.90113067626953
-74.02134704589844,40.647010803222656,-74.00405883789062,40.65459442138672
-73.95098876953125,40.68049621582031,-73.9539566040039,40.69042205810547
-73.84967041015625,40.72400665283203,-73.83512878417969,40.70719909667969
-73.9466781616211,40.80628967285156,-73.93624877929686,40.79925155639648
-73.98682403564453,40.70245742797852,-73.97278594970702,40.69290161132813
-73.91205596923827,40.7754020690918,-73.89364624023438,40.76850509643555
-73.9617462158203,40.71377944946289,-73.98593139648438,40.71804809570313
-73.94091033935547,40.69868087768555,-73.94107818603516,40.6828498840332
-73.84423828125,40.72149658203125,-73.8086929321289,40.73440170288085
-73.89108276367188,40.74691009521485,-73.87848663330078,40.7494010925293
-73.84487915039062,40.75502395629883,-73.87222290039062,40.77399063110352
-73.87079620361328,40.73346328735352,-73.87014770507811,40.73357391357422
-73.94847869873048,40.81386184692383,-73.94107055664062,40.81884002685547

** subset of the data

I found following question in stackoverflow but not really sure if thats the correct approach. Haversine Formula in Python (Bearing and Distance between two GPS points)

Update: So far solution

import math

    def getPoints(lon, lat):
        radius = 1800 # in feet (not sure if this is the right approach)
        N = 360 

        # generate points
        circlePoints = []
        for k in range(N):
            angle = math.pi*2*k/N
add-semi-colons
  • 18,094
  • 55
  • 145
  • 232
  • Checked [this](https://stackoverflow.com/questions/53182179/convert-lat-long-to-xy/53182479#53182479)? – Cheche Nov 20 '18 at 22:07
  • Totally dependent on your problem. You could have an infinite number of coords in range; do you have any way of pruning down the options before you run the test? – roganjosh Nov 20 '18 at 22:08
  • @roganjosh May be I am missing something How can there be infinite. We use the Central point and from that point we define radius and then select all the points that are in above columns that are within the distance. – add-semi-colons Nov 20 '18 at 22:53
  • 1
    I think OP wants to select, form a set of already determined lat,long pairs, those that are within a certain distance of another lat,long point. It boils down to a bunch of pairwise distance queries, if you don't use a fancier GIS index data structure. – interfect Nov 20 '18 at 22:59
  • My point was that lat and long are continuous (you may limit to a certain number of decimal places) but without some kind of geofencing you can quickly become swamped by the number of pairs to test. – roganjosh Nov 21 '18 at 06:36

1 Answers1

1

How important is accuracy, especially near the poles of Earth?

The easy thing to do would be to work out the number of feet per degree of latitude and longitude at your central point. Then for each point, you calculate the latitude and longitude differences from your central point in degrees, an convert them to feet using the conversion factor that is correct at the central point. Then you compute the distance in feet as sqrt(latFeet^2 + longFeet^2).

The latitude/foot conversion factor will be constant everywhere (1 Earth circumference / 360 degrees of latitude), but the longitude/foot conversion factor will change as your latitude changes. If you draw a diagram and do some trigonometry, you can see that the distance around the (assumed spherical) Earth at a given latitude is 2 * Pi * Earth Radius * sin(90 degrees - abs(latitude)), and dividing that by 360 degrees of latitude gives you your distance per degree.

The approximation that 1 degree of latitude or longitude is the same distance in feet over the area you are working in breaks down at the poles, but if you don't have to operate near the poles, and if you don't care about the oblateness of the Earth, it should hold relatively well over distances of 1000 feet.

interfect
  • 2,665
  • 1
  • 20
  • 35