Python: error using osmnx during building extraction - python

I would like to extract the building layer information from in Haiti using osmnx. I works for different cities it does not in the case of
import osmnx as ox
place_name = "Port-au-Prince"
buildings = ox.buildings_from_place(place_name)
I get the following error
TypeError: Geometry must be a shapely Polygon or MultiPolygon

I guess this is an internal bug of osmnx. "Port-au-Prince" is mapped in OSM as a node. This node is the first result when searching for "Port-au-Prince" in Nominatim (a geocoder). osmnx seems to expect an area instead, i.e. an administrative boundary relation. Such a relation comes second and third in Nominatim. osmnx seems to fail if it finds a node as first search result. Create an upstream bug report for osmnx.

See https://github.com/gboeing/osmnx/issues/16 for a comprehensive discussion of this issue and how to resolve it in your query.
Per the OSMnx documentation:
The query must be geocodable and OSM must have polygon boundaries for the geocode result. If OSM does not have a polygon for this place, you can instead get its street network using the graph_from_address function, which geocodes the place name to a point and gets the network within some distance of that point. Alternatively, you might try to vary the which_result parameter to use a different geocode result. For example, the first geocode result (ie, the default) might resolve to a point geometry, but the second geocode result for this query might resolve to a polygon, in which case you can use graph_from_place with which_result=2.

Related

finding nearest edge to a gps point by querying OpenStreetMap in Athena

Previously I have used OSMnx library in python to get the closest drive way to a particular gps datapoint. To do so I was using following code:
places=['Nebraska, USA']
G=ox.graph_from_place(places,network_type='drive')
origin_point = (lat, long)
nearest_edge = ox.get_nearest_edge(G, origin_point)
Now what I want to do is querying OpenStreetMap with Athena for the same thing (still in the python). I want to give bunch of gps datapoints and for each datapoint get the closest road. Does anyone know how I should do this?
Also if you know any documentation which can help I really appreciate it.
Thanks
Athena and Presto support Geo-spatial functions such as:
SELECT ST_Distance(ST_Point(-71.0882, 42.3607), ST_Point(-74.1197, 40.6976))
Based on the dataset that you want to focus on and its format you can build in S3 a databased on the location that you care about such as roads in Nebraska, USA, and query against it.

Creating new nodes using redistribute_vertices

