这将给出从哪里开始的粗略想法:
import pandas as pd
import numpy as np
from shapely.geometry import Point
from shapely.geometry.polygon import LinearRing, Polygon
import tkinter as tk
from functools import partial
import matplotlib.pyplot as plt
#reading data
data = pd.read_csv('address.csv')
df = pd.DataFrame(data)
#initialization
lat = np.asarray(df['lat'])
long = np.asarray(df['long'])
poly_cords = [(2, 9), (2, 6), (5, 5), (6, 9)]
address = df['address']
#visualization
poly = Polygon(poly_cords)
x,y = poly.exterior.xy
plt.scatter(lat,long)
plt.plot(x, y, color='#6699cc', alpha=0.7,
linewidth=3, solid_capstyle='round', zorder=2)
plt.show()
#function to produce proximity results
def call_result(label_result, n1, n2, poly_cords):
lat = (n1.get())
long = (n2.get())
lat = float(lat)
long = float(long)
point = Point(lat,long)
polygon = Polygon(poly_cords)
if polygon.contains(point) == False:
x = "We do not serve here"
else:
x = "we serve here"
label_result.config(text="Result is %s" % x)
return
#GUI
root = tk.Tk()
root.geometry('400x200+100+200')
root.title('Address Proximity')
number1 = tk.StringVar()
number2 = tk.StringVar()
labelTitle = tk.Label(root, text="Address Proximity").grid(row=0, column=2)
labelNum1 = tk.Label(root, text="Enter a lat").grid(row=1, column=0)
labelNum2 = tk.Label(root, text="Enter long").grid(row=2, column=0)
labelResult = tk.Label(root)
labelResult.grid(row=7, column=2)
entryNum1 = tk.Entry(root, textvariable=number1).grid(row=1, column=2)
entryNum2 = tk.Entry(root, textvariable=number2).grid(row=2, column=2)
call_result = partial(call_result, labelResult, number1, number2, polygon_cordinates)
buttonCal = tk.Button(root, text="Calculate", command=call_result).grid(row=3, column=0)
root.mainloop()
根据您的问题生成以纬度和经度为输入的 GUI。测试 (lat,long) 是否存在于多边形内。如果存在,它将显示“我们在这里服务”,否则它将显示“我们不在这里服务”。您可以根据需要更改多边形的坐标。
多边形看起来像: