I want to retrieve all airports around a city (g.e. Leipzig) within a radius of 50km.
I tried this
[out:csv(::type,name, 'name', ::id; true; ";")];
(
relation["iata"~".*"](around: 50000, 51.3124404, 12.4131075);
node["iata"~".*"](around: 50000, 51.3124404, 12.4131075);
way["iata"~".*"](around: 50000, 51.3124404, 12.4131075);
);
out;
returns
#type;name;name;#id
way;Flughafen Leipzig/Halle;Flughafen Leipzig/Halle;435715317
relation;Leipzig-Altenburg Airport;Leipzig-Altenburg Airport;6116338
But I want to use the osm-id directly.
When I search within Leipzig (admin_level = 8) and a radius
[out:csv(::type,name, 'name', ::id; true; ";")];
area(3600062649) -> .leipzig;
way(around.leipzig:50000)[iata~".*"]({{bbox}});
out;
I retrieve an empty result set
When I search within saxony (admin_level = 4)
area(3600062467) -> .sachsen;
way(area.sachsen)[iata~".*"]({{bbox}});
out;
then I retrieve
#type;name;name;#id
way;Flughafen Leipzig/Halle;Flughafen Leipzig/Halle;435715317
I want to retrieve the same result like I use the lat/lon-information.
Edit:
I get the expected result by retriving the center-lat/lon of a relation (given by an osm-id) and use this lat/lon-information to retrieve all airports within a given radius.
Now I want to skip the step "retrieve center-lat/lon". I want to use the osm-id of a relation and a given radius directly to retrieve all airports within a given radius.
#mmd: I hope it's more understandable.
Related
I'm trying to query data from the OSM Overpass API. Specifically I'm trying to determine the count of amenities of a given type around a point (using the 'around' syntax). When running this for many locations (lat, lons) I'm running into a TooManyRequests error.
I have tried to work around by setting sleep time pauses and playing with the timeout header and retry time, but I'm running into the same issue. I'm trying to find a way to adapt the query so that it just returns the count of amenities (of specified type) around each point, rather than the full json of nodes which is more data intensive. My current script is as follows;
# Running Overpass query for each point
results = {}
for n in range(0, 200):
name = df.loc[n]['city']
state = df.loc[n]['state_name']
rad = df.loc[n]['radius_m']
lat = df.loc[n]['lat']
lon = df.loc[n]['lng']
# Overpass query for amenities
start_time = time.time()
api = overpy.Overpass(max_retry_count=None, retry_timeout=2)
r = api.query(f"""
[out:json][timeout:180];
(node["amenity"="charging_station"](around:{rad}, {lat}, {lon});
);
out;
""")
print("query time for "+str(name)+", number "+str(n)+" = "+str(time.time() - start_time))
results[name] = len(r.nodes)
time.sleep(2)
Any help is much appreciated from other Overpass users!
Thanks
In general, you can run out count; to return a count from an overpass API query.
It's hard to say without knowing how your data is specifically structured, but you might have better luck using area to look at specific cities, or regions.
Here is an example that returns the count of all nodes tagged as charging station in Portland, Oregon:
/* charging stations in portland */
area[name="Oregon"]->.state;
area[name="Portland"]->.city;
(
node["amenity"="charging_station"](area.state)(area.city);
);
out count;
I am using Flask-SQLAlchemy with Postgres, Postgis and GEOAlchemy. I am able to sort entries in a table according to a point submitted by the user. I wonder how I could also return the calculated distance...
This is how I sort the items:
result = Event.query.order_by(func.ST_Distance(Event.address_gps, coordinates_point)).paginate(page, 10).items
for result in results:
result_dict = result.to_dict()
return result_dict
according to the users position (coordinates_point). I would like to add an entry in each result in the result_dict which also contains the distance that the item was ordered by. How do I do that? What does func.ST_Distance return?
I tried to add this in the for loop above:
current_distance = func.ST_Distance(Event.address_gps, coordinates_point)
result_dict['distance'] = current_distance
But that did not seem to work.
You can use column labels
query = Event.query.with_entities(Event, func.ST_Distance(Event.address_gps, coordinates_point).label('distance')).order_by('distance')
results = query.paginate(page, 10).items
for result in results:
event = result.Event
distance = result.distance
result_dict = event.to_dict()
result_dict['distance'] = distance
I have a list of Companies with a ROIC measure. Each Company belongs to a Segment.
I created a parameter to select a Company: [SelectedCompany], and I want to create a SET which includes all the companies except the [SelectedCompany], which are in the same [Segment] as [SelectedCompany].
My set is currently defined by this formula:
[Company] != [SelectedCompany]
I should add something like:
[Company] != [SelectedCompany]
AND
[Segment] = [SelectedCompany].[Segment]
But I don't know how to access the [Segment] attribute of the [SelectedCompany].
Just for clarification, I'm making this because I want to compare the [SelectedCompany] ROIC against the average ROIC of the other Companies in the same Segment.
I would appreciate any help on this.
Thanks a lot!
Here's a bit of a hacky way to get what you're looking for. Keep your original definition for the set:
[Company] != [SelectedCompany]
Create a calculated field:
{ FIXED [Segment] : MAX( IIF([Company] = [Parameters].[SelectedCompany], 1, 0) ) }
Then drag that field into the Filters card and filter to allow only 1's. This will filter out all Segments except for the selected company's Segment.
I have created a structure about patient. Its fields are name, age, etc. I want to be able to retrieve a patient's all info by entering its name or any other unique property. In other words, how can I find the patient's index? Thanks in advance.
patient(10).name = 'Chuck';
patient(10).age = 29;
patient(11).name = 'Sarah';
patient(11).name = 28;
Structures are not a good data type for doing what you want.
I suggest using a table. If you have your data in the structure already, call
patientTable = struct2table(patient);
Then, you get the index as:
chucksIndex = find( strcmp( patientTable.name, 'Chuck'))
And you get that patient's information as
patientTable(chucksIndex,:)
(note: if all you need the index for is lookup, you don't need to call find, the logical index from strcmp suffices).
Double-clicking the table in the workspace browser presents the data in an Excel-like fashion. The only thing you'll have to change in your code is accessing the data. Instead of
patient(10).name
patient(10).age
You write
patientTable.name{10}
patientTable.age(10)
If you do not want to use a table, you can get the index as:
chucksIndex = find(strcmp({patient.name},'Chuck'));
First, there is an error, it should be patient(11).name = 28;.
Here is a way this should work. I've started the indexes for Chuck and Sarah at 1.
patient(1).name = 'Chuck';
patient(1).age = 29;
patient(2).name = 'Sarah';
patient(2).age = 28;
% Assign to cell array
plist = {patient.name};
% Choose the name of a patient
choose_patient = 'Sarah';
% Find the chosen patient in the list
ix_patient = find(strcmp(plist, choose_patient))
% Get full entry for that patient
patient(ix_patient)
Using MongoDB I'm querying homes that are within 25 miles of a lat/long.
My first attempt to do this used the near command, like so:
var near = Query.Near("Coordinates", coordinates.Latitude, coordinates.Longitude, find.GetRadiansAway(), false);
var query = Collection().Find(near);
var listings = query.ToList();
The issue with near is that it only returns 100 listings, whereas I want to return all listings within 25 miles of the coordinates.
My next attempt was to use within:
var within = Query.WithinCircle("Coordinates", coordinates.Latitude, coordinates.Longitude, find.GetRadiansAway(), false);
var query = Collection().Find(within);
var listings = query.ToList();
Within returns all listings within 25 miles, which is great, however it doesn't sort them by how close they are to the center coordinates like near does.
So my question is, how do I get the best of both worlds? How do I get all listings within 25 miles AND have them sorted by proximity to the center coordinates?
Geospatial $near queries set a default limit() of 100 results. You should be able to get more results by setting a new limit().
While "near" queries are sorted by distance, "within" is not (although "within" doesn't have a default limit).