initial commit
This commit is contained in:
commit
84f5b867db
4
data.csv
Normal file
4
data.csv
Normal file
@ -0,0 +1,4 @@
|
||||
Job Number,Borough Name,Count Permits,First Permit Date,Current Date,Age,Permit Expiration Date,Sidewalk Shed/Linear Feet,Construction Material,Current Job Status,BIN Number,Community Board,Latitude Point,Longitude Point,House Number,Street Name,Borough Digit,Block,Lot,Applicant Business Name,ProCert,Source,activity,Commercial
|
||||
B00834636-I1,BROOKLYN,,2023-02-28,2023-04-01,31,2024-01-25,30.0,,Permit Entire,3058797,302,40.68897,-73.97565,23,SOUTH ELLIOTT PLACE,3,2099,29,MOHAMMAD AHEAD PE,1,DOB NOW,Construction or Maintenance,Other Zoning Districts
|
||||
B00538999-I1,BROOKLYN,,2021-07-20,2023-04-01,619,2023-05-05,29.0,,Permit Entire,3058601,302,40.68941,-73.97881,96,DEKALB AVENUE,3,2095,25,JOEL PHAGOO P.E. PLLC,1,DOB NOW,Construction or Maintenance,Commercial District/Overlay
|
||||
B07996914-I1,BROOKLYN,,2022-10-01,2023-04-01,181,2023-10-01,354.0,,Permit Entire,3391840,302,40.68969,-73.97998,80,DEKALB AVENUE,3,2094,10,PAUL PERDEK PROF. ENG. PLLC,1,DOB NOW,Local Law 11,Commercial District/Overlay
|
|
87
map.py
Normal file
87
map.py
Normal file
@ -0,0 +1,87 @@
|
||||
import geopy.distance
|
||||
import overpy
|
||||
from shapely.geometry import Point, LineString
|
||||
import folium
|
||||
from math import radians, cos, sin, sqrt, atan2, asin
|
||||
from decimal import Decimal
|
||||
|
||||
import pandas as pd
|
||||
|
||||
R =6371
|
||||
|
||||
def distance(lat1, lon1, lat2, lon2):
|
||||
return geopy.distance.geodesic((lat1, lon1), (lat2, lon2)).m
|
||||
|
||||
def get_subline(points, length):
|
||||
subline = []
|
||||
subline_length = 0
|
||||
|
||||
# Iterate through the points and add them to the subline until its length is equal to or greater than the desired length
|
||||
for i in range(len(points) - 1):
|
||||
p1 = points[i]
|
||||
p2 = points[i+1]
|
||||
segment_length = distance(p1[0], p1[1], p2[0], p2[1])
|
||||
#print(f"Points {p1} -> {p2} : Distance {segment_length}")
|
||||
|
||||
# If adding the current segment would make the subline too long, interpolate a point on the segment and add that instead
|
||||
if subline_length + segment_length > length:
|
||||
remaining_length = length - subline_length
|
||||
ratio = Decimal(remaining_length / segment_length)
|
||||
subline.append(p1)
|
||||
subline.append((Decimal(p1[0]) + (Decimal(p2[0]) - Decimal(p1[0])) * ratio, p1[1] + (p2[1] - p1[1]) * ratio))
|
||||
return subline
|
||||
|
||||
subline.append(p1)
|
||||
subline_length += segment_length
|
||||
|
||||
# If we get to the end of the line and still haven't reached the desired length, just return the whole line
|
||||
subline.append(points[-1])
|
||||
return subline
|
||||
|
||||
df = pd.read_csv('data2.csv')
|
||||
clat = df['Latitude Point'][0]
|
||||
clon = df['Longitude Point'][0]
|
||||
m = folium.Map(location=[clat, clon], zoom_start=20)
|
||||
api = overpy.Overpass()
|
||||
|
||||
iters = 0
|
||||
|
||||
for index, row in df.iterrows():
|
||||
print(row)
|
||||
lat = row['Latitude Point']
|
||||
lon = row['Longitude Point']
|
||||
length = row['Sidewalk Shed/Linear Feet'] * 0.3048
|
||||
|
||||
# coordinates and length of line in feet
|
||||
#lat = 40.68941
|
||||
#lon = -73.97881
|
||||
#length = 260
|
||||
|
||||
# convert lat/lon to Point object
|
||||
coords = Point(lat, lon)
|
||||
|
||||
# use overpass API to get nearest sidewalk
|
||||
result = api.query(f'way["highway"="footway"](around:100,{lat},{lon});out;')
|
||||
if len(result.ways) == 0:
|
||||
continue
|
||||
sidewalk_coords = [(node.lat, node.lon) for node in result.ways[0].get_nodes(resolve_missing=True)]
|
||||
|
||||
# create LineString object from sidewalk coordinates
|
||||
new_line = get_subline(sidewalk_coords, length)
|
||||
# create folium map centered at given coordinates
|
||||
map_center = [lat, lon]
|
||||
|
||||
# add sidewalk and line to map
|
||||
folium.PolyLine(sidewalk_coords, color='orange', weight=10).add_to(m)
|
||||
for i in sidewalk_coords:
|
||||
folium.CircleMarker(location=[i[0], i[1]],
|
||||
radius=2,
|
||||
weight=5, tooltip=f"{i[0]}, {i[1]}").add_to(m)
|
||||
folium.PolyLine(new_line, color='red').add_to(m)
|
||||
iters = iters + 1
|
||||
if iters%50 == 0:
|
||||
m.save('your_map.html')
|
||||
|
||||
# show map
|
||||
m.save('your_map.html')
|
||||
|
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@ -0,0 +1,5 @@
|
||||
geopy==2.2.0
|
||||
overpy==0.4
|
||||
Shapely==1.7.1
|
||||
folium==0.12.1
|
||||
|
Loading…
Reference in New Issue
Block a user