-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
605 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,36 @@ | ||
import re | ||
|
||
|
||
class CiGrid: | ||
|
||
srid = 23030 | ||
|
||
def __init__(self, sref: str): | ||
self.sref = sref | ||
|
||
def validate(self) -> bool: | ||
if len(self.sref) == 8: | ||
return True | ||
else: | ||
|
||
# Ignore any spaces in the grid ref. | ||
self.sref = self.sref.replace(' ', '') | ||
|
||
# Check the first two letters are a valid combination. | ||
# Column is in range S-Z | ||
# Rows in the range U-V and A-G | ||
sq100 = self.sref[:2].upper() | ||
if not re.match(r'[S-Z]([U-V]|[A-G])', sq100): | ||
return False | ||
|
||
# Check either remaining chars are all numeric and an equal | ||
# number, up to 10 digits OR for DINTY Tetrads, 2 numbers followed by a | ||
# letter (Excluding O, including I). | ||
eastnorth = self.sref[2:] | ||
if (( | ||
not re.match(r'^[0-9]*$', eastnorth) or | ||
len(eastnorth) % 2 != 0 or | ||
len(eastnorth) > 10 | ||
) and ( | ||
not re.match(r'^[0-9][0-9][A-NP-Z]$', eastnorth) | ||
)): | ||
return False | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,34 @@ | ||
import re | ||
|
||
|
||
class NiGrid: | ||
|
||
srid = 29901 | ||
|
||
def __init__(self, sref: str): | ||
self.sref = sref | ||
|
||
def validate(self) -> bool: | ||
if len(self.sref) == 8: | ||
return True | ||
else: | ||
|
||
# Ignore any spaces in the grid ref. | ||
self.sref = self.sref.replace(' ', '') | ||
|
||
# Check the first letter is valid. | ||
sq100 = self.sref[0].upper() | ||
if not re.match(r'[A-HJ-Z]', sq100): | ||
return False | ||
|
||
# Check either remaining chars are all numeric and an equal | ||
# number, up to 10 digits OR for DINTY Tetrads, 2 numbers followed by a | ||
# letter (Excluding O, including I). | ||
eastnorth = self.sref[1:] | ||
if (( | ||
not re.match(r'^[0-9]*$', eastnorth) or | ||
len(eastnorth) % 2 != 0 or | ||
len(eastnorth) > 10 | ||
) and ( | ||
not re.match(r'^[0-9][0-9][A-NP-Z]$', eastnorth) | ||
)): | ||
return False | ||
|
||
return True |
Oops, something went wrong.