Skip to content

Commit 82c39e8

Browse files
authored
Merge pull request #41 from ishiland/handle_similiar_names
- add similar street names example - update Github actions to use the GeoSupport 25c
2 parents 9fcdee7 + 462f520 commit 82c39e8

File tree

4 files changed

+86
-16
lines changed

4 files changed

+86
-16
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test-windows:
1111
runs-on: windows-latest
1212
env:
13-
GEO_VERSION: 25a
13+
GEO_VERSION: 25c
1414
steps:
1515
- uses: actions/checkout@v3
1616
- name: Set up Python 3.11 (64-bit)
@@ -22,7 +22,7 @@ jobs:
2222
shell: pwsh
2323
run: |
2424
$FILENAME = "gde_${{ env.GEO_VERSION }}_x64.zip"
25-
$URL = "https://s-media.nyc.gov/agencies/dcp/assets/files/zip/data-tools/bytes/$FILENAME"
25+
$URL = "https://s-media.nyc.gov/agencies/dcp/assets/files/zip/data-tools/bytes/geosupport/$FILENAME"
2626
$LOCALDIR = "gde_${{ env.GEO_VERSION }}_x64"
2727
$TARGETDIR = "C:\Program Files\Geosupport Desktop Edition"
2828
@@ -45,7 +45,7 @@ jobs:
4545
test-linux:
4646
runs-on: ubuntu-latest
4747
env:
48-
GEO_VERSION: 25a
48+
GEO_VERSION: 25c
4949
steps:
5050
- uses: actions/checkout@v3
5151
- name: Set up Python 3.11
@@ -68,7 +68,7 @@ jobs:
6868
6969
# Build the filename based on GEO_VERSION; for example, for 25b it becomes linux_geo25b_25.2.zip
7070
FILENAME="linux_geo${GEO_VERSION}_${NUM}.${MINOR}.zip"
71-
URL="https://s-media.nyc.gov/agencies/dcp/assets/files/zip/data-tools/bytes/$FILENAME"
71+
URL="https://s-media.nyc.gov/agencies/dcp/assets/files/zip/data-tools/bytes/geosupport/$FILENAME"
7272
7373
LOCALDIR="geosupport-install-lx"
7474

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Check out documentation for installing and usage [here](https://python-geosuppor
2020
## Compatibility
2121

2222
- Python 3.8+
23-
- Tested on Geosupport Desktop Edition 25a
23+
- Tested on Geosupport Desktop Edition 25c
2424
- Windows (64-bit & 32-bit) and Linux operating systems
2525

2626
## Quickstart
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
"""
3+
Example: Accessing similar street names from Geosupport errors
4+
5+
When Geosupport can't find a street name, it returns up to 10 similar names
6+
in the error response. This example shows how to extract them.
7+
"""
8+
9+
from geosupport import Geosupport, GeosupportError
10+
11+
12+
def get_similar_streets(error):
13+
"""Extract similar street names from a GeosupportError."""
14+
result = error.result
15+
16+
# Get count of similar names (may be string or int)
17+
count = result.get("Number of Street Codes and Street Names in List", 0)
18+
if isinstance(count, str):
19+
count = int(count.strip() or "0")
20+
if count == 0:
21+
return []
22+
23+
# Get list of street names (already parsed into a list by the library)
24+
similar_names = result.get("List of Street Names", [])
25+
26+
# Filter out empty strings and return
27+
return [name for name in similar_names if name and name.strip()]
28+
29+
30+
# Example usage
31+
if __name__ == "__main__":
32+
g = Geosupport()
33+
34+
# Example 1: Misspelled street name
35+
print("Example: Searching for 'wycoff street' in Brooklyn")
36+
print("-" * 50)
37+
38+
try:
39+
# This will fail because it should be 'wyckoff'
40+
result = g["1N"](borough_code="BK", street_name="wycoff street")
41+
except GeosupportError as e:
42+
print(f"Error: {e}\n")
43+
44+
# Extract and display similar names
45+
similar = get_similar_streets(e)
46+
if similar:
47+
print(f"Found {len(similar)} similar street(s):")
48+
for i, name in enumerate(similar, 1):
49+
print(f" {i}. {name}")
50+
51+
# You could now retry with similar[0] or let user choose
52+
print(f"\nRetrying with first match: '{similar[0]}'")
53+
result = g["1N"](borough_code="BK", street_name=similar[0])
54+
print(
55+
f"Success! Street code: {result.get('B10SC - First Borough and Street Code')}"
56+
)

examples/readme.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
# Geosupport Examples
22

3-
Some examples to demonstrate different usages of python-geosupport.
3+
Example scripts demonstrating python-geosupport usage.
4+
5+
## Running Examples
6+
7+
### Basic Usage
8+
9+
```bash
10+
# Run any example directly
11+
python handle_similar_street_names.py
12+
python pandas_simple.py
13+
python pandas_multiprocessing.py
14+
```
15+
16+
### Available Examples
17+
18+
| Example | Description |
19+
|---------|-------------|
20+
| `handle_similar_street_names.py` | Extract similar street names when Geosupport returns a "NOT RECOGNIZED" error |
21+
| `pandas_simple.py` | Geocode addresses in a pandas DataFrame |
22+
| `pandas_multiprocessing.py` | Parallel geocoding using multiprocessing for large datasets |
423

524
## Using Docker
6-
Use NYC Plannings [docker-geosupport](https://github.com/NYCPlanning/docker-geosupport) image to geocode your data.
725

8-
> nycplanning/docker-geosupport image will be automatically updated whenever there's a new major release or upad release on Bytes of the Big Apple
26+
NYC Planning's [docker-geosupport](https://github.com/NYCPlanning/docker-geosupport) image includes python-geosupport pre-installed.
927

10-
### Build
11-
```shell
28+
```bash
29+
# Build the examples container
1230
docker build . -t geosupport-examples
13-
```
1431

15-
### Run
16-
From this directory, you can run:
17-
```shell
32+
# Run examples
1833
docker run -it --rm --volume ${PWD}:/examples geosupport-examples pandas_simple.py
19-
2034
docker run -it --rm --volume ${PWD}:/examples geosupport-examples pandas_multiprocessing.py
2135
```
2236

23-
The outputs will be in the *./data* directory.
37+
Output files will be saved to `./data/` directory.

0 commit comments

Comments
 (0)