From fef4dd012a73daeb19f7f5750a90fc2fb93bcbcb Mon Sep 17 00:00:00 2001 From: jgavalda Date: Tue, 19 Dec 2023 11:37:24 -0500 Subject: [PATCH] Including a central point and plotting buildings in a square --- latlong2.py | 42 ++++++++++++++++++++++++++++++++++++++++++ main.py | 20 +++++++++++++------- 2 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 latlong2.py diff --git a/latlong2.py b/latlong2.py new file mode 100644 index 0000000..525b7b0 --- /dev/null +++ b/latlong2.py @@ -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]}") \ No newline at end of file diff --git a/main.py b/main.py index 0e23d69..9ca691d 100644 --- a/main.py +++ b/main.py @@ -5,13 +5,19 @@ from pathlib import Path # Make sure to enter your points in the clockwise direction # and in the longitude, latitude format -selection_box = Polygon([[-73.543833, 45.575932] , - [-73.541834, 45.575245], - [-73.542275, 45.574652], - [-73.544235, 45.575329], - [-73.543833, 45.575932]]) - -geojson_file = Path('./data/collinear_clean.geojson').resolve() +#selection_box = Polygon([[-73.543833, 45.575932] , +# [-73.541834, 45.575245], +# [-73.542275, 45.574652], +# [-73.544235, 45.575329], +# [-73.543833, 45.575932]]) +x=-73.61574532884296 +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() buildings_in_region = []