Skip to content

Commit 3c90525

Browse files
authored
Merge pull request #133 from urbanopt/develop
Version 0.5.0
2 parents c7e9659 + cdc74c0 commit 3c90525

20 files changed

+121
-59
lines changed

.github/pull_request_template.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Addresses #[issue number here]
1+
### Resolves #[issue number here]
22

33
### Pull Request Description
44

@@ -9,5 +9,5 @@
99
- [ ] Unit tests have been added or updated
1010
- [ ] Documentation has been modified appropriately
1111
- [ ] All ci tests pass (green)
12-
- [ ] An [ISSUE](https://github.com/urbanopt/urbanopt-geojson-gem/issues) has been created that this is addressing. Issues will get added to the Change Log when the change_log.rb script is run.
12+
- [ ] An [issue](https://github.com/urbanopt/urbanopt-geojson-gem/issues) has been created (which will be used for the changelog)
1313
- [ ] This branch is up-to-date with develop

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# URBANopt GeoJSON Gem
22

3+
## Version 0.5.0
4+
Date Range 09/26/20 - 12/02/20
5+
6+
- Fixed [#124]( https://github.com/urbanopt/urbanopt-geojson-gem/issues/124 ), DOCUMENTATION: Add docs on scaling for building footprint using building area
7+
- Fixed [#126]( https://github.com/urbanopt/urbanopt-geojson-gem/issues/126 ), [BUG] setting timesteps_per_hour in a feature throws an error
8+
- Fixed [#131]( https://github.com/urbanopt/urbanopt-geojson-gem/issues/131 ), OpenStudio 3.1.0 support
9+
310
## Version 0.4.0
4-
Date Rage 08/08/20 - 09/25/20
11+
Date Range 08/08/20 - 09/25/20
512

613
Accepted Pull Requests: 11
714
- Fixed [#92]( https://github.com/urbanopt/urbanopt-geojson-gem/pull/92 ), Adds scaling for building footprint using building area

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Version 1.0
44

5-
The URBANopt<sup>&trade;</sup> team welcomes your contribution to the project. You can contribute to the URBANopt project in several ways: by using the software, reporting issues, contributing documentation, or contributing code back to the project. The GitHub [Contributing to Open Source](https://opensource.guide/how-to-contribute/) guide provides a good overview. If you contribute code, you agree that your contribution may be incorporated into the URBANopt Software Development Kit (SDK) and made available under the URBANopt SDK license.
5+
The URBANopt&trade; team welcomes your contribution to the project. You can contribute to the URBANopt project in several ways: by using the software, reporting issues, contributing documentation, or contributing code back to the project. The GitHub [Contributing to Open Source](https://opensource.guide/how-to-contribute/) guide provides a good overview. If you contribute code, you agree that your contribution may be incorporated into the URBANopt Software Development Kit (SDK) and made available under the URBANopt SDK license.
66

77
The contribution process for URBANopt is composed of three steps:
88

RDOC_MAIN.md

+26-22
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,57 @@
22

33
### [back to main docs](../)
44

5-
The URBANopt<sup>&trade;</sup> GeoJSON Gem has been developed by restructuring methods extracted from the
5+
The URBANopt&trade; GeoJSON Gem has been developed by restructuring methods extracted from the
66
[urban_geometry_creation](https://github.com/NREL/openstudio-urban-measures/tree/develop/measures/urban_geometry_creation)
77
and
88
[urban_geometry_creation_zoning.](https://github.com/NREL/openstudio-urban-measures/tree/develop/measures/urban_geometry_creation_zoning)
99

10-
The +urban_geometry_creation+ measure can be used to create an OpenStudio Model for a
10+
The `urban_geometry_creation` measure can be used to create an OpenStudio Model for a
1111
building feature from the feature file and create the surrounding buildings that are shading the
1212
building feature as shading objects.
13-
The arguments used in the measure are the +GeoJSON File+, +Feature ID+ of the building and +Surrounding Buildings+. The
14-
Surrounding Buildings argument takes two possible choices - None or Shading Only. The None choice
13+
The arguments used in the measure are the `geojson_file`, `feature_id` of the building, `surrounding_buildings` and `scale_footprint_area_by_floor_area`. The
14+
`surrounding_buildings` argument takes two possible choices - None or Shading Only. The None choice
1515
would create no other buildings adjacent to the building feature while the Shading Only option
16-
determines what other buildings are shading the building feature and creates them as OpenStudio Shading Surfaces.
16+
determines what other buildings are shading the building feature and creates them as OpenStudio
17+
Shading Surfaces. The `scale_footprint_area_by_floor_area` is an optional argument that is set to
18+
false by default. When set to true, the building footprint area is calculated from the
19+
floor_area/number_of_stories for the building in the GeoJSON file and this footprint area is used to
20+
scale the building coordinates and create the building.
1721

18-
The +urban_geometry_creation_zoning+ measure has the same capabilities as the
19-
+urban_geometry_creation+ measure, however it also creates core and perimeter zones for the spaces
20-
in the OpenStudio Model. It takes in the same arguments as the +urban_geometry_creation+ measure.
22+
The `urban_geometry_creation_zoning` measure has the same capabilities as the
23+
`urban_geometry_creation` measure, however it also creates core and perimeter zones for the spaces
24+
in the OpenStudio Model. It takes in the `geojson_file`, `feature_id` of the building,
25+
`surrounding_buildings` as arguments.
2126

2227
The main components of the gem are:
2328

24-
- geojson.rb : Base gem file that imports all modules and classes.
29+
- geojson.rb : Base gem file that imports all modules and classes.
2530
- extension.rb : The extension class inherits from OpenStudio::Extension::Extension, and
26-
overrides the following methods as needed -
31+
overrides the following methods as needed
2732
- _measures_dir_
2833
- _files_dir_
2934
- _doc_templates_dir_
30-
- Gemfile and .gemspec : Describe the extension dependencies on other gems.
31-
- Classes and Modules within +lib/urbanopt/geojson+ -
32-
35+
- Gemfile and .gemspec : Describe the extension dependencies on other gems.
36+
- Classes and Modules within `lib/urbanopt/geojson`
3337

3438
*Modules that do not require instances for calling the methods:*
3539

3640
- URBANopt::GeoJSON::Helper : Contains methods extracted from the two measures to
37-
perform utility-like tasks like - +is_shaded+ and +is_shadowed+.
41+
perform utility-like tasks like - `is_shaded` and `is_shadowed`.
3842
- URBANopt::GeoJSON::Zoning : Contains methods extracted from
39-
+urban_geometry_creation_zoning+ .
43+
`urban_geometry_creation_zoning`.
4044
- URBANopt::GeoJSON::Model : Contains methods that perform tasks on an instance of
41-
+OpenStudio::Model::Model+.
45+
`OpenStudio::Model::Model`.
4246

4347
*Classes and subclasses that contain instance-dependant methods and private methods
4448
that perform tasks on the given feature.*
4549

46-
- URBANopt::GeoJSON::GeoFile : Contains a +get_feature+ method that returns an
50+
- URBANopt::GeoJSON::GeoFile : Contains a `get_feature` method that returns an
4751
instance of a Feature Subclass for the the feature type. Also contains methods to validate the GeoJSON
48-
file against the GeoJSON schema.
49-
- URBANopt::GeoJSON::Feature : Contains methods to return +feature+ +id+ , +name+ ,
50-
+multiple+ +polygons+ +coordinates+ which are inherited by classes for all feature types.
52+
file against the GeoJSON schema.
53+
- URBANopt::GeoJSON::Feature : Contains methods to return `feature id` , `name` ,
54+
`multiple polygons coordinates` which are inherited by classes for all feature types.
5155
- URBANopt::GeoJSON::Building : A subclass of Feature, contains class methods that
52-
are specific to handling features of the Building type.
56+
are specific to handling features of the Building type.
5357
- URBANopt::GeoJSON::DistrictSystem : A subclass of Feature, contains class methods
54-
that are specific to handling features of District System type. *Note: This subclass does not contain any methods yet*.
58+
that are specific to handling features of District System type. *Note: This subclass does not contain any methods yet*.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# URBANopt GeoJSON Gem
22

3-
Library and measures to translate URBANopt<sup>&trade;</sup> GeoJSON format to OpenStudio. See the [developer documentation](https://urbanopt.github.io/urbanopt-geojson-gem/) for more details.
3+
Library and measures to translate URBANopt&trade; GeoJSON format to OpenStudio. See the [developer documentation](https://urbanopt.github.io/urbanopt-geojson-gem/) for more details.
44

55
## Installation
66

@@ -12,7 +12,7 @@ gem 'urbanopt-geojson'
1212

1313
And then execute:
1414

15-
$ bundle
15+
$ bundle install
1616

1717
Or install it yourself as:
1818

docs/.vuepress/components/InnerJsonSchema.vue

+7-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import highlightJson from "../highlight";
1313
import { emptyPromise } from '../utils';
1414
1515
const JSONSchemaViewP = emptyPromise();
16-
const $RefParserP = emptyPromise();
1716
1817
export default {
1918
name: "InnerJsonSchema",
@@ -24,27 +23,24 @@ export default {
2423
};
2524
},
2625
created() {
26+
// created only runs on the client, which is good because
27+
// this module causes an error if we load it in a server context
2728
import("json-schema-view-js").then(JSONSchemaViewP.resolve);
28-
import("json-schema-ref-parser/dist/ref-parser.js").then($RefParserP.resolve);
2929
},
3030
computed: {
3131
view() {
32-
return Promise.all([$RefParserP, JSONSchemaViewP])
33-
.then(([$RefParser]) => $RefParser.default.dereference(this.schema))
34-
.then(
35-
s =>
36-
new window.JSONSchemaView(s, 2, {
37-
theme: "dark"
38-
})
39-
);
32+
return JSONSchemaViewP
33+
.then( () => new window.JSONSchemaView(this.schema, 2, {
34+
theme: "dark"
35+
}));
4036
},
4137
schemaFormatted() {
4238
return highlightJson(JSON.stringify(this.schema, null, 2));
4339
}
4440
},
4541
methods: {
4642
async replaceRenderedSchema() {
47-
const v = await this.view;
43+
const v = await this.view; // this never resolves on the server
4844
this.$refs.schemaTarget.innerHtml = "";
4945
this.$refs.schemaTarget.appendChild(v.render());
5046
}

docs/.vuepress/config.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const path = require('path');
2+
13
module.exports = {
24
base: '/urbanopt-geojson-gem/',
35
themeConfig: {
@@ -18,5 +20,13 @@ module.exports = {
1820
]
1921
}
2022
]
21-
}
23+
},
24+
chainWebpack: config => {
25+
config.module
26+
.rule('json')
27+
.test(/\.json$/)
28+
.use(path.join(__dirname, 'json-schema-deref-loader.js'))
29+
.loader(path.join(__dirname, 'json-schema-deref-loader.js'))
30+
.end()
31+
},
2232
};

docs/.vuepress/highlight.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import hljs from "highlight.js/lib/highlight.js";
1+
import hljs from "highlight.js";
22
import json from "highlight.js/lib/languages/json";
33

44
hljs.registerLanguage("json", json);
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// thanks to https://gist.github.com/mgesmundo/07d6ea3958ed4c7d19d1161551fa46ca
2+
const $RefParser = require('@apidevtools/json-schema-ref-parser')
3+
4+
module.exports = async function () {
5+
const parser = new $RefParser()
6+
const schema = await parser.dereference(this.resourcePath, {
7+
dereference: {
8+
circular: false
9+
}
10+
})
11+
const resolve = await parser.resolve(this.resourcePath, {
12+
dereference: {
13+
circular: false
14+
}
15+
})
16+
17+
for (const dep in resolve._$refs) {
18+
this.addDependency(dep)
19+
}
20+
21+
return JSON.stringify(schema)
22+
}

docs/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
### <StaticLink href="rdoc/">Rdocs</StaticLink>
44

5-
The URBANopt<sup>&trade;</sup> GeoJSON Gem is an OpenStudio Extension Gem with functionality to translate
5+
The URBANopt&trade; GeoJSON Gem is an OpenStudio Extension Gem with functionality to translate
66
information in a GeoJSON format to energy model inputs. GeoJSON is a commonly used
7-
format for describing geospatial data related to the built environment.
7+
format for describing geospatial data related to the built environment.
88

99
A JSON schema for the GeoJSON format is available at [geojson
1010
schema](https://github.com/geojson/schema).
@@ -26,5 +26,4 @@ The current functionalities of the URBANopt GeoJSON gem include:
2626
- Translate Building Feature to an OpenStudio Model.
2727
- Translate Building Feature to OpenStudio Shading Objects.
2828

29-
The <StaticLink href="rdoc/">Rdocs</StaticLink> contain more information about the URBANopt GeoJSON Gem architecture.
30-
29+
The <StaticLink href="rdoc/">Rdocs</StaticLink> contain more information about the URBANopt GeoJSON Gem architecture.

docs/package-lock.json

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/urbanopt/geojson/building.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ def create_windows(spaces)
249249
end
250250
end
251251

252+
##
253+
# Used to calculate the perimeter from the floor polygon of a Feature. Returns the perimeter
254+
# value.
255+
#
256+
# [Parameters]
257+
# * +feature+ - An instance of URBANopt::GeoJSON::Feature
258+
#
252259
def calculate_perimeter(feature)
253260
model = OpenStudio::Model::Model.new
254261
runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
@@ -285,9 +292,8 @@ def calculate_perimeter(feature)
285292
end
286293

287294
##
288-
# Convert to a Hash equivalent for JSON serialization
289-
##
290-
# - Exclude attributes with nil values.
295+
# Convert to a Hash equivalent for JSON serialization.
296+
# Excludes attributes with nil value.
291297
##
292298
def to_hash
293299
result = {}

lib/urbanopt/geojson/feature.rb

+5
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def schema
9898
return @@feature_schema[feature_type]
9999
end
100100

101+
##
102+
# Used to calculate the aspect ratio for a given floor polygon.
103+
#
101104
def calculate_aspect_ratio
102105
multi_polygons = get_multi_polygons(@feature_json)
103106
rad_per_deg = 0.017453293
@@ -170,6 +173,8 @@ def calculate_aspect_ratio
170173
end
171174
end
172175

176+
##
177+
# Used to calculate the perimeter multiplier given the aspect ratio, original perimeter and area.
173178
def get_perimeter_multiplier(area, aspect_ratio, perimeter_original)
174179
perimeter_new = 2 * (Math.sqrt(area * aspect_ratio) + Math.sqrt(area / aspect_ratio))
175180
perimeter_ratio = perimeter_original / perimeter_new

lib/urbanopt/geojson/geo_file.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def merge_site_properties(feature)
199199
add_props.each do |prop|
200200
if project.key?(prop[:site]) && project[prop[:site]]
201201
# property exists in site
202-
if !feature[:properties].key?(prop[:feature]) || feature[:properties][prop[:feature]].nil? || feature[:properties][prop[:feature]].empty?
202+
if !feature[:properties].key?(prop[:feature]) || feature[:properties][prop[:feature]].nil? || feature[:properties][prop[:feature]].to_s.empty?
203203
# property does not exist in feature or is nil: add site property (don't overwrite)
204204
feature[:properties][prop[:feature]] = project[prop[:site]]
205205
end

lib/urbanopt/geojson/helper.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,14 @@ def self.floor_print_from_polygon(polygon, elevation, origin_lat_lon, runner, zo
229229
return floor_print
230230
end
231231

232-
# scale footprint to desired area, keeping the shape
232+
##
233+
# Used to scale footprint to desired area while keeping the original shape.
234+
#
235+
# [Parameters]
236+
# * +vertices+ - _Type:Array_ - An array of vertices for the original floorprint
237+
# * +desired_area+ - _Type:String_ - Area to which you want to scale the vertices to
238+
# * +runner+ - _Type:String_ - An instance of +Openstudio::Measure::OSRunner+ for the measure run.
239+
#
233240
def self.adjust_vertices_to_area(vertices, desired_area, runner, eps = 0.1)
234241
ar = ScaleArea.new(vertices, desired_area, runner, eps)
235242

lib/urbanopt/geojson/scale_area.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def initialize(vertices, desired_area, runner, eps)
6262
@one = BigDecimal('1.0')
6363
@two = BigDecimal('2.0')
6464
@ten = BigDecimal('10.0')
65-
@eps = eps # BigDecimal::new(eps)
65+
@eps = eps
6666
end
6767

6868
attr_reader :zero
@@ -75,7 +75,10 @@ def initialize(vertices, desired_area, runner, eps)
7575

7676
attr_reader :eps
7777

78-
# compute value
78+
##
79+
# Used to determine new scaled vertices, by iteratively passing in the perimeter distance to
80+
# minimise the difference of the new and scaled area. Returns the difference of the new area and desired area.
81+
#
7982
def values(x)
8083
@new_vertices = URBANopt::GeoJSON::Zoning.divide_floor_print(@vertices, x[0].to_f, @runner, scale = true)
8184
new_area = OpenStudio.getArea(@new_vertices)

lib/urbanopt/geojson/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030

3131
module URBANopt
3232
module GeoJSON
33-
VERSION = '0.4.0'.freeze
33+
VERSION = '0.5.0'.freeze
3434
end
3535
end

spec/files/nrel_stm_footprints.geojson

+4-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@
402402
"updated_at": "2017-09-01T21:17:07.518Z",
403403
"created_at": "2017-09-01T21:16:27.662Z",
404404
"height": 3,
405-
"geometryType": "Polygon"
405+
"geometryType": "Polygon",
406+
"timesteps_per_hour": 2
406407
}
407408
},
408409
{
@@ -1157,7 +1158,8 @@
11571158
"updated_at": "2017-09-01T21:17:07.484Z",
11581159
"created_at": "2017-09-01T21:16:27.622Z",
11591160
"height": 3,
1160-
"geometryType": "Polygon"
1161+
"geometryType": "Polygon",
1162+
"timesteps_per_hour": 2
11611163
}
11621164
},
11631165
{

spec/urbanopt/geojson/geo_file_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
feature = geofile.get_feature_by_id('59a9ce2b42f7d007c059d306')
4444
expect(feature.feature_json[:type]).to eq('Feature')
4545
expect(feature.feature_json[:properties][:name]).to eq('Thermal Test Facility')
46+
expect((feature.feature_json[:properties][:timesteps_per_hour]).to_s).to eq('2')
47+
expect((feature.feature_json[:properties][:timesteps_per_hour]).to_s).not_to be_empty
4648
end
4749

4850
it 'gets feature, given a feature_id geojson example' do

urbanopt-geojson-gem.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ Gem::Specification.new do |spec|
3030
spec.add_development_dependency 'rspec', '~> 3.7'
3131

3232
spec.add_runtime_dependency 'json-schema', '~> 2.8'
33-
spec.add_runtime_dependency 'openstudio-extension', '~> 0.2.5'
34-
spec.add_runtime_dependency 'urbanopt-core', '~> 0.4.0'
33+
spec.add_runtime_dependency 'openstudio-extension', '~> 0.3.1'
34+
spec.add_runtime_dependency 'urbanopt-core', '~> 0.5.0'
3535
end

0 commit comments

Comments
 (0)