Comments (6)
I tried a simple fix for this
def geocode(data: str):
try:
location = ox.geocode_to_gdf(data)
geom = location.geometry[0]
geojson = json.loads(json.dumps({"type": "Feature", "geometry": mapping(geom)})) # turn geom tuple into list by (de-)serialising
return geojson
except InsufficientResponseError as e:
print(f"An error occurred: {e}")
but getting issues with the geojson_to_quadkey
function in download_buildings
File "/usr/local/lib/python3.10/dist-packages/open_buildings-0.10.0-py3.10.egg/open_buildings/download_buildings.py", line 23, in geojson_to_quadkey
geom = shape(data["geometry"])
TypeError: 'NoneType' object is not subscriptable
@felix-schott can you try reproducing please?
from open-buildings.
Hi @mtravis - not on my laptop at the moment, so can't reproduce but I'm guessing it might be because the programme is not exiting and because the geocoding is unsuccessful, the programme continues and expects a geometry instead of None where it raises the error. try-except is the right approach to suppress the long error message, but we need to exit the programme immediately afterwards. A similar thing happens here - maybe copy that approach? The empty return terminates the programme. (On Linux, it would be better to use sys.exit(1) instead of an empty return but I'm not sure how that behaves on other platforms, so just use the empty return.)
from open-buildings.
I'd also print a more meaningful error message: "No results found for {location} - please try a different search term." Otherwise users don't know what's happening.
from open-buildings.
error
Actually, sorry, you will have to use sys.exit or raise an exception since return will only exit the helper function, not the whole programme. It might be cleaner to return None from the geocoding function if no result could be found, and then use the empty return approach in the calling function if geocoding_result is None
. Not sure if that's clear, if I have time, I can give you a code snippet
from open-buildings.
I've got it working with sys.exit but will try implementing the return None and updating the calling function later.
My error message is sensible looking once it calls the internal message from the event.
from open-buildings.
@felix-schott I'm struggling a bit with to get the script to exit fully without sys.exit(1). I agree it would be cleaner not to use this method but can't get download_buildings to work.
from open-buildings.
Related Issues (20)
- Automatically calculate country codes per quadkey & remove country_iso flag HOT 2
- Option to just get the 'count' of buildings, but not actually download the results. HOT 2
- Better progress reporting in `get_buildings` HOT 1
- Make get building requests with smaller quadkeys
- Better estimates of how long a query might take
- Warn users if their geojson is not in `iso_country`
- Don't create empty files if there are 0 features
- Add tests HOT 2
- Create QGIS plugin for get_buildings HOT 2
- Install spatial extension if not installed HOT 3
- Add a geocoding option HOT 2
- Tidy up requirements.txt
- Structure of the package
- Python interface for functionality
- Cannot save as Shapefile HOT 10
- Allow both .geojson and .json as suffixes to mean output as GeoJSON
- Accept more input formats HOT 2
- Installation requirement files and dependencies HOT 3
- Document version of data used HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from open-buildings.