lib/urbanopt/geojson/helper.rb in urbanopt-geojson-0.3.1 vs lib/urbanopt/geojson/helper.rb in urbanopt-geojson-0.4.0

- old
+ new

@@ -1,7 +1,7 @@ # ********************************************************************************* -# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other +# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other # contributors. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: # @@ -181,11 +181,13 @@ # # * +elevation+ - _Type:Integer_ - Indicates the elevation. # * +origin_lat_lon+ - _Type:Float_ - An instance of +OpenStudio::PointLatLon+ indicating the origin's latitude and longitude. # * +runner+ - _Type:String_ - The measure run's instance of +OpenStudio::Measure::OSRunner+ . # * +zoning+ - _Type:Boolean_ - Value is +True+ if utilizing detailed zoning, else +False+. Zoning is set to False by default. - def self.floor_print_from_polygon(polygon, elevation, origin_lat_lon, runner, zoning = false) + # * +scaled_footprint_area+ - Used to scale the footprint area using the floor area. 0 by + # default (no scaling). + def self.floor_print_from_polygon(polygon, elevation, origin_lat_lon, runner, zoning = false, scaled_footprint_area = 0) floor_print = OpenStudio::Point3dVector.new all_points = OpenStudio::Point3dVector.new polygon.each do |p| lon = p[0] lat = p[1] @@ -205,10 +207,36 @@ return nil elsif normal.get.z > 0 floor_print = OpenStudio.reverse(floor_print) runner.registerWarning('Reversing floor print') end + + # check for scaling + if scaled_footprint_area > 0 + + # check that the scaled_footprint_area desired is no less than X % of the original + original_floor_print_area = OpenStudio.getArea(floor_print).get + if scaled_footprint_area / original_floor_print_area <= 0.5 || scaled_footprint_area / original_floor_print_area >= 2 + # TOO MUCH SCALING...using original footprint when scaled is 2x bigger or smaller than the original + runner.registerWarning('Desired scaled_footprint_area is a factor of 2 of the original footprint...keeping original footprint (no scaling!)') + else + new_floor_print = adjust_vertices_to_area(floor_print, scaled_footprint_area, runner) + new_footprint_area = OpenStudio.getArea(new_floor_print).get + runner.registerInfo("New floor area: #{new_footprint_area}, compared to scaled area desired: #{scaled_footprint_area}") + floor_print = new_floor_print + end + end + return floor_print + end + + # scale footprint to desired area, keeping the shape + def self.adjust_vertices_to_area(vertices, desired_area, runner, eps = 0.1) + ar = ScaleArea.new(vertices, desired_area, runner, eps) + + n = Newton.nlsolve(ar, [0]) + + return ar.new_vertices end ## # Calculate which other buildings are shading the current feature and return as an array of # +OpenStudio::Model::Space+.