2021-04-28

For loop is only iterating the last value in the set

import datetime as dt
import pandas as pd
import pandas_datareader as pdr
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as dates
import numpy as np
#import natlparks as pnp
import geopandas as gpd
import geopy as gp
import googlemaps as gm
import shapely
import scipy
import geopy.distance
from geopy.geocoders import Nominatim
from shapely.geometry import Point
from shapely.ops import nearest_points
from scipy.spatial import cKDTree
import scipy.spatial as spatial
#import streamlit as st
#st.title("Finding NY National Parks Near You")
def close_by(pt, location):
    data = pd.read_csv('National_Register_of_Historic_Places (3).csv')
    close_locations = []
    location_latitude = float(location.latitude)
    location_longitude = float(location.longitude)
    #for index, row in data.itterrows():
    close_locations = [shapely.geometry.Point(lon, lat) for lon,lat in zip(data['Longitude'], data['Latitude'])]
    gdf = gpd.GeoDataFrame(data, geometry=close_locations, crs={"init":"EPSG:4326"})
    pts = gdf.geometry.unary_union
    ptsArray = np.array(pts)
    print(ptsArray)
    point_tree = spatial.KDTree(ptsArray)
    query = point_tree.query_ball_point([location.longitude, location.latitude], 1)
    **for i in range(len(query)):
        lst = []
        otherList=[]
        value = query[i]
        lst.append(gdf.iloc[value])**
def main():
    data = pd.read_csv('National_Register_of_Historic_Places (3).csv')
    streetNum = input("Enter your number")
    streetName = input("Enter Your Street Name")
    city = input("Enter your city")
    geolocator = Nominatim(user_agent="Final_Project_Python")
    location = geolocator.geocode(f"{streetNum} {streetName} {city} ")
    print(location.address)
    print(location.latitude, location.longitude)
    pt = Point(location.longitude, location.latitude)
    print(float(location.latitude))
    print(float(location.longitude))
    close_by(pt, location)
main()

The For loop I bolded in the close_by function currently only returns the last value of the query instead of all the records before it. Does anybody know how to make it include all the values it iterates through rather than overwriting the previous value each time?



from Recent Questions - Stack Overflow https://ift.tt/2QZDDPs
https://ift.tt/eA8V8J

No comments:

Post a Comment