QGIS: How to find the shortest distance between two line layers - qgis

I am working with two layers in QGIS, which are both line layers. Essentially, I would like to add an attribute in one layer indicating the shortest distance to a feature in the other layer, as well as that other feature's ID. Is there a tool to do this without converting one of the two layers to points first? Or some relatively simple python process?
For example, I have a river segments layer and a road segments layer. I would like to add the distance to the nearest road & the name of that road to the river layer.

Related

QGIS - Create a shape layer polygon within the empty space of other shapes

I've got a few shape-layers with some polygons which all join up. I want to create a new shape which is the the hole in the middle of the other layers.
I've tried 'snapping', but it seems to lock to vertex and requires a lot of manual accuracy. Ideally i'd like to select the lines where they join and then 'fill in' the area. Though I don't know how to do this in QGIS.
You could use an algorithmic approach like the following (it assumes a situation as the one in the question, so no other holes and polygons are from different layers):
Merge vector layers to combine your different layers into one layer
Dissolve to combine all your features into one feature with one hole
Delete holes to get a layer with hole in the middle filled
Symmetrical Difference of output of 3. and 2. to get a layer where overlapping areas are removed i.e. only the hole should remain as a new layer

Hide polygons that are within a specific area

I'm trying to create an experience where I have a couple of detailed 3D models of buildings on the map with extruded building footprints of neighboring buildings via a vector tile source. The 3D models would be the main focus point and the extruded footprints would be for reference. One challenge I'm running into is that I have a global building footprint layer and it has a footprint for the 3D buildings which doesn't match up perfectly. Additionally, when extruded, it ends up merging/overlapping the nice 3D models.
I'd like to be able to hide the individual footprints that overlap the 3D models. My original thought was to grab the bounding box of the 3D model and then use the new within style expression, but it looks like this will only filter points and lines, not polygons. The building footprint polygons have no unique information in them that I could use to filter on.
I know I could monitor map movements and query the rendered features and manually detect intersecting polygons, but since there is no unique property on the footprint, I can't filter or use feature state.
Any ideas of how to efficiently avoid rendering individual polygons in a specific area that come in from a vector tile source?
It is a common issue that the buildings layer in Mapbox Streets don't contain any unique attributes to allow filtering or rendering differently.
The best solution is usually to source a different buildings layer, and in this case, remove those redundant buildings in pre-processing.
I can think of one rather crazy workaround that might work here, although the performance may be poor.
Add the building layer with very low opacity, of type fill, essentially invisible. (Maybe invisible would work.) Call your main source buildings`.
Create a secondary building source of type geojson, and a secondary fill-extrusion layer. Call this source buildings-copy.
On map move or moveend, use querySourceFeatures to obtain a copy of all buildings.
Process this copy using Turf to remove the buildings you don't want, and call setData to set the copy as the data for buildings-copy.
You may need to do some clever caching to get reasonable performance.

Hiding features on the layer based on other layer's data

I am using mapbox-gl and have point and line layers on the map. All layers are vector tiles. Some points lie on the lines, some not and I want to hide points that don't lie on the lines
Is it possible to do it only on the frontend side with writing something like a filter that checks if a point on any line or not? I really don't want to change the backend
Why don't you use turf.js in conjunction with mapbox-gl-js?
E.g. you could calculate the distance to the line with http://turfjs.org/docs/#pointToLineDistance for each point, then filter out any points with a distance bigger than 0.

Visualising road segments as heatmap in Leaflet efficiently

I have data consisting of parts of road segments of a city, with different number of visits. I want to plot the data on a Map and visualise it in the form of a heatmap.
I have two related questions:
I have the data from Open Street Maps (OSM) in the form of pairs of node ID's, where node ID correspond to the unique ID being assigned to a point by OSM. I also have a mapping for each node Id to its corresponding coordinates. Is there any Leaflet or Mapbox utility or plugin, which can plot a trip / highlight the road segment using 2 node ID's. I can always do it manually (by using the coordinate mapping and converting it into GeoJSON), but the problem occurs with the line width -- I have to make it exactly overlap with the width of the road, so that it seems that I am highlighting a road segment.
Is there any plugin / utility for Leaflet or Mapbox, which can be used for plotting polylines or geojson as heatmap efficiently? My current approach is calculating the color for each polyline and encoding that as a geojson property. But the problem is that with the increase in the number of lines (> 1K) the rendering becomes a pain and the method is not feasible. There are some plugins for Leaflet out there for plotting heatmap, but all of them are for points only and not lines. Any approach using WebGL would be really great.
An approach which I thought of could be converting my data into a shape file, upload to Mapbox Studio and use as a layer directly. But I have no idea how to go about doing that i.e. creating a shapes file, encoding the information in such a way that the complete road segment gets highlighted in the correct color.

Distance between two points with MapKit WITHOUT euclidean distance calculation

I have a game map that has been tiled over the world map of MapKit. I generate a path to take for the player. With this I find the 3 nearest nodes (in game cities) and select one at random then recurs this to find a 3rd node. I have some logic that means the chosen nodes at each stage aren't in any of the previous arrays to allow for a nice path and no "coming back on your self".
However, the issue I'm facing is I'm using CLLocation.distance(), this unfortunately uses an euclidean distance calculation due to the curvature of the earth. Is there any way to off set the curve as my current logic ends up in all paths slowly leaning towards the poles as the world map is just a flat image.
I've thought about translating CLLocation to a UIView between the first node and all possible second nodes, however this becomes massively intensive.
Any ideas on how to either offset the curve calulation or remove it all together?