[Qgis-user] Road Labels

Mike Flannigan mikeflan at att.net
Thu Oct 22 05:08:04 PDT 2020


Thanks for this procedure Thayer.
I use Overpass Turbo to plot tracks along roads.  It is somewhat
of a complicated process, but it works.  Perhaps I should be
using QGIS to do this instead.

But since I currently reply on the Overpass Turbo website, I am
looking for an alternate website that does the same thing.  I want
to prepare for the day when Overpass Turbo disappears (or moves).

So this email is a 2 part question.

1) Are there any other websites that do what the Overpass Turbo website 
does?

2) Do you have any suggestions on a better way to get a track plot along
roads, when you feed the program just a few vertexes along the road route?

My convoluted procedure to get tracks along roads is shown below.


Mike



THE New Procedure for Tracks is:

Create a text file with DD lat/longs that looks like this:
38.891953, -94.714428
39.961945, -95.788242
42.263043, -96.481528
42.874940, -97.140297
43.095141, -98.332987

This is generally created from taking each point from Google Maps.


Then run googmaptrack.pl to create a google maps URL like this:
https://www.google.com/maps/dir/38.891953,-94.714428/39.961945,-95.788242/42.263043,-96.481528/42.874940,-97.140297/43.095141,-98.332987


Paste that URL into a browser and make sure it is the correct route.
If not, add more intermediary points to correct the route.


Then run trackosrm.pl to create a bunch of terminal commands that
curl an OSRM URL like this:
curl 
'http://router.project-osrm.org/route/v1/driving/-104.062500,46.498392;-94.714428,38.891953?alternatives=false&annotations=nodes' 
 >/home/mike/Documents/copy5/procout01.txt

Paste the whole string of terminal commands into a terminal to create
all the procoutXX.txt files.


Then use trackosrm2.pl to process those procoutXX.txt files
to extract all of the node numbers to nodes.txt.  It will
create an output that looks like this:

[out:json];
(
   node(77927832);
   node(77927830);
   node(77927828);
   node(77927826);
);
(._;>;);
out;

YOU NEED TO ADD THOSE FIRST 2 LINES AND LAST 3 LINES.


Then paste all those nodes and to this website:
http://overpass-turbo.eu/

Hit the Run button at the upper left.

Then hit the "Data" tab at the upper right and copy and paste the data 
supplied
into a file like latlong.txt.

Use garminfile.pl to extract the lat/longs to TopoUSA format.


Unfortunately, curl does not keep the items in order.  So we need
to change the trackosrm.pl 'out' file above that looks like this:
curl 
'http://router.project-osrm.org/route/v1/driving/-118.799440,37.663330;-118.592720,37.671850?alternatives=false&annotations=nodes' 
 >/home/mike/Documents/copy5/procout01.txt
curl 
'http://router.project-osrm.org/route/v1/driving/-118.592720,37.671850;-116.855740,38.125510?alternatives=false&annotations=nodes' 
 >/home/mike/Documents/copy5/procout02.txt

and change it to this:

firefox 
'http://router.project-osrm.org/route/v1/driving/-118.799440,37.663330;-118.592720,37.671850?alternatives=false&annotations=nodes'
firefox 
'http://router.project-osrm.org/route/v1/driving/-118.592720,37.671850;-116.855740,38.125510?alternatives=false&annotations=nodes'

by using this:
find /home/mike/Documents/copy3 -maxdepth 1 -type f -iname 
"track2_out.txt" -exec grep -il -Z "driving" {} \; | xargs -0 perl 
-i.bak -pnwe 's/curl\s(.*) >.*/firefox $1/g'


Then copy each firefox command into the terminal and copy the web page 
output
into an 'order.txt' file, remove the beginning and ending lines, so we only
have the node lines.  Then do a search and replace - search for 
"^\d+\s+" and
replace with nothing.

So order.txt has nothing but node numbers (in order) in it.

Then use trackorder.pl to reorder all the procout.txt files created above.


Then use trackreduce.pl to reduce the number of points with the Douglas 
- Peucker algorithm.


Then use geojson.pl to create a geojson file to use in QGIS to see what 
the track looks like.




On 10/20/20 5:37 PM, qgis-user-request at lists.osgeo.org wrote:
>   Hi Wanda,
> There are ways of filtering Open Street Map data before you download it, so the processing is done on the server not on your computer, so that should help you avoid crashes in QGIS.
> One way to do this is with Overpass Turbo (https://overpass-turbo.eu) to select all of the roads in the map view.
> Overpass Turbo
> 0) Close applications that you do not need, and open a web browser.1) Go to the Overpass Turbo website and use the search and zoom controls to adjust the map to your area of interest. 2) Then copy and paste the sample query into the text area to the left side of the map window. 3) Then click on the "Run" button at the top left.4) After it runs for a while it will probably say "Large Amounts of Data"  and ask you if you want to continue, click "continue anyway".     Rockford indeed is small and does not have this problem, but Grand Rapids for example gives 30 MB of data, 60 MB may cause an error.5) Click on Export (third button from the left at the top). 6) Then on the top line of the dialog click "download" from "download/copy as GeoJSON"7) Name the file and download it to somewhere that you will be able to find again (the default is export.geojson).8) Click "done"9) Close the web browser
> QGIS
> 10) In QGIS open the Data Source Manager and click on Vector (at the top click Layer then choose Data Source Manager from the menu)  a) Under Source click on the three dots to the right of Vector Datasets   b) browse to the export.geojson file and click Open.  c) at the bottom right of the Data Source Manager-Vector window click on "Add"  11) This will bring up a dialog asking you which of the geometry layers to add.  a) click on the one that says LineString at the right side under Geometry type. Then click OK.12) After a few seconds you should see the "export" layer appear in the Layers list and see the roads show up in the map.  a) close the Data Source Manager window.
> Geojson layers are very slow in QGIS, so you should convert them to another format like ESRI Shapefile.
> 13) In the Layers panel right click on the "export" layer (the one with the line on the left side)  a) from the menu hover over Export then click on Save Features As14) At the top of the "Save Vector Layer As..." dialog:   a) change the format to "ESRI Shapefile"  b) click on the three dots to the right of File Name    i) name your file (e.g. grand_rapids.shp), choose a folder where to save it, and click "Save"  c) at the bottom click OK.  d) the grand_rapids layer will be added to the Layers panel, and the color of the roads on the map should change.15) Right click on the "export" layer.  a) click Remove Layer    i) click OK when asked: "Remove 1 Legend Entries?"16) Save the project.
> Label the roads.
> 17) Double click on the "grand_rapids" layer in the Layers panel.18) At the left of the Layer Properties window click on Labels  a) at the top change No Labels to Single Labels    i) just below Single Lables set the Value to "name"    ii) at the bottom right click OK
> Now when you zoom in and out the labels will appear on the roads.
> -Thayer




More information about the Qgis-user mailing list