An API to get a given city's area size? - rest

I would like to find an API that would return a city's area in square feet, square miles, square meters or any area unit given only the city name.
For example, I query "san francisco" and I get something back like "231.89 sq mi or 600.6 km2".
I need this data for US and Canadian cities for now but it would be nice to have an API that covers any city in the world.
I'd rather avoid scraping wikipedia or any other website and use a proper API if at all possible.

You can use DBpedia to get this information. An example of a SPARQL query to get this information would be:
select ?area where { dbr:San_Francisco dbo:areaTotal ?area }

Related

How to filter house numbers of a city in OSM map

Does anyone have any documentation or know how to get all the house numbers of a city available on OpenStreetMap or Nominatim?
I've searched some documentation but it doesn't seem to work.
Or anyone have api documentation that can do it please help me.
Thanks,
There's no direct API for this that would just spit out all the addresses, or even just all the house numbers, for a specific city, at least not that I'd know off.
If you can import an OSM planet extract containing your city of choice into an osm2pgsql database it would be easy to run:
SELECT DISTINCT "addr:housenumber"
FROM planet_osm_point
WHERE "addr:city=..."
UNION
SELECT DISTINCT "addr:housenumber"
FROM planet_osm_polygon
WHERE "addr:city=..."
Overpass API could also be used, esp. with the OverPass Turbo frontend it can be given queries like "addr:housenumber=* in City_name", but by default it will return full object data and not just a single field like house number.
Raw Overpass API queries can probably do just that, but I'm not that deep into its query syntax. Maybe the examples can give you a hint towards what may work.
But the Overpass API query language is not necessarily for those faint at heart ... :O

Refence for Location Polygon names in OSMnx/OSM API

Looking through the OSMnx and OSM API documentation I haven't been able to find a reference for how to specify world place names.
The OSMnx examples use US locations, where the City, County, State, Country structure is used, but this structure doesn't apply to other countries of course.
Specifically, how should I structure this query to specify the boundary of London for instance? Or are there docs I haven't found for this yet?
G = ox.graph_from_place('London', network_type='drive')
# project the network to UTM (zone calculated automatically) then plot it
G_projected = ox.project_graph(G)
fig, ax = ox.plot_graph(G_projected)
Thanks!
This thread provides more detail about how to narrow your query. Long story short, use OSMnx's which_result argument and pass your place query as an explicit dict rather than a string to improve geocoder specificity.

Get list of all important sub-location in a city by city name

I tried to google place API to get a list of all important sub-location within a city but it's not showing the complete list.It gives the result on the basis of some search like restaurant and all.
Is there any API to get a list of all sub-location within the city on the basis of city name?
try something as mentioned below:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=28.7041,77.1025&radius=50000&key=YOUR_API_KEY.
The link of format:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=[LATITUDE AND LONGITUDE OF CITY]&radius=50000[I have specified 50KM which is largest google api allows]&key=YOUR_API_KEY.
Do not specify the type.
radius: you get the approx size of city to restrict the value for radius.

Getting Streets of a specific postcode using Open Street Maps

I want to write a code that has the Countrycode and Postcode as an input and the ouput are the streets that are in the given postcode using some apis that use GSM.
My tactic is as follows:
I need to get the relation Id of the district. For Example 1991416 is the relation id for the third district in Vienna - Austria. It's provided by the nominatim api: http://nominatim.openstreetmap.org/details.php?place_id=158947085
Put the id in this api url: http://polygons.openstreetmap.fr/get_wkt.py?id=1991416&params=0
After downloading the polygon I can put the gathered polygon in this query on the overpass api
(
way
(poly: "polygone data")
["highway"~"^(primary|secondary|tertiary|residential)$"]
["name"];
);
out geom;
And this gives me the streets of the searched district. My two problems with this solution are
1. that it takes quite a time, because asking three different APIs per request isn't that easy on ressources and
2. I don't know how to gather the relation Id from step one automatically. When I enter a Nominatim query like http:// nominatim.openstreetmap.org/search?format=json&country=austria&postalcode=1030 I just get various point in the district, but not the relation id of the searched district in order to get the desired polygone.
So my questions are if someone can tell my how I can get the relation_Id in order to do the mentioned workflow or if there is another, maybe better way to work this issue out.
Thank you for your help!
Best Regards
Daniel
You can simplify your approach quite a bit, down to a single Overpass API call, assuming you define some relevant tags to match the relation in question. In particular, you don't have to resort to using poly at all, i.e. there's no need to convert a relation to a list of lat/lon pairs. Nowadays the concept of an area can be used instead to query for certain objects in a polygon defined by a way or relation. Please check out the documentation for more details on areas.
To get the matching area for relation 1991416, I have used postal_code=1030 and boundary=administrative as filter criteria. Using that area you can then search for ways in this specific polygon:
//uncomment the following line, if you need csv output
//[out:csv(::id, ::type, name)];
//adjust area to your needs, filter critera are the same as for relations
area[postal_code=1030][boundary=administrative]->.a;
// Alternative: {{geocodeArea:name}} -> see
// http://wiki.openstreetmap.org/wiki/Overpass_turbo/Extended_Overpass_Queries
way(area.a)["highway"~"^(primary|secondary|tertiary|residential)$"]["name"];
(._;>;);out meta;
// just for checking if we're looking at the right area
rel(pivot.a);out geom;
Try it on overpass turbo link: http://overpass-turbo.eu/s/6uN
Note: not all ways/relations have a corresponding area, i.e. some area generation rules apply (see wiki page above). For your particular use case you should be ok, however.

Associate facebook user check-ins to list of cities based on latitude and longitude

I am studying the development of an application that would show a user which cities in the world their friends have traveled to. To do this, I was thinking of getting a list of check-ins for each of the user's friends and mapping those check-ins to my list of cities based on each check-in latitude and longitude.
This looks like the only way to achieve this since the Facebook graph API doesn't return a city locationId that I could use to map the check-in city to my own city list.
I have absolutely no idea how to perform this mapping from a check-in lat/long to the lat/long I have stored for each city in my city table.
Could anyone point me in the right direction or toward a tutorial explaining how this can be done?
I only have a single pair of lat/long coordinates, so I suppose I would need to define for each city a range of latitudes and longitudes around the city center lat/long that would qualify a check-in for being deemed to take place in any given city, and then do a SQL query against my city table to find which city any given check-in finds itself in?
Or is there another / better way of doing this?
Thanks in advance for any tip and suggestion.
Lothaire
You can use the search API https://developers.facebook.com/docs/reference/api/#searching to search for places around a specific lat/long location.
For example, caffes in San Francisco: https://graph.facebook.com/search?q=coffee&type=place&center=37.76,-122.427&distance=1000
Similarly, you could search for places around your coordinates and look at places type to filter out cities. You would do that by calling https://graph.facebook.com/PLACE_ID and looking at the details. For example, in the search example above, Philz Coffee (first result) - https://graph.facebook.com/151116474914629 - gives you "category": "Local business".
It's not ideal if you're aiming for cities, as check-ins are focused around places people go in the cities (you'd actually have more results of your friends checking into places probably, than them checking in to cities).