I am working on a graph flow model in the context of transport networks. I have the position of sensors (lat/lon) and would like to associate these sensors with nodes on a graph retrieved using osmnx.
At present, I use get_nearest_node to map a sensor to a node. However, this isn't optimal, as I'm at the mercy of the cartographer -- straight roads will be have fewer nodes, and so the mean displacement (and therefore error) will be higher, even when dealing with unsimplified graphs. I had considered using get_nearest_edge, but I'd still need to edit the graph to insert a new node at the position of the sensor.
Instead, I thought a reasonable way of achieving this would be to upsample the graph (perhaps using redistribute_vertices), applying get_nearest_node, and then re-simplifying the graph, but somehow whitelisting the node that is now associated with a sensor to prevent it from being removed.
However, it's not clear to me how to go from the output of redistribute_vertices to a graph -- it returns a LineString or MultiLineString rather than a new graph.
I saw this question posted on the osmnx GitHub project: https://github.com/gboeing/osmnx/issues/304, in which a GeoDataFrame is generated, with a new column containing the redistributed way as a (Multi)LineString. However, I'm not sure how I can map this new gdf back to a Graph -- the corresponding node dataframe hasn't been updated, and u and v values remain the same in the new edges table.
Any pointers (including telling me I'm going about this the wrong way and should be using function XYZ) would be really appreciated.

Use OSMnx to evaluate the travel time depending on the OSM highway=* key: maxspeed. Possible?

I'm working me throu the impressiv OSMnx jupyter notebook of gboenig, I'm a MA Architecture Student from Germany and would like to use some Code to bring some fundametal Arguments to my MasterThesis, so I tried a lot and I'm very happy with the possibilities and the results. But there is one scenario that i want to evaluate:
First, all of my questions based on the osmnx-examples from Geoff Boeing (https://github.com/gboeing/osmnx-examples/tree/master/notebooks) so I don't post code snippets because there are no changes at the moment.
My idea is to analyse the impact of changing the maxspeed in some streets to raise the traveltime and force the driver to use another way throu the area, so that the lineare distance isn't the fastest way.
For this I made 2 OSM Files with JOSM, one with the current status and one with my changes.
To simplify I have the picture below:
Shortest - Fastest Way
The Red Vector is the shortest way, but with the parameter maxspeed from OSM the blue one could be the fastest, and I would like to analyse witch ways I have to manipulate to get the result I'm looking for.
From the OSMnx-Examples Notebook I know the Route function, witch reacts to oneway streets and on the other Hand I know the Isometric Workflow from the Example Notebook, where I can set the travel_speed, but is there a way to use the maxspeed key from highway?
The functionality to calculate edge travel times is available as of OSMnx v0.13.0. You can then use these new edge travel time attributes to solve network shortest paths by travel time rather than distance.

Facebook Graph Api checkins in geographical area

Well i want to use facebook's graph api to get checkins from a specific geo-graphical location with python.
In the api documentation area i didn't find the right combinations of api parameters to get it done;
http://developers.facebook.com/docs/reference/api/checkin/
For example , if i want to get all checkins in coffee-shops in Harvard-square(Boston) what would be the api call ? (without going into specifying every coffee-shop in that location)
thanks.
You can search for coffee places as follows:
https://graph.facebook.com/search?q=coffee&type=place.
You can then narrow narrow your search to a specific location and distance by adding the center parameter (with latitude and longitude) and an optional distance parameter:
https://graph.facebook.com/search?q=coffee&type=place&center=37.76,-122.427&distance=1000
This is documented by Facebook here.

How to convert from lat lon to zipcode or state to generate choropleth map

I have a large collection (and growing) of geospatial data (lat, lon) points (stored in mongodb, if that helps).
I'd like to generate a choropleth map (http://vis.stanford.edu/protovis/ex/choropleth.html), which requires knowing the state which contains that point. Is there a database or algorithm that can do this without requiring call to external APIs (i.e. I'm aware of things like geopy and the google maps API).
Actually, the web app you linked to contains the data you need -
If you look at http://vis.stanford.edu/protovis/ex/us_lowres.js for each state, borders[] contains a [lat,long] polyline which outlines the state. Load this data and check for point-in-polygon - http://en.wikipedia.org/wiki/Point_in_polygon
Per Reverse Geocoding Without Web Access you can speed it up a lot by pre-calculating a bounding box on each state and only testing point-in-polygon if point-in-bounding-box.
Here's how to do it in FORTRAN. Remember FORTRAN? Me neither. Anyway, it looks pretty simple, as every state has its own range.
EDIT It's been point out to me that your starting point is LAT-LONG, not the zipcode.
The algorithm for converting a lat-long to a political division is called "a map". Seriously, that's allan ordinary map is, a mapping of every point in some range to the division it belongs to. A detailed digital map of all 48 contiguous states would be a big database, and then you would need some (fairly simple) code to determine for each state (described as a series of line segments outlining the border) whether a given point was inside it or out.
you can try using Geonames database. It has long/lat as well as city, postal and other location type data. It is free as well.
but If you need to host it locally or import it into your own database , the USGS and NGA provide a comprehensive list of cities with lat/lon. It's updated reguarly, free, and reliable.
http://geonames.usgs.gov
http://earth-info.nga.mil/gns/html/index.html
Not sure the quality of the data, but give this a shot: http://www.boutell.com/zipcodes/
If you don't mind a very crude solution, you could adapt the click-map here.

Categories

Resources