Unique Building Identifier (UBID)
Project description
Website: https://buildingid.pnnl.gov/
Documentation
Install
To complete this guide, Git and Python 3 are required. Dependencies are automatically installed using pip.
Clone the repository, and then install the pnnl-buildingid package:
git clone https://github.com/pnnl/buildingid-py cd buildingid-py pip3 install -e .[dev]
Verify the location of the buildingid command:
which buildingid #=> /usr/local/bin/buildingid
Uninstall
Use pip to remove the pnnl-buildingid package:
pip3 uninstall pnnl-buildingid
Test
Test the pnnl-buildingid package using the pytest package:
pytest tests/
Coverage testing is enabled using the pytest-cov plugin:
pip3 install pytest-cov pytest --cov=buildingid --cov-report=html tests/
Usage
The pnnl-buildingid package supports two usages:
Application programming interface (API)
Command-line interface (CLI; the buildingid command)
The API
buildingid.code
Code
CodeArea
area() -> float
encode() -> Code
intersection(CodeArea) -> typing.Optional[typing.Tuple[float, float, float, float]]
jaccard(CodeArea) -> typing.Optional[float]
resize() -> CodeArea
decode(Code) -> CodeArea
encode(float, float, float, float, float, float, **kwargs) -> Code
isValid(Code) -> bool
Note: The Optional and Tuple type hints are provided by the typing module.
In the following example, a UBID code is decoded and then re-encoded:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import buildingid.code if __name__ == '__main__': # Initialize UBID code. orig_code = '849VQJH6+95J-51-58-42-50' print(orig_code) # Decode UBID code. orig_code_area = buildingid.code.decode(orig_code) print(orig_code_area) # Resize resulting UBID code area. # # The effect of this operation is that the length and width of the UBID code # area are reduced by half an OLC code area. new_code_area = orig_code_area.resize() print(new_code_area) # Encode new UBID code area. new_code = new_code_area.encode() print(new_code) # Test that new UBID code and UBID code area match the originals. assert (orig_code == new_code) assert (orig_code_area == new_code_area)
The CLI
View the documentation for the buildingid command using the --help command-line option:
buildingid --help #=> Usage: buildingid [OPTIONS] COMMAND [ARGS]... #=> <<more lines of output>>
View the documentation for a sub-command of the buildingid command using the --help command-line option. For example, to view the documentation for the “append2csv” sub-command:
buildingid append2csv --help #=> Usage: buildingid append2csv [OPTIONS] [latlng|wkb|wkt] #=> <<more lines of output>>
Commands
Command name |
Description |
|---|---|
append2csv |
Read CSV file from stdin, append UBID field, and write CSV file to stdout. |
crossref |
Read two CSV files, cross-reference UBID fields, and write CSV file. |
Tutorials
Instructions in this section use Bash syntax.
Append UBID field to CSV file
Prerequisites
buildingid command is installed.
Verify installation:
buildingid --version
Expected output: “buildingid, version 2.0.0” (or higher version)
Step-by-step instructions
Locate input CSV file, e.g., path/to/in.csv.
Locate output CSV file (generated), e.g., path/to/out.csv.
Locate errors CSV file (generated), e.g., path/to/err.csv.
Identify number of digits in Open Location Code (OLC) part of UBID code string, e.g., 11.
Identify column of output CSV file that contains UBID code strings, e.g., “UBID”.
If input CSV file contains latitude and longitude coordinates for a centroid only:
Identify columns of input CSV file that contain latitude and longitude coordinates, e.g., “Latitude” and “Longitude”.
Assign UBIDs:
buildingid append2csv latlng --code-length=11 --fieldname-code="UBID" --fieldname-center-latitude="Latitude" --fieldname-center-longitude="Longitude" < path/to/in.csv > path/to/out.csv 2> path/to/err.csv
If input CSV file contains latitude and longitude coordinates for (i) a centroid and (ii) the northeast and southwest corners of a bounding box:
Identify columns of input CSV file that contain latitude and longitude coordinates, e.g., “Latitude_C”, “Longitude_C”, “Latitude_N”, “Longitude_E”, “Latitude_S”, and “Longitude_W”.
Assign UBIDs:
buildingid append2csv latlng --code-length=11 --fieldname-code="UBID" --fieldname-center-latitude="Latitude_C" --fieldname-center-longitude="Longitude_C" --fieldname-north-latitude="Latitude_N" --fieldname-east-longitude="Longitude_E" --fieldname-south-latitude="Latitude_S" --fieldname-west-longitude="Longitude_W" < path/to/in.csv > path/to/out.csv 2> path/to/err.csv
If input CSV file contains hex-encoded well-known binary (WKB) strings:
Identify column of input CSV file that contains hex-encoded WKB strings, e.g., “WKB”.
Assign UBIDs:
buildingid append2csv wkb --code-length=11 --fieldname-code="UBID" --fieldname-wkbstr="WKB" < path/to/in.csv > path/to/out.csv 2> path/to/err.csv
If input CSV file contains well-known text (WKT) strings:
Identify column of input CSV file that contains WKT strings, e.g., “WKT”.
Assign UBIDs:
buildingid append2csv wkt --code-length=11 --fieldname-code="UBID" --fieldname-wktstr="WKT" < path/to/in.csv > path/to/out.csv 2> path/to/err.csv
Notes
See buildingid append2csv --help for full help.
Cross-reference UBID fields in two CSV files
Prerequisites
buildingid command is installed.
Verify installation:
buildingid --version
Expected output: “buildingid, version 2.0.0” (or higher version)
Step-by-step instructions
Locate left input CSV file, e.g., path/to/left.csv.
Locate right input CSV file, e.g., path/to/right.csv.
Locate output CSV file (generated), e.g., path/to/out.csv.
Identify column of left input CSV file that contains UBID code strings, e.g., “UBID”.
Identify column of right input CSV file that contains UBID code strings, e.g., “UBID”.
Cross-reference UBIDs:
buildingid crossref path/to/left.csv path/to/right.csv path/to/out.csv --left-fieldname-code="UBID" --right-fieldname-code="UBID"
Notes
See buildingid crossref --help for full help.
Default behavior is for output CSV file to be many-to-many (i.e., many records in left input CSV file are cross-referenced with many records in right input CSV file). Use --left-group-by-jaccard and --right-group-by-jaccard options for one-to-many and many-to-one, respectively.
Default behavior is for output CSV file to include only columns that contain UBID code strings. Use --include-left-field and --include-right-field options to include other columns.
Convert from Esri shapefile to CSV file
Prerequisites
Geospatial Data Abstraction Library (GDAL) is installed.
Verify installation:
ogr2ogr --version
Expected output: “GDAL 2.3.1, released 2018/06/22” (version and release date may vary)
Step-by-step instructions
Locate input Esri shapefile, e.g., path/to/in.shp.
Locate input PRJ file, e.g., path/to/in.prj.
Locate output CSV file (generated), e.g., path/to/out.csv.
Convert input Esri shapefile into output CSV file:
ogr2ogr -s_srs "$(cat path/to/in.prj)" -t_srs "EPSG:4326" -f CSV path/to/out.csv path/to/in.shp -lco GEOMETRY=AS_WKT
Notes
See ogr2ogr --long-usage for full help.
Output CSV file has added “WKT” column whose elements are well-known text (WKT) strings; enabled by -lco GEOMETRY=AS_WKT option.
Projection system for geographic coordinates in output CSV file is WGS84; enabled by -t_srs "EPSG:4326" option.
Records in input Esri shapefile are converted into rows in output CSV file, where fields in input Esri shapefile are converted into columns in output CSV file.
Shapes in input Esri shapefile are converted into elements of “WKT” column of output CSV file.
Case Studies
Chicago, IL
The City of Chicago’s open data portal hosts the “Building Footprints (current)” dataset in CSV format; available at: https://data.cityofchicago.org/api/views/syp8-uezg/rows.csv?accessType=DOWNLOAD.
The “the_geom” column of the input CSV file contains WKT strings.
To assign UBIDs to the records in the input CSV file:
buildingid append2csv wkt --code-length=11 --fieldname-code="UBID" --fieldname-wktstr="the_geom" < rows.csv > rows.out.csv 2> rows.err.csv
San Jose, CA
The City of San Jose hosts datasets that include building footprints and land parcels.
The contents of the “Basemap_2” zip archive includes a building footprints dataset in Esri shapefile format. The coordinate system is NAD 1983 StatePlane California III FIPS 0403 Feet.
To convert the Esri shapefile into CSV format and then assign UBIDs to the resulting CSV file:
ogr2ogr -s_srs "$(cat Basemap2_201905021152225992/BuildingFootprint.prj)" -t_srs "EPSG:4326" -f CSV BuildingFootprint.csv Basemap2_201905021152225992/BuildingFootprint.shp -lco GEOMETRY=AS_WKT
buildingid append2csv wkt --code-length=11 --fieldname-code="UBID" --fieldname-wktstr="WKT" < BuildingFootprint.csv > BuildingFootprint.out.csv 2> BuildingFootprint.err.csv
License
Contributions
Contributions are accepted on GitHub via the fork and pull request workflow. See here for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file buildingid_nrel-2.2.0.tar.gz.
File metadata
- Download URL: buildingid_nrel-2.2.0.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90fb94dd429f1bd97623741001ff5e15f8e1fefcd6f18bb08a5828bdc77254a4
|
|
| MD5 |
88d831a286ac1b5e1e6a25e73df30640
|
|
| BLAKE2b-256 |
259f85767597c70668a7de142b8cd77fa3f813bef962c84aba48d3678206a171
|
Provenance
The following attestation bundles were made for buildingid_nrel-2.2.0.tar.gz:
Publisher:
pypi_release.yml on SEED-platform/buildingid-nrel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
buildingid_nrel-2.2.0.tar.gz -
Subject digest:
90fb94dd429f1bd97623741001ff5e15f8e1fefcd6f18bb08a5828bdc77254a4 - Sigstore transparency entry: 577000165
- Sigstore integration time:
-
Permalink:
SEED-platform/buildingid-nrel@46853f6c32737aea0a267f44e895d0b007113d1a -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/SEED-platform
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@46853f6c32737aea0a267f44e895d0b007113d1a -
Trigger Event:
release
-
Statement type:
File details
Details for the file buildingid_nrel-2.2.0-py3-none-any.whl.
File metadata
- Download URL: buildingid_nrel-2.2.0-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96a3097d78c98140e49a72e20febc8d0fb93da54052e1a8fec0c37835c1c3760
|
|
| MD5 |
e43fb656263e7196ce86c7fc902cfce6
|
|
| BLAKE2b-256 |
5e37f281dc2c881b611693abfab42b54ab565ca6419ed68e41a6c1ce9ab935e8
|
Provenance
The following attestation bundles were made for buildingid_nrel-2.2.0-py3-none-any.whl:
Publisher:
pypi_release.yml on SEED-platform/buildingid-nrel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
buildingid_nrel-2.2.0-py3-none-any.whl -
Subject digest:
96a3097d78c98140e49a72e20febc8d0fb93da54052e1a8fec0c37835c1c3760 - Sigstore transparency entry: 577000225
- Sigstore integration time:
-
Permalink:
SEED-platform/buildingid-nrel@46853f6c32737aea0a267f44e895d0b007113d1a -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/SEED-platform
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@46853f6c32737aea0a267f44e895d0b007113d1a -
Trigger Event:
release
-
Statement type: