Add select by coordinate function and update code comments

This commit is contained in:
Koa Wells 2024-01-08 18:13:23 -05:00
parent 26093f7bb2
commit 43e5666a9b
2 changed files with 24 additions and 8 deletions

View File

@ -26,8 +26,7 @@ class BuildingSelectionTool:
def select_by_polygon(self, selection_polygon_coordinates):
"""
Get all buildings within a specified polygon and write the output to output_file_path
:param selection_polygon: list of coordinates forming the selection polygon
:param output_file_path: path and file name for output file containing selected buildings and their metadata
:param selection_polygon_coordinates: list of coordinates forming the selection polygon
:return: None
"""
selection_polygon = Polygon(selection_polygon_coordinates)
@ -42,15 +41,24 @@ class BuildingSelectionTool:
def select_by_coordinate(self, coordinate):
"""
:param coordinate: longitude, latitude coordinate of selected
:return:
:return: None
"""
pass
longitude = coordinate[0]
latitude = coordinate[1]
point = Point([longitude, latitude])
for building in self.buildings:
building_coordinates = building['geometry']['coordinates'][0]
building_polygon = Polygon(building_coordinates)
if point.within(building_polygon):
self.selected_buildings.append(building)
def select_by_address(self, address):
"""
Select a building by inputting an address
:param address:
:return:
:return: None
"""
coordinates = helpers.get_gps_coordinate_by_address(address)
longitude = coordinates[1]
@ -66,8 +74,9 @@ class BuildingSelectionTool:
def save_selected_buildings(self, output_file_path):
"""
:return:
Save all selected buildings to an output file.
:param output_file_path: destination file path including file name and extension
:return: None
"""
output_file = Path(output_file_path).resolve()
output_region = {"type": "FeatureCollection",

View File

@ -2,6 +2,7 @@ from building_selection_tool import BuildingSelectionTool
selection_tool = BuildingSelectionTool('./data/collinear_clean.geojson')
# select all buildings within a polygon
sample_polygon_coordinates = [[-73.543833, 45.575932],
[-73.541834, 45.575245],
[-73.542275, 45.574652],
@ -10,8 +11,14 @@ sample_polygon_coordinates = [[-73.543833, 45.575932],
selection_tool.select_by_polygon(sample_polygon_coordinates)
# select building by address
sample_address = "2155 Rue Guy, Montreal, Quebec"
selection_tool.select_by_address(sample_address)
# select building by [longitude, latitude] coordinate
sample_coordinate = [-73.5790796, 45.4972906]
selection_tool.select_by_coordinate(sample_coordinate)
# save selected buildings in geojson format to specified output_file_path
output_file_path = "./output_files/sample_output.geojson"
selection_tool.save_selected_buildings(output_file_path)