Skip to content

Instantly share code, notes, and snippets.

@aidenprice
Last active August 29, 2015 14:03
Show Gist options
  • Save aidenprice/b6c2f364c02ed8a38321 to your computer and use it in GitHub Desktop.
Save aidenprice/b6c2f364c02ed8a38321 to your computer and use it in GitHub Desktop.
A class to describe a point in latitude, longitude and elevation. __eq__ and __repr__ methods excluded. This class was created for my Curtin University, Masters of Geospatial Science, Spatial Computations 100, second assignment, BoreholeWrangler V3.0.
class LocationObject:
# Class properties
fLatitude = None
fLongitude = None
fElevation = None
# Class hidden properties
# Minimum and maximum values to validate location inputs.
_MIN_LATITUDE = -90.0
_MAX_LATITUDE = 90.0
_MIN_LONGITUDE = -180.0
_MAX_LONGITUDE = 180.0
_MIN_ELEVATION = -16.0
_MAX_ELEVATION = 8848.0
def __init__(self, fLatitudeInput, fLongitudeInput, fElevationInput=0.0):
try: # Exception handling for invalid latitude input
if self._MIN_LATITUDE <= fLatitudeInput <= self._MAX_LATITUDE:
self.fLatitude = float(fLatitudeInput)
else:
raise ValueError("Latitude input not on planet Earth")
except ValueError:
raise ValueError("Non-numerical input to latitude value")
try: # Exception handling for invalid longitude input
if self._MIN_LONGITUDE <= fLongitudeInput <= self._MAX_LONGITUDE:
self.fLongitude = float(fLongitudeInput)
else:
raise ValueError("Longitude input not on planet Earth")
except ValueError:
raise ValueError("Non-numerical input to longitude value")
try: # Exception handling for invalid elevation input
if self._MIN_ELEVATION <= fElevationInput <= self._MAX_ELEVATION:
self.fElevation = float(fElevationInput)
else:
raise ValueError("Elevation input not on the surface of the Earth")
except ValueError:
raise ValueError("Non-numerical input to elevation value")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment