How to join the edges of one line layer to nearest line layer and deleting the extra line after the intersection point in pyqgis? - qgis

Hi all im a newbie to the qgis and pyqgis, as i mentioned in the question i have two condtions:
Condition 1:
I want result something like this
condition 2:
i want something like this
Basically i want to match the edge of two shapefiles i tried creating start point and endpoint and shortest line between them but it didn't help me.
I will be thankful if anyone guide me how to solve this . Thank You

My English is not very good, but I can provide the idea of ​​what I did before
Algorithms require you to write your own
The line is actually composed of several points
So you need to find the head and tail coordinates of the line is a list[0] and list[-1]
You need to write code to calculate the distance between two coordinates and change the coordinates of the line attributes
Iterate over each coordinate using the coordinates of list[0] and list[-1]
Assuming that the coordinates of list[0] and line B are the closest, modify the coordinates of lineB to list[0]
Finally, some parts need to be corrected. For example, you need to exclude the coordinate comparison with the other end of the line.
Hope it helps you

Related

How can I make a border mesh with 2 pointsets that each have their own length

So i need to create a border mesh from 2 different pointsets that have their own length. The "mesh" needs to be a list of polygons that are sorted clockwise, the polygons can contain any number of points.
image of problem
I used to do this by looping through the points in the outer set, and for each point I would connect it to the closest point of the inner set. After that I would make faces with 4 points out of the lines I made. This worked perfectly.
But now we run into the problem that the outer point set no longer has the same length as the inner set. So our current approach will no longer work.
if someone could help me in the right direction or with an example on how to achieve this that would be greatly appreciated

Check intersections between points and polygons in QGIS

I have two data layers, one with points and one with polygons. Both layers have ID's and I would like to check whether the points with ID x lay inside or outside the polygon with ID x.
Does someone know how to do this?
Thanks,
Marie
One potential solution which gives you a comma separated list in the python console is to run a small script from the python console:
mapcanvas = iface.mapCanvas()
layers = mapcanvas.layers()
for a in layers[0].getFeatures():
for b in layers[1].getFeatures():
if a.geometry().intersects(b.geometry()):
print a.id(),",",b.id()
This should produce a result of cases where one feature intersects the other. The order of the layers did not matter in my testing, however, both layers had to use the same coordinate reference system, so you might need to re-project your data if both layers have different reference systems. This worked for points in polygons and polygons intersecting polygons (I'm sure it would work with lines as well).
Answers such as this: https://gis.stackexchange.com/questions/168266/pyqgis-a-geometry-intersectsb-geometry-wouldnt-find-any-intersections may help with further refinement of such a script, and was a primary source on this answer.

DITMatlab: How to calculate hysteresis for experimental data set?

I got an experimental data set that looks more or less like this.
I need to determine how big the hysteresis loop is, aka if I look at two points with the same capacity (Y axis), whats the maximum distance between said points (X axis).
The issue is, data points arent located on the same Y value, aka I cant just find max X and min X for every Y and subtract them - that'd be too easy :^)
I figured I can use convex hull (convhull) to calculate the outer envelope of the set, but then I realised, it will only work for the convex part, not the concaved part, but I guess I can divide my data set into smaller subsets and find a sum of them... or something.
And then, assuming I have the data set thats only the outer outline of the data set, I need to calculate distances between left and right border (as shown here), but then again, thats just data set of X and Y, and Id need to find the point where green line crosses outer rim
So here are the questions:
Is there a matlab procedure that calculates the outer outline of data set, that works with the concaved part - kinda like convhull, but better?
Assuming I have the outline data set, is there an easy way to calculate secant line of data set, like shown on second picture??
Thanks for any advice, hope I made what I have in mind clear enough - english isnt my first language
Benji
EDIT 1: Or perhaps there is an easier (?) way to determine, which points form biggest outline? Like... group points into (duh) groups, lets say, those near 20%, 30%, 40%... and then pick two randomly (or brute force pick all possible pairs), one for top boundary, other for bot boundary, and then calculate area of polygon formed this way? Then, select set of points resulting in polygon with biggest area?
EDIT 2: Ooor I could group them like I thought I would before, and then work on only two groups at a time. Find convex hull for two groups, then for two next groups, and when Im done with all the groups, Id only need to find points common to all the group, and find a global hull :D Yeah, that might work :D

How do I optimize point-to-circle matching?

I have a table that contains a bunch of Earth coordinates (latitude/longitude) and associated radii. I also have a table containing a bunch of points that I want to match with those circles, and vice versa. Both are dynamic; that is, a new circle or a new point can be added or deleted at any time. When either is added, I want to be able to match the new circle or point with all applicable points or circles, respectively.
I currently have a PostgreSQL module containing a C function to find the distance between two points on earth given their coordinates, and it seems to work. The problem is scalability. In order for it to do its thing, the function currently has to scan the whole table and do some trigonometric calculations against each row. Both tables are indexed by latitude and longitude, but the function can't use them. It has to do its thing before we know whether the two things match. New information may be posted as often as several times a second, and checking every point every time is starting to become quite unwieldy.
I've looked at PostgreSQL's geometric types, but they seem more suited to rectangular coordinates than to points on a sphere.
How can I arrange/optimize/filter/precalculate this data to make the matching faster and lighten the load?
You haven't mentioned PostGIS - why have you ruled that out as a possibility?
http://postgis.refractions.net/documentation/manual-2.0/PostGIS_Special_Functions_Index.html#PostGIS_GeographyFunctions
Thinking out loud a bit here... you have a point (lat/long) and a radius, and you want to find all extisting point-radii combinations that may overlap? (or some thing like that...)
Seems you might be able to store a few more bits of information Along with those numbers that could help you rule out others that are nowhere close during your query... This might avoid a lot of trig operations.
Example, with point x,y and radius r, you could easily calculate a range a feasible lat/long (squarish area) that could be used to help rule it out if needless calculations against another point.
You could then store the max and min lat and long along with that point in the database. Then, before running your trig on every row, you could Filter your results to eliminate points obviously out of bounds.
If I undestand you correctly then my first idea would be to cache some data and eliminate most of the checking.
Like imagine your circle is actually a box and it has 4 sides
you could store the base coordinates of those lines much like you have lines (a mesh) on a real map. So you store east, west, north, south edge of each circle
If you get your coordinate and its outside of that box you can be sure it won't be inside the circle either since the box is bigger than the circle.
If it isn't then you have to check like you do now. But I guess you can eliminate most of the steps already.

How can I determine if two paths in Quartz 2d intersect?

If I create two paths in Quartz 2d, is there a way to determine if they intersect?
Vaguely thought one could make a context and set one path as the clipping path, then draw the other path through that; but then how to determine if the resultant path is empty?
I have had a similar problem to this. I was building an asteroids-like game, and needed to check for ship-asteroid and bullet-asteroid intersections. All 3 were drawn with vectors so worked out as simple as checking each line in one object against the lines in the other object. ie loop through the lines in one object and in that loop then loop through all potential object and their lines to see if there is an intersection.
To check for actual line intersection I would read up here:
http://zonalandeducation.com/mmts/intersections/intersectionOfTwoLines1/intersectionOfTwoLines1.html
and here:
http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=geometry2
Let us know how you get on.