Overpass: Busstops of Busroutes - openstreetmap

I'm pretty new to the OSM Overpass-Turbo-Coding. Started 3 hours ago, to be exactly. I'm looking for a code to extract all the buslines in a certain area including the busstops and put all that into a nice csv-file.
I experimented quite a bit and I have the feeling, that I'm very close. So I already managed to create lists with all the busroutes, a list with all the bus stops. What I did not managed to do was to export into the csv file the data of recursive operations - so id, name, ref of the route AND id, name of the subsequent bus stops of the same line (in the correct order).
Ideally, I'm thinking about a table like
Busline(=ref of relation) Direction(=name of relation) StopID (id of node) StopName(name of node)
Line 1 north 123456 MainRd
Line 1 north 123457 Evergreen Terrace
Line 1 north 123458 Hospital
Line 1 north 123459 Dontknowwhere
......
.
//[out:csv(::id, ::type, name, ref, role, members)];
// gather results
(
// query part for: “Buslinie”
relation["type"="route"]["route"="bus"]({{bbox}});
node(r)["public_transport"="stop_position"];
);
// print results
out body;
//>;
//out;
//out skel qt;

Related

Postgresql: Querying on a list of pairs where one field is a fuzzy match and another exact

I want to query multiple addresses based on the street name and city. The street name is a fuzzy match whereas city is an exact. If we are querying a single record, the following works:
SELECT
*
FROM
Addresses a
WHERE
a.street like '32 foxrun%' --could be foxrun st or foxrun street
AND
a.city = 'Montreal'
Problem
I would like to run the above query on thousands of street name/city pairs. I know I can use
LIKE ANY('{32 foxrun%, 45 main%}')
to match the street names, but since there are likely quite a few main streets, it helps to add the additional address component, city. Furthermore, I know I could break up the WHERE clause into an OR for each city, like so:
WHERE
(a.street LIKE ANY('{32 foxrun%, 45 main%}') and a.city = 'Montreal')
OR
(a.street LIKE ANY('{74 broad%, 2 kings%}') and a.city = 'Los Angeles')
But since the number of cities can be in the thousands, I was hoping there was a more effective solution.
Thank you!
You can use a join against a values clause:
select a.*
from addresses a
join (
values
('32 foxrun%', 'Montreal'),
('42 answer%', 'London'),
.... more parameters ...
) as t(street, city) on a.city = t.city and a.street like t.street;

Grouping and Sorting by Odd and Even Numbers

I am trying to create a report which has addresses in form of house Nbr and street Name. I want to group all address by street name and then order them by house nbr which is a string but should sort like a number. Ideally i would like the odd ascending and then the evens descending so that my list would look like
1,3,5,7,9 .... 8,6,4,2
How would i go about this ? I created first group on street name and then 2nd group on house number with a formula for sorting of nbrs
i created a Formula Field OddEven with
ToNumber({tbl_FarmMaster.sano}) MOD 2
but i am having hard time applying that to my group
Create two formulas like below. Let's call them oddFirst and negativeEven.
oddFirst formula:
ToNumber({tbl_FarmMaster.sano}) MOD 2 == 1 then
1 //it is odd
else
2 //it is even
negativeEven formula:
if ToNumber({tbl_FarmMaster.sano}) MOD 2 == 1 then
ToNumber({tbl_FarmMaster.sano}) //it is odd
else
-ToNumber({tbl_FarmMaster.sano}) //it is even, note the negative sign
Then create two groups to sort:
first by the formula oddFirst
second by the formula negativeEven
Show the {tbl_FarmMaster.sano} field.

Lat-Long of exits on a Freeway e.g US 101 say arranged in N-S direction

