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

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.

Related

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

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.

How to have a generator class in shader glsl with amplify shader editor

i want to create a shader that can cover a surface with "circles" from many random positions.
the circles keep growing until all surface covered with them.
here my first try with amplify shader editor.
the problem is i don't know how make this shader that create array of "point maker" with random positions.also i want to controll circles with
c# example:
point_maker = new point_maker[10];
point_maker[1].position = Vector2.one;
point_maker[1].scale = 1;
and etc ...
Heads-up: That's probably not the way to do what you're looking for, as every pixel in your shader would need to loop over all your input points, while each of those pixels will only be covered by one at most. It's a classic case of embracing the benefits of the parallel nature of shaders. (The keyword for me here is 'random', as in 'random looking').
There's 2 distinct problems here: generating circles, and masking them.
I would go onto generating a grid out of your input space (most likely your UV coordinates so I'll assume that from here), by taking the fractional part of the coords scaled by some value: UV (usually) go between 0 and 1, so if you want 100 circles you'd multiply the coord by 10. You now have a grid of 100 pieces of UVs, where you can do something similar to what you have to generate the circle (tip: dot product a vector on itself gives the square distance, which is much cheaper to compute).
You want some randomness, so you need to add some offset to the center of the circle. You need some sort of random number (there might be some in ASE I can't remember, or make one your own - there's plenty of that you look online) that is unique per cell of the grid. To do this you'd input the remainder of your frac() as value to your hash/random method. You also need to limit that offset depending on the radius of the circle so it doesn't touch the sides of the cell. You can overlay more than one layer of circles if you want more coverage as well.
Second step is to figure out if you want to display those circles at all, and for this you could make the drawing conditional to the distance from the center of the circle to an input coordinate you provide to the shader, by some threshold. (it doesn't have to be an 'if' condition per se, it could be clamping the value to the bg color or something)
I'm making a lot of assumptions on what you want to do here, and if you have stronger conditions on the point distribution you might be better off rendering quads to a render texture for example, but that's a whole other topic :)

Anything in Leaflet that is similar to isLocationOnEdge() from Google Maps?

Google Maps has the function isLocationOnEdge(point, polyline, tolerance) that takes a tolerance value in degrees and uses it to determine whether a point falls near a polyline.
Is there anything similar in Leaflet(or some plug-in) that does the same thing?
A handful library for such operation is Turf.
For your case, a simple approach would be to:
Create a polygon out of your polyline using turf.buffer with appropriate "tolerance" (Turf takes a distance at Earth surface, or degrees).
Check whether your point is within that polygon or not using turf.inside.
Unfortunately, turf.buffer is only an approximation, it does not takes geodesy into account… therefore for big tolerance you will have a deformed shape.
An exact method could be to:
Use instead turf.pointOnLine to find the nearest point of the polyline.
turf.distance to measure the distance between those 2 points, and compare with your tolerance (or even just Leaflet latLng.distanceTo, but you would have to convert GeoJSON points back to Leaflet LatLngs).

how can i split an image based on longest horizontal edge?

For example , how can i split the two row of books of this shelf based on horizontal edge? I have used sobel edge detector to detect the edges but i don't know how to or what condition to use to split the image.
I can recommend you two different approach to solve this problem.
1) Machine learning approach. This requires some labeled data, indicating the y coordinate of the edge position, then HOG feature plus a random forest classifier will do the job.
2) Image processing approach. First, let's see the output of what i have done:
the blue color indicating the score of being the desired y position of the separation edge.
Such approach always relies on some assumptions on your data, here we suppose that the target horizontal edge separating books, which contains a lot of vertical lines. Namely, we are looking for y coordinate where locate long horizontal lines which are not cut by vertical lines.
Once define our objective, the rest begin very easy.
First we need a straight line detector, hough transform will do.
Secondly, we vote for each y coordinates for being the best separator using two scores:
1) 1st score describes how many long horizontal lines (found previously) are located in the neighborhood. Let's call it s_h.
2) 2nd score describes how many long vertical lines are located in the neighborhood. Let's call it s_v.
Finally, we only need to combine s_v and s_h to make a final score. For example,
s = s_h / (s_v + 1)
Using this, we get the first scoring map posted at the beginning. Some further post processing need to be done, but should not be difficult.
Here is just one possibility to solve it, here you find my code presented in a notebook.

Calculate nearest point of KML polygon for iPhone app

I have a series of nature reserves that need to be plotted, as polygon overlays, on a map using the coordinates contained within KML data. I’ve found a tutorial on the Apple website for displaying KML overlays on map instances.
The problem is that the reserves vary in size greatly - from a small pond right up to several hundred kilometers in size. As a result I can’t use the coordinates of the center point to find the nearest reserves. Instead I need to calculate the nearest point of the reserves polygon to find the nearest one. With the data in KML - how would I go about trying to achieve this?
I've only managed to find one other person ask this and no one had replied :(
Well, there are a couple different solutions depending on your needs. The higher the accuracy required, the more work required. I like Phil's meanRadius parameter idea. That would give you a rough idea of which polygon is closest and would be pretty easy to calculate. This idea works best if the polygons are "circlish". If the polygon are very irregular in shape, this idea loses it's accuracy.
From a math standpoint, here is what you want to do. Loop through all points of all polygons. Calculate the distance from those points to your current coordinate. Then just keep track of which one is closest. There is one final wrinkle. Imagine a two points making a line segment that is very long. You are located one meter away from the midpoint of the line. Well, the distance to these two points is very large, while, in fact you are very close to the polygon. You will need to calculate the distance from your coordinate to every possible line segment which you can do in a variety of manners which are outlined here:
http://www.worsleyschool.net/science/files/linepoint/distance.html
Finally, you need to ask yourself, am I in any polygons? If you're 10 meters away from a point on a polygon, but are, in fact, inside the polygon, obviously, you need to consider that. The best way to do that is to use a ray casting algorithm:
http://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm