Overpass API : Loop through cities and find total length of road centerline per city - openstreetmap

I am trying to prepare a Overpass QL such a way that it iterate through a list of City Names and find sum of lengths of all the road centerline features which are falling inside the city administrative boundary.
The idea is not to download to entire data rather to get only required total road length per city wise.
New York City, New York, USA
Toronto, Ontario, Canada
Jersey city, New Jersey, USA
<City_Name>, <STATE/PROVINCE>,
Above is the example input and below is sample QL with BBOX but need to automate either with overpy python api or writing single overpass QL for entire list of cities.
[out:json][timeout:25];(way"highway"="primary";way"highway"="secondary";way"highway"="tertiary";way"highway"="unclassified";way"highway"="residential";);(._;>;);out;
Appreciate if someone can give pointers to move ahead.
-Prem

Related

OSM get all roads for a given US county as a shapefile

I am working on a project where I need to get a shapefile of all roads in a given US county from open streetmap data, add some information to the county roads, then merge the individual county road shape files into a larger single shapefile using qgis.
My current process is to download the state roads map from the OSM repsitory that has my desired counties, and clip the larger state map to my desired county set of roads using qgis. I use the census bureau's county boundary shapefile to determine the boundary of the clip. The problem is that qgis seems to delete small sections of roads at the county boundary and I am unable to merge the "fabric" of the map together because there are gaps in road lines at the county boundary.
As an alternative approach, I have stared to research using the OSM overpass api to query for a set of county roads. If I can query OSM for all roads within a given county and download as a shapefile, should I then be able to merge the individual county road maps into a larger map without gaps and avoid the problem I have with clipping?
Are there any articles that describe the overpass api query for getting roads within a known administrative boundary, like a US county?

Tableau - Given longitude and latitude how can I count how many points fall under a certain zip code for New York?

I'm trying to count how many subway stations each zip code in NYC has. I have the longitudes and latitudes of each station but am wondering how I can relate this to zip codes? Thank you for your help!
Subway Stations on default map
You'll need some spatial data source that contains the boundaries of each zip code, such as a ESRI shapefile, GeoJSON file, KML etc. Tableau's built-in geocoding can display zip code boundaries visually, but they are not accessible for computation (unless you find a way to hack the geocoding files that ship with Tableau)
It should not be hard to find a shapefile of zip code boundaries for NYC.
Once you have that use a spatial join with the INTERSECTS operator to combine the zip code boundary data with your subway station data. If your station data is not in a spatial format, you'll need to use the MAKEPOINT() function in Tableau to convert the latitude and longitude coordinates into a spatial geometry datatype that can be used to specify your join condition.
This sounds like more work that it really is. In the end, the INTERSECTS operator will do all the work to assign each station to the correct zip code.

Finding the next intersection on the current street by using OpenStreetMap

I'm new to OSM and would like to know if my approach for finding the next intersection ahead is possible when doing it offline.
The goal is to get the coordinates (latitude/longitude) of the next intersection on the street I'm currently driving on. For that I have my actual position (lat/lon coordinates) and heading (w.r.t. the north-pole) at disposition.
My current approach right now is to first use my coordinates for getting the name of the street/way/trace in which I am driving; then use that name for knowing which are the next intersections on that street (to both sides); and then use the heading for knowing which direction is the one I should pay attention to.
Once I have the intersection, I would get its coordinates and continue with the program.
My questions are then, is it possible to do all of that offline, i.e. with a .osm file (or similar)?
And, do you know a better approach for getting the coordinates of the next intersection ahead?
Thanks a lot in advance!
PS. I was able to get the name of the street by using nominatim and to get all the intersections of a street by using Overpass turbo, but this solutions would need internet; or is there a way of using them offline?

Facebook Audience API - Targeting Audiences using Shapefiles

I know it's possible to target ads geographically based on zip codes and/or the radius around a given coordinate. Is it somehow possible to target ads geographically based on a shapefile (census Canada for example) or do we have to essentially "build" the shapefile using a combination of zip codes and radius inclusions / exclusions?
It seems the only real "shapes" for a target audience is either providing a country, state (or province if in Canada), congressional district and some zipcodes:
Canada province:
Audience Details:
Location - Living In:
Canada: Alberta
Age:
18 - 65+
US Congressional District
Audience Details:
Location - Living In:
United States: Pennsylvania's 1st District (US:PA01)
Age:
18 - 65+
US Zipcode
Audience Details:
Location - Living In:
United States: Beverly Hills (90210) California
Age:
18 - 65+
However, some zipcodes map to a simple point so you need to fallback to a coordinate and radius.
I guess the only way to create an audience for a given polygon is to try and fill its surface with circles, considering those circles have a minimum radius, so it will always be just an approximation.
There are examples of circle-packing around. I repaired an old gist (https://gist.github.com/shashashasha/1020117) to make you a plunkr example.
See this plunker
However, circle packing considers that circles shouldn't overlap each other, so you'll have to figure out another way to achieve the same.

Getting cross streets from a geocoded address

Let's say I have a lot of JSON data relating to intersections and their geolocations.
I have an app where the user uses his or her current location, and I want to be able to figure out what block they're on (i.e. the street they're on, and between what two cross streets). What's the best way to do this? Is there a good way?
Example: I get the user's geolocation, reverse-geocode it into 435 W. 42nd st. Using that data, I want to know that the user is between 9th ave and 10th ave on 42nd st.
Any help is much appreciated!
You'll need to have the geolocations of each of the intersections, blocks or whatever you want to relate the user position to. Once you have that information, you can easily find the nearest intersections to the user's current geolocation.
If all of the geolocation information is in your JSON data, then work only in geolocations (don't reverse geocode) until you've determine the nearest intersections, etc.
You'll likely do best to convert your JSON data to a database so you can query more easily.