How to extract street graph or network from OpenStreetMap? - networking

How to extract street graph or network from OpenStreetMap ?

Solutions:
There are many solutions to achieve this goal, I listed some of them below.
- Overpass-api
Overpass-api & overpass-turbo let you use overpass query language to collect ways and nodes of type highway for a city :
[out:xml]; area[name = "Pantin"]; (way(area)[highway]; ); (._;>;); out;
Pantin is a city in France
- Geofabrik & Osmium
Geofabrik allows you to download various datasets from continents to cities.
Next, extract nodes and ways of type highway using Osmium tag-filters:
osmium tags-filter map.osm w/highway -o highways-ways.osm
NOTE: osmium tags-filter also works with .pbf files
- Ophois
Ophois is a CLI tool written in Rust, i created to:
Download a map from overpass-api
Process data from Overpass or Geofabrik to extract the street graph
Simplify the extracted graph with detailed heuristics
Discretize the extracted or simplified graph to a distance in meter
I also created a simple tool to display the generated graph on a Leaflet map to check the simplification process, cartographe.
Cartographe let you check the node id and the distance of links in meters using haversine formula.
Extracted
Simplified
Simplified and Discretized
NOTE: Simplified and discretized with 10 meters parameter
- OSMnx
OSMnx: Python for street networks. Retrieve, model, analyze, and visualize street networks and other spatial data from OpenStreetMap.
NOTE: Pantin using OSMnx

Related

How can I add streets as nodes in a osmnx graph?

If I understood well, the osmnx method graph_from_address generates a graph in which a node refers to the intersection of two or more streets, whereas edge refers to a single street connecting two (or more) intersections.
Following this figure, from reference[1], it seems osmnx method graph_from_address generates something like Fig 1 (b) (axial graph), rather than a connectivity graph as defined in Fig 1(c) of same reference, where streets are nodes instead of edges.
enter image description here
Is there a osmnx method to extract streets as nodes, rather than as edges?
[1] Bin Jiang (2009) Ranking spaces for predicting human movement in an urban
environment, International Journal of Geographical Information Science, 23:7, 823-837, DOI:
10.1080/13658810802022822
PS: I have not found anything equivalent in the doc

Plot coastline and calculate distances (marmap and ggmap)

I am working on a research project in marine ecology, using R, and I would like to create a map of a small and precise part of the French Mediterranean coast. From this map I would like to add the different fish collection sites in order to calculate the distances between these sites, taking into account the topology of the coast (the sites being very close to the coast). I have used the marmap package to do this, however due to the size of the map I wish to create, the resolution is very poor and the map is unworkable.
data <- getNOAA.bathy(lon1 =2.97,lon2 =3.53,lat1 =41.9,lat2 =42.3,resolution = 1)
I would like to know if there is an alternative, such as using the ggmap package to get a map with a good resolution, then import the GPS points of the sites and calculate the distances between them using marmap ? Are the two packages compatible?
Do you have any other ideas?
I'd recommend using leaflet for mapping and geosphere to find the Haversine (as the crow flies` distance betwen points.

How to calculate distance from a certain point to a POI using OSM with R

I have Latitude and Longitude of a given point and I'd like to calculate the distance from this given point and some POIs (Point of Interest).
Moreover I'd like to use OSM (OpenStreetMap) and R.
Anyone can hel me?
Tnx
Have you looked into using the osmar project (http://osmar.r-forge.r-project.org/) for accessing POI data from OpenStreetMap? Here is a tutorial for using it - https://journal.r-project.org/archive/2013-1/eugster-schlesinger.pdf.
So, osmar will allow you to access POI data via an API and then you can use any standard R package for handling spatial data to get distances.

Convert lat/lon to zipcode / neighborhood name

I have a large collection of pictures with GPS locations, encoded as lat/lon coordinates, mostly in Los Angeles. I would like to convert these to (1) zipcodes, and (2) neighborhood names. Are there any free web services or databases to do so?
The best I can come up with so far is scrape the neighborhood polygons from the LA times page and try to find out in which polygon every coordinate is. However this might be quite a lot of work, and not all of my coordinates are in LA. As for the zipcodes, this 2004 database is the best I can find, however zipcodes are encoded as a single coordinates instead of a polygon. So the best I can do is find the minimum distance from a given coordinate to the given zipcode-coordinates, which is not optimal.
I was under the impression that google-maps or open-street-maps should be able to do this (as they seem to 'know' exactly where every neighboorhood and zipcode is), however I cannot find any API's to do the lookups / queries.
You can now do this directly within R itself thanks to the rather awesome ggmap package.
Like others mention, you'll be reverse geocoding using the google maps API (and therefore limited to 2,500 queries daily), but it's as simple as:
library("ggmap")
# generate a single example address
lonlat_sample <- as.numeric(geocode("the hollyood bowl"))
lonlat_sample # note the order is longitude, latitiude
res <- revgeocode(lonlat_sample, output="more")
# can then access zip and neighborhood where populated
res$postal_code
res$neighborhood
Use Reverse Geocoding to convert your lat/lon to addresses. It has some limit on the number of queries per day though.
Here is a nice blog post with examples how to geocode and reverse geocode using google-maps.
Try this one:
http://www.usnaviguide.com/zip.htm
There is some limit as to how many queries per day you can do on the site, but they also sell the complete database, which changes every few months.
Sorry that I don't know of any free resources.
As others suggested, geocode them into street address should work fine for zip code. i am not too sure about neighborhood, because you may have to look if street number is odd/even to see if it is located which side of a road that determines neighborhood.
An alternative way is to prepare GIS polygon feature (ESRI shape file for example), test each point against this set of polygons see which one it intersects.
zip code is very straighforward, you can download shape file from the census.
http://www.census.gov/cgi-bin/geo/shapefiles2010/main
neighborhood is harder, i'd guess. In another part of US i had to create my shape file on my own by combining definitions from municipal government, real-estate website, newspaper etc so that it looks like what people thinks neighborhood in the city are without having any overlap or gap. It can take some time to compose such set of polygons. you may crab census "block group", or even census "block" from the above page and merge them
Once you prepared polygon features, there are couple of GIS tools on different environment (stand-alone executable, GUI program, c/python/sql etc API, probably R as well, to do intersection of polygons and points.

quadrant sectioned map

I am unable to find any documentation on how to do what has been accomplished on the map in the page of the link below. Does anyone know how this was accomplished?
Link to interactive map
The technology is called quadtree and quadkey. It uses a z curve to reduce the dimension complexity. Each quadrant is a part of a bigger map. The entire map is made of 21^4 tiles. Each tile has it unique address. You can also look for a geohash or Nick's spatial index quadtree hilbert curve blog. I've written a hilbert curve quadkey script in php at phpclasses org (hilbert-curve). It uses a script to transform a lat/lng pair to WSG 84 datum and compute a quadkey. For example you can use it for a fast proximity lookup.

Resources