I am trying to find all exits on US 101 exits, preferably in the order North to South using the OpenGIS osm2pgsql. But no luck so far.
Closes solution I found is:
http://stackoverflow.com/questions/1960005/how-to-get-lattitude-and-longitude-of-us-interstate-exits-programmatically comes close with the SQL:
select osm_id, name, ref from planet_osm_roads where highway='motorway_link';
The query:
select osm_id, name, ref from planet_osm_roads where highway='motorway';
Returns a lot more nodes with ref but I dont think those are freeway exits (whats special about the points noted on the freeway where highway="motorway"?
However most of the exits have null name and ref so while I have exit lat-longs its not clear which freeway these exits are on and nor are they ordered say North to South..
Please help.
In OSM data motorway exit is tagged with highway=motorway_junction, and it's type of point, so:
select *
from planet_osm_point
where highway = 'motorway_junction'
and ref = '101'
order by ST_Y(way) desc
If there is a problem with empty ref on this points you can also check if there is some motorway with specified ref (of course it's not a 100% method but better than no method)
select *
from planet_osm_point p
where highway = 'motorway_junction'
and exists (
select 1
from planet_osm_lines l
where st_DWithin(l.way::geography, p.way::geography, 100)
and highway = 'motorway'
and ref = '101')
order by ST_Y(way) desc
You can run an Overpass query that gives you all ways tagged as highway=motorway_link that are connected to ways tagged [ref="US 101"]:
[timeout:60][bbox:19.56,-132.63,51.62,-56.60];
way[highway][ref="US 101"];
node(w);
way(bn)[highway=motorway_link];
out center;
You can then export the data as GeoJSON.

Talend - Combining two rows into one

Sample Input
Here is an example of my input. As you can see, the address column has 2 values which I would like to separate and then combine into one value.
Expected Output
This is what the output should be, Combined values into one cell.
Talend Output
If I read the data into Talend it looks like this:
You should be able to accomplish this by using the tMemorizeRows component in Talend.
A really rough example job might look like:
I'm using a tFixedFlowInput to hardcode some data here rather than reading in an Excel Sheet but it should match what you've provided as an example in the question:
The tMemorizeRows component keeps a specified amount of rows in memory at all times rather than processing things row by row in a flow as normal (although some components will require the entire data set to be in memory such as with a sort). This can then be accessed as an array. You just want to set this to memorise all of the columns and you only need 2 rows in memory at all times:
In this case you need to pull all of the data from the previous row into the next row when you have an empty name so we can access the data held by the tMemorizeRows component using a tJavaRow using the following example code (quickly hacked together):
String name = "";
String address = input_row.address;
String mailingAddress = input_row.mailing_address;
if ("".equals(input_row.name)) {
name = name_tMemorizeRows_1[1];
address = address_tMemorizeRows_1[1] + " " + input_row.address;
mailingAddress = mailing_address_tMemorizeRows_1[1] + " " + input_row.mailing_address;
} else {
name = "DELETE THIS ROW";
address = input_row.address;
mailingAddress = input_row.mailing_address;
}
output_row.name = name;
output_row.address = address;
output_row.mailing_address = mailingAddress;
Notice how I've set the name for the non empty name rows to "DELETE THIS ROW". I can then use a tFilterRow to remove this row from the flow so we are left with only the output we want:
Leaving us with the following output:
.-----------+---------------------------+---------------------.
| Output |
|=----------+---------------------------+--------------------=|
|name |address |mailing_address |
|=----------+---------------------------+--------------------=|
|John Carter|Washington Street USA 12345|PO Box 999 USA 12345 |
|Linda Green|London Road UK E20 2ST |PO Box 998 UK E20 2ST|
'-----------+---------------------------+---------------------'

SQL Server 2008 R2 Spatial Queries

I am very new to the spatial realm of SQL Server and need some help. I have a waypoint organizing app and I am trying to generate some queries that follow along the premise of finding waypoints that are part of geographic polygons like lakes, rivers, etc. I have preloaded my tables with data I have downloaded. I used shape2sql.exe to load shapefiles into the appropriate db tables.
Tables are as follows:
Water table - id, name, geog(geography data type)
State table - id, state_name, state_abbr, geog(geography data type)
County table - id, name, state_name, geog(geography data type)
Waypoint table - id, name, lat, lon, waterid
How do I write queries against these tables to return things like:
- all waypoints in 'michigan'
- all waypoints on 'bass lake' in 'montcalm' county in 'michigan' (there are multiple bass lakes in michigan and the country hence the county/state part)
- auto assign the water id column of the waypoint table by "processing" a group of waypoints and finding what lake they actually belong to
- etc.
Thanks!
Learned so far:
select geog.ToString() as Points, geog.STArea() as Area, geog.STLength() as Length
from water
where name like '%bass lake%' and STATE = 'mi'
will return the record for Bass Lake and the polygon with the actual coordinates for the lake.
POLYGON ((-87.670498549804691 46.304831340698243, -87.670543549804691 46.307117340698241, -87.676573549804687 46.313480340698241, -87.68120854980468 46.314821340698245, -87.685168549804686 46.315703340698242, -87.6877605498047 46.313390340698241, -87.685051549804683 46.308827340698244, -87.682360549804685 46.305650340698243, -87.677734549804683 46.304768340698246, -87.674440549804686 46.304336340698242, -87.670498549804691 46.304831340698243)) 1022083.96662664 4027.52433709888
Shooting from the hip, here, but maybe like this:
UPDATE waypoints
SET waypoints.WaterId = water.Id
FROM dbo.Waypoints AS waypoints LEFT JOIN
dbo.Water AS water ON geography::Point(waypoints.Lat, waypoints.Lon, 4326).STIntersects(water.geog)
Should set the waterId on the wapoints table to one of the matching water ids, from the water table.
This should get you all the waypoints on BASS LAKE
SELECT waypoints.*
FROM dbo.Waypoints as waypoints INNER JOIN
dbo.Water AS water ON geography::Point(waypoints.Lat, waypoints.Lon, 4326).STIntersects(water.geog) = 1
WHERE water.Name = 'BASS_LAKE' -- OR WHATEVER
Ok - learning as I go so here are some answers to my own questions for anyone what would like to know.
Here is one query for finding various waypoints with conditions in the where clause:
SELECT * FROM WaypointTable wp
JOIN WaterTable w
ON wp.geogcolumn.STIntersects(w.geogcolumn) = 1
WHERE w.name LIKE '%bass lake%'
AND w.state = 'mi';
Here is a query for assigning water id's to waypoints based on where they 'fit':
UPDATE WaypointTable wp
SET WaterID = (
SELECT ID
FROM WaterTable
WHERE geogcolumns.STIntersects(wp.geogcolumn) = 1
);
Both of these queries work extremely well and fast! Love it!