Skip to content

Commit

Permalink
Merge 8d38428 into 8ba06bf
Browse files Browse the repository at this point in the history
  • Loading branch information
nllong committed Aug 6, 2019
2 parents 8ba06bf + 8d38428 commit 2628815
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ probablepeople==0.5.4
# Parsing and managing geojson data (this is only used in managed tasks at the moment)
geojson==2.4.1

# pnnl/buildingid
-e git+https://github.com/SEED-platform/buildingid.git@fd9067f70ae40f6ae3bf2bad6e31b5d2a9e8b150#egg=buildingid
# pnnl/buildingid-py
-e git+https://github.com/SEED-platform/buildingid.git@f68219df82191563cc2aca818e0b0fa1b32dd52d#egg=buildingid

enum34==1.1.6 # enum34 needs to be specified to support cryptography and oauth2
oauthlib==2.0.2
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pycodestyle==2.5.0
# documentation and spelling
Sphinx==1.8.1
sphinxcontrib-spelling==4.2.0
sphinx_rtd_theme==0.4.2
sphinx_rtd_theme==0.4.3

# For running the server
uWSGI==2.0.17.1
15 changes: 9 additions & 6 deletions seed/tests/test_utils_ubid.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,23 @@ def test_decode_ulids_does_nothing_if_no_ULID_provided(self):
def test_decode_ubids_is_successful_when_v2_format_C_NW_SE_UBID_provided(self):
property_details = self.property_state_factory.get_details()
property_details['organization_id'] = self.org.id
property_details['ubid'] = '849VQJH6+95J-849VQJH5+VGW-849VQJG6+XV8'
# Old format (v2) is not longer supported
# property_details['ubid'] = '849VQJH6+95J-849VQJH5+VGW-849VQJG6+XV8'
property_details['ubid'] = '849VQJH6+95J-51-58-42-50'

property = PropertyState(**property_details)
property.save()
properties = PropertyState.objects.filter(pk=property.id)

decode_unique_ids(properties)
refreshed_property = PropertyState.objects.get(pk=property.id)

property_bounding_box_wkt = (
"POLYGON ((-122.38778125 37.77740000000001, "
"-122.38778125 37.77975000000001, "
"-122.3911875 37.77975000000001, "
"-122.3911875 37.77740000000001, "
"-122.38778125 37.77740000000001))"
"POLYGON ((-122.3877812499996 37.77739999999996, "
"-122.3877812499996 37.77975000000004, "
"-122.3911875000003 37.77975000000004, "
"-122.3911875000003 37.77739999999996, "
"-122.3877812499996 37.77739999999996))"
)
property_centroid_wkt = (
"POLYGON ((-122.38959375 37.77845, "
Expand Down
25 changes: 13 additions & 12 deletions seed/utils/ubid.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# !/usr/bin/env python
# encoding: utf-8

import buildingid.v2
import buildingid.v3
from buildingid.code import decode
from django.contrib.gis.geos import GEOSGeometry

import logging

_log = logging.getLogger(__name__)


def centroid_wkt(state):
"""
Expand Down Expand Up @@ -33,12 +36,10 @@ def decode_unique_ids(qs):

for item in filtered_qs.iterator():
try:
bounding_box_obj = buildingid.v3.decode(getattr(item, unique_id))
bounding_box_obj = decode(getattr(item, unique_id))
except ValueError:
try:
bounding_box_obj = buildingid.v2.decode(getattr(item, unique_id))
except ValueError:
continue # property with an incorrectly formatted UBID/ULID is skipped
_log.error(f'Cound not decode UBID of {getattr(item, unique_id)}')
continue # property with an incorrectly formatted UBID/ULID is skipped

# Starting with the SE point, list the points in counter-clockwise order
bounding_box_polygon = (
Expand All @@ -52,11 +53,11 @@ def decode_unique_ids(qs):

# Starting with the SE point, list the points in counter-clockwise order
centroid_polygon = (
f"POLYGON (({bounding_box_obj.child.longitudeHi} {bounding_box_obj.child.latitudeLo}, "
f"{bounding_box_obj.child.longitudeHi} {bounding_box_obj.child.latitudeHi}, "
f"{bounding_box_obj.child.longitudeLo} {bounding_box_obj.child.latitudeHi}, "
f"{bounding_box_obj.child.longitudeLo} {bounding_box_obj.child.latitudeLo}, "
f"{bounding_box_obj.child.longitudeHi} {bounding_box_obj.child.latitudeLo}))"
f"POLYGON (({bounding_box_obj.centroid.longitudeHi} {bounding_box_obj.centroid.latitudeLo}, "
f"{bounding_box_obj.centroid.longitudeHi} {bounding_box_obj.centroid.latitudeHi}, "
f"{bounding_box_obj.centroid.longitudeLo} {bounding_box_obj.centroid.latitudeHi}, "
f"{bounding_box_obj.centroid.longitudeLo} {bounding_box_obj.centroid.latitudeLo}, "
f"{bounding_box_obj.centroid.longitudeHi} {bounding_box_obj.centroid.latitudeLo}))"
)
item.centroid = centroid_polygon

Expand Down

0 comments on commit 2628815

Please sign in to comment.