Skip to content

Commit

Permalink
Improve example and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerBroker2 committed Mar 1, 2024
1 parent 80946a1 commit deaf820
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 20 deletions.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
# GeoScraper
[![GitHub version](https://badge.fury.io/gh/PowerBroker2%2FGeoScraper.svg)](https://badge.fury.io/gh/PowerBroker2%2FGeoScraper) [![PyPI version](https://badge.fury.io/py/GeoScraper.svg)](https://badge.fury.io/py/GeoScraper)<br /><br />

Very user friendly library to parse OpenSourceMap data either from an XML file (i.e. *.osm), from an OSM API URL, or from a user specified bounding box.

# To Install
```
pip install GeoScraper
```

# Example Python Script
```python
import os
from pprint import pprint

from GeoScraper import GeoScraper


USE_BBOX = True
USE_FILE = True
USE_URL = True

XML_FNAME = os.path.join(os.path.dirname(__file__), 'map.osm') # YOU MAY NEED TO CHANGE THIS LINE!
BBOX = [-84.0958000, # left
39.7617000, # bottom
-84.0484000, # right
39.7823000] # top
URL = r'https://api.openstreetmap.org/api/0.6/map?bbox=-84.0958000,39.7617000,-84.0484000,39.7823000'


if __name__ == '__main__':
scraper = GeoScraper()

if USE_FILE:
print('=' * 50)
print('Using file:')
print('=' * 50)
scraper.from_file(XML_FNAME)
pprint(scraper.highways()[:3])
print('\n')

if USE_BBOX:
print('=' * 50)
print('Using bbox:')
print('=' * 50)
scraper.from_bbox(left = BBOX[0],
bottom = BBOX[1],
right = BBOX[2],
top = BBOX[3])
pprint(scraper.highways()[:3])
print('\n')
print('=' * 50)
print('Done')
print('=' * 50)

if USE_URL:
print('=' * 50)
print('Using url:')
print('=' * 50)
scraper.from_url(URL)
pprint(scraper.highways()[:3])
print('\n')
print('=' * 50)
print('Done')
print('=' * 50)
```
61 changes: 41 additions & 20 deletions examples/basic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,50 @@
from GeoScraper import GeoScraper


XML_FNAME = os.path.join(os.path.dirname(__file__),
'map.osm')
USE_BBOX = True
USE_FILE = True
USE_URL = True

XML_FNAME = os.path.join(os.path.dirname(__file__), 'map.osm') # YOU MAY NEED TO CHANGE THIS LINE!
BBOX = [-84.0958000, # left
39.7617000, # bottom
-84.0484000, # right
39.7823000] # top
URL = r'https://api.openstreetmap.org/api/0.6/map?bbox=-84.0958000,39.7617000,-84.0484000,39.7823000'


if __name__ == '__main__':
scraper = GeoScraper()

# print('=' * 50)
# print('Using file:')
# print('=' * 50)
# scraper.from_file(XML_FNAME)
# pprint(scraper.highways()[:3])
# print('\n')
if USE_FILE:
print('=' * 50)
print('Using file:')
print('=' * 50)
scraper.from_file(XML_FNAME)
pprint(scraper.highways()[:3])
print('\n')

if USE_BBOX:
print('=' * 50)
print('Using bbox:')
print('=' * 50)
scraper.from_bbox(left = BBOX[0],
bottom = BBOX[1],
right = BBOX[2],
top = BBOX[3])
pprint(scraper.highways()[:3])
print('\n')
print('=' * 50)
print('Done')
print('=' * 50)

print('=' * 50)
print('Using bbox:')
print('=' * 50)
scraper.from_bbox(left = -84.0958000,
bottom = 39.7617000,
right = -84.0484000,
top = 39.7823000)
pprint(scraper.highways()[:3])
print('\n')
print('=' * 50)
print('Done')
print('=' * 50)
if USE_URL:
print('=' * 50)
print('Using url:')
print('=' * 50)
scraper.from_url(URL)
pprint(scraper.highways()[:3])
print('\n')
print('=' * 50)
print('Done')
print('=' * 50)

0 comments on commit deaf820

Please sign in to comment.