def test_from_geojson_units_test(): """Test the Model from_geojson method with non-meter units.""" # Load test geojson geojson_folder = os.path.join(os.getcwd(), 'tests', 'geojson') geo_fp = os.path.join(geojson_folder, 'TestGeoJSON.geojson') location = Location('Boston', 'MA', 'USA', 42.366151, -71.019357) model, loc = Model.from_geojson(geo_fp, location=location, units='Feet') # Check the first building bldg1 = [bldg for bldg in model.buildings if bldg.identifier == 'ResidenceBuilding'][0] # Check properties assert bldg1.identifier == 'ResidenceBuilding' assert bldg1.display_name == 'ResidenceBuilding' # Check if area is in feet square m2ft = 1 / hb_model.Model.conversion_factor_to_meters('Feet') sm2sft = m2ft * m2ft assert (600.0 * sm2sft) == pytest.approx(bldg1.floor_area, abs=1e-5) assert (200.0 * sm2sft) == pytest.approx(bldg1.footprint_area, abs=1e-5) assert bldg1.story_count == 3 # Check story assert bldg1.story_count == 3 assert len(bldg1.unique_stories) == 1 for story in bldg1.unique_stories: assert (3.0) == pytest.approx(story.floor_to_floor_height, abs=1e-10)
def test_from_geojson(): """Test the Model from_geojson method.""" # Load test geojson geojson_folder = os.path.join(os.getcwd(), 'tests', 'geojson') geo_fp = os.path.join(geojson_folder, 'TestGeoJSON.geojson') location = Location('Boston', 'MA', 'USA', 42.366151, -71.019357) model, loc = Model.from_geojson(geo_fp, location=location) # Check model non-geometry properties assert model.identifier == 'TestGeoJSON' assert model.display_name == 'TestGeoJSON' # Check model buildings (features) assert len(model.buildings) == 3, len(model.buildings) # Check the first building bldg1 = [bldg for bldg in model.buildings if bldg.identifier == 'ResidenceBuilding'][0] # Check properties assert bldg1.identifier == 'ResidenceBuilding' assert bldg1.display_name == 'ResidenceBuilding' assert 600.0 == pytest.approx(bldg1.floor_area, abs=1e-5) assert 200.0 == pytest.approx(bldg1.footprint_area, abs=1e-5) assert bldg1.story_count == 3 assert bldg1.unique_stories[0].floor_to_floor_height == pytest.approx(3.0, abs=1e-10) # Check the second building bldg2 = [bldg for bldg in model.buildings if bldg.identifier == 'RetailBuildingBig'][0] # Check properties assert bldg2.identifier == 'RetailBuildingBig' assert bldg2.display_name == 'RetailBuildingBig' assert 200.0 == pytest.approx(bldg2.floor_area, abs=1e-5) assert 200.0 == pytest.approx(bldg2.footprint_area, abs=1e-5) assert bldg2.story_count == 1 assert bldg2.unique_stories[0].floor_to_floor_height == pytest.approx(3.0, abs=1e-10) # Check the third building bldg3 = [bldg for bldg in model.buildings if bldg.identifier == 'OfficeBuilding'][0] # Check properties assert bldg3.identifier == 'OfficeBuilding' assert bldg3.display_name == 'OfficeBuilding' assert 1625.0 == pytest.approx(bldg3.floor_area, abs=1e-5) assert 325.0 == pytest.approx(bldg3.footprint_area, abs=1e-5) assert bldg3.story_count == 5 assert bldg3.unique_stories[0].floor_to_floor_height == pytest.approx(3.0, abs=1e-10)
def test_from_minimal_geojson(): """Test the Model from_geojson method with a minimal geojson file.""" # Load test geojson geojson_folder = os.path.join(os.getcwd(), 'tests', 'geojson') geo_fp = os.path.join(geojson_folder, 'TestGeoJSON_minimal.geojson') location = Location('Boston', 'MA', 'USA', 42.366151, -71.019357) model, loc = \ Model.from_geojson(geo_fp, all_polygons_to_buildings=True, location=location) # Check model non-geometry properties assert model.identifier == 'Model_1' assert model.display_name == 'Model_1' # Check model buildings (features) assert len(model.buildings) == 3, len(model.buildings) bldgs = [] for bldg in model.buildings: if abs(bldg.floor_area - 200.0) < 1e-5: # Formerly ResidentialBuilding, or RetailBuildingBig bldgs.append(bldg) else: # Formerly OfficeBuilding bldgs.append(bldg) # Check properties assert 200.0 == pytest.approx(bldgs[0].floor_area, abs=1e-5) assert 200.0 == pytest.approx(bldgs[0].footprint_area, abs=1e-5) assert bldgs[0].story_count == 1 assert bldgs[0].unique_stories[0].floor_to_floor_height == \ pytest.approx(3.5, abs=1e-10) # Check properties assert 200.0 == pytest.approx(bldgs[1].floor_area, abs=1e-5) assert 200.0 == pytest.approx(bldgs[1].footprint_area, abs=1e-5) assert bldgs[1].story_count == 1 assert bldgs[1].unique_stories[0].floor_to_floor_height == \ pytest.approx(3.5, abs=1e-10) # Check properties assert 325.0 == pytest.approx(bldgs[2].floor_area, abs=1e-5) assert 325.0 == pytest.approx(bldgs[2].footprint_area, abs=1e-5) assert bldgs[2].story_count == 1 assert bldgs[2].unique_stories[0].floor_to_floor_height == \ pytest.approx(3.5, abs=1e-10)
def test_from_geojson_coordinates_simple_location(): """Test the Model coordinates from_geojson method with different location inputs. """ # Test 1: The location is equal to the point (0, 0) in model space. # Construct Model pts_1 = (Point3D(50, 50, 0), Point3D(60, 50, 0), Point3D(60, 60, 0), Point3D(50, 60, 0)) pts_2 = (Point3D(60, 50, 0), Point3D(70, 50, 0), Point3D(70, 60, 0), Point3D(60, 60, 0)) room2d_1 = Room2D('Residence1', Face3D(pts_1), 3) room2d_2 = Room2D('Residence2', Face3D(pts_2), 3) story = Story('ResidenceFloor', [room2d_1, room2d_2]) story.solve_room_2d_adjacency(0.01) story.set_outdoor_window_parameters(SimpleWindowRatio(0.4)) story.multiplier = 3 test_building = Building('ResidenceBuilding', [story]) # Convert to geojson. Location defines the origin of the model space. test_model = Model('TestGeoJSON_coords1', [test_building]) location = Location('Boston', 'MA', 'USA', 42.366151, -71.019357) # bottom-left geojson_folder = './tests/geojson/' test_model.to_geojson(location, folder=geojson_folder) geo_fp = os.path.join(geojson_folder, test_model.identifier, '{}.geojson'.format(test_model.identifier)) # Convert back to Model. Location defines the origin. model, loc = Model.from_geojson(geo_fp, location=location, point=Point2D(0, 0)) assert len(model.buildings) == 1 # Test geometric properties of building bldg1 = model.buildings[0] # Check story height for story in bldg1.unique_stories: assert 3.0 == pytest.approx(story.floor_to_floor_height, abs=1e-10) assert pytest.approx(bldg1.footprint_area, test_building.footprint_area, abs=1e-10) vertices = bldg1.footprint()[0].vertices test_vertices = test_building.footprint()[0].vertices for point, test_point in zip(vertices, test_vertices): assert point.is_equivalent(test_point, 1e-5) # Test 2: Change the location to equal to the point (70, 60) in model space, which is # the top-right corner of the building footprints. # Construct model with a new location that defines the top-right corner in lon/lat degrees. location2 = Location('Boston', 'MA', 'USA', 42.366690813294774, -71.01850462247945) # We define the point at the top-right corner in model units. model, loc = Model.from_geojson(geo_fp, location=location2, point=Point2D(70, 60)) assert len(model.buildings) == 1 # Test geometric properties of building bldg1 = model.buildings[0] assert test_building.footprint_area == pytest.approx(bldg1.footprint_area, abs=1e-5) vertices = bldg1.footprint()[0].vertices test_vertices = test_building.footprint()[0].vertices for point, test_point in zip(vertices, test_vertices): assert point.is_equivalent(test_point, 1e-3) # reduce precision due to conversion nukedir(os.path.join(geojson_folder, test_model.identifier), True)
from ladybug_rhino.config import tolerance, angle_tolerance, units_system, \ conversion_to_meters from ladybug_rhino.grasshopper import all_required_inputs except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component) and _import: # set default inputs if not specified pt = to_point2d(_point_) if _point_ is not None else Point2D(0, 0) all_to_bldg = bool(all_to_bldg_) # handle case of None model_units, con_fac = units_system(), 1 / conversion_to_meters() # convert the geoJSON to a dragonfly Model model, location = Model.from_geojson(_geojson, point=pt, all_polygons_to_buildings=all_to_bldg, units=model_units, tolerance=tolerance, angle_tolerance=angle_tolerance) point = from_point2d(pt) # if other geometry has been requested, then import it if other_geo_: # parse the geoJSON into a dictionary and get lat/lon converters with open(_geojson, 'r') as fp: data = json.load(fp) origin_lon_lat = origin_long_lat_from_location(location, pt) _convert_facs = meters_to_long_lat_factors(origin_lon_lat) convert_facs = 1 / _convert_facs[0], 1 / _convert_facs[1] # get all of the non-building geometry features geo_types = ('LineString', 'Polygon')