Skip to content

Commit 9f2b729

Browse files
authored
Merge pull request #10 from fabanc/issue-9
Issue 9
2 parents 81a54ff + dd017a4 commit 9f2b729

File tree

5 files changed

+169
-4
lines changed

5 files changed

+169
-4
lines changed

scripts/gp_open_location_geocode.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import arcpy
22
from openlocationcode import openlocationcode as olc
33

4+
from lib import custom_errors
5+
46
# https://github.com/google/open-location-code/blob/master/python/openlocationcode_test.py
57
# https://grid.plus.codes/
68

@@ -12,7 +14,8 @@ def check_spatial_reference(feature_class):
1214
:param feature_class: The feature class that will be used to generate the Open Location Code.
1315
:return:
1416
"""
15-
sr = arcpy.Describe(feature_class).spatialReference
17+
desc = arcpy.Describe(feature_class)
18+
sr = desc.spatialReference
1619
if sr.factoryCode != 4326:
1720
raise ValueError('The input feature class must be in WHS84 (WKID 4326)')
1821

@@ -49,13 +52,13 @@ def validate_code_field_length(feature_class, plus_code_field, code_length):
4952

5053
field = fields[0]
5154
if field.type != 'String':
52-
raise Exception('The field for plus code must be of type String')
55+
raise custom_errors.FieldTypeError('The field for plus code must be of type String')
5356

5457
if field.length < 9:
55-
raise Exception('The field {} must at the minimum have a length of 9'.format(plus_code_field))
58+
raise custom_errors.FieldTooShort('The field {} must at the minimum have a length of 9'.format(plus_code_field))
5659

5760
if field.length < (code_length + 1):
58-
raise Exception('The field {} is not long enough. Field Length: {} - Plus Code Length: {} - Plus Code Length Required: {}'.format(
61+
raise custom_errors.FieldTooShort('The field {} is not long enough. Field Length: {} - Plus Code Length: {} - Plus Code Length Required: {}'.format(
5962
field.name,
6063
field.length,
6164
code_length,

scripts/lib/custom_errors.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# define Python user-defined exceptions
2+
class Error(Exception):
3+
"""Base class for other exceptions"""
4+
pass
5+
6+
7+
class FieldTypeError(Error):
8+
"""Raise when a field is not of the right type"""
9+
pass
10+
11+
12+
class FieldTooShort(Error):
13+
"""Raise when a field is too short"""
14+
pass

0 commit comments

Comments
 (0)