Including a central point and plotting buildings in a square

This commit is contained in:
Oriol Gavalda 2023-12-19 11:37:24 -05:00
parent 5da9766da6
commit fef4dd012a
2 changed files with 55 additions and 7 deletions

42
latlong2.py Normal file
View File

@ -0,0 +1,42 @@
import requests
def get_lat_lng(api_key, address):
base_url = "https://api.opencagedata.com/geocode/v1/json"
params = {
'q': address,
'key': api_key,
}
response = requests.get(base_url, params=params)
data = response.json()
if response.status_code == 200 and data['status']['code'] == 200:
location = data['results'][0]['geometry']
return location['lat'], location['lng']
else:
print(f"Error: {data['status']['message']}")
return None, None
def get_lat_lng_for_addresses(api_key, addresses):
coordinates = []
for address in addresses:
lat, lng = get_lat_lng(api_key, address)
if lat is not None and lng is not None:
coordinates.append((lat, lng))
return coordinates
# Replace 'YOUR_API_KEY' with your OpenCage Geocoding API key
api_key = '744ad0d2d58e49d1ac57d6fb04fe5d82'
# Example list of addresses
addresses = ["1600 Amphitheatre Parkway, Mountain View, CA",
"Eiffel Tower, Paris, France",
"Big Ben, London, UK"]
coordinates = get_lat_lng_for_addresses(api_key, addresses)
# Print the coordinates
for address, coord in zip(addresses, coordinates):
print(f"{address} -> Latitude: {coord[0]}, Longitude: {coord[1]}")

20
main.py
View File

@ -5,13 +5,19 @@ from pathlib import Path
# Make sure to enter your points in the clockwise direction # Make sure to enter your points in the clockwise direction
# and in the longitude, latitude format # and in the longitude, latitude format
selection_box = Polygon([[-73.543833, 45.575932] , #selection_box = Polygon([[-73.543833, 45.575932] ,
[-73.541834, 45.575245], # [-73.541834, 45.575245],
[-73.542275, 45.574652], # [-73.542275, 45.574652],
[-73.544235, 45.575329], # [-73.544235, 45.575329],
[-73.543833, 45.575932]]) # [-73.543833, 45.575932]])
x=-73.61574532884296
geojson_file = Path('./data/collinear_clean.geojson').resolve() y=45.603911965131
diff=0.001
selection_box = Polygon([[x+diff, y-diff],
[x-diff, y-diff],
[x-diff, y+diff],
[x+diff, y+diff]])
geojson_file = Path('./data/collinear_clean 1.geojson').resolve()
output_file = Path('./output_buildings.geojson').resolve() output_file = Path('./output_buildings.geojson').resolve()
buildings_in_region = [] buildings_in_region = []