0

I work at a pizza place and I thought it would be fun to create code to check if a location is within our delivery zone, instead of checking the giant ugly map that we have. I've already created code to convert a street address to coords, but how can I do the rest? Our delivery zone has tons of zigzags so I can't use a basic shape.

Delivery Zone for refs:

map with a polygon overlayed

wjandrea
  • 28,235
  • 9
  • 60
  • 81
pxrplmxxn
  • 1
  • 2
  • If you can come up with a list of the street coordinates of all the vertices of your polygon, then your conversion function can convert those to coordinates Once you have coordinates, the rest is easy (see the link above). – Tim Roberts Aug 11 '21 at 19:07
  • 1
    This question might be better suited for [gis.SE]. – das-g Aug 11 '21 at 19:29

2 Answers2

1

Use https://agromonitoring.com/create-polygon?lat=39.2323&lon=-121.311&zoom=7&op=truecolor&from=s2 to define a geofence which is basically a set of lat/long coordinates that represent the vertices of your polygon. Store these vertices as a list of tuples, let's call it serviceAreaCoordinates.

import picket

fence = picket.Fence()
# serviceAreaCoordinates is a list of tuples containing lat, long
for coordinate in serviceAreaCoordinates:
    fence.add_point(tuple(coordinate))

answer = fence.check_point(deliveryLocationCoordinate)
Martin
  • 1,095
  • 9
  • 14
0

If I look on your image my first impression is that your red contour line, that defines the border of your delivery area, could be very easy extracted as a contour with opencv. Then you will get as result of this a list with coordinates of the red line. If a customer calls, then you already calculate his coordinates. Then you can test your address coordinates against the contour coordinates.

Step1: Take a look at how to get contours (really not difficult with opencv for python): https://learnopencv.com/contour-detection-using-opencv-python-c/

Step2: Take a look at this post to check if a point is inside a contour: How to check if point is placed inside contour?

fuyi
  • 2,573
  • 4
  • 23
  • 46
ScienceLover
  • 43
  • 1
  • 6