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.
Related
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
I have two geometries, one is made from another by offsetting its vertices,
so both have same structure and hierarchy.
Need to connect these two geometries with caps (yellow geometry).
Pretty sure that the problem could be solved by finding edge points (yellow lines) on both sides for each element. As soon as these geometries have same # of vertices and herarchy caps could be easilly calculated.
But, for now, I don't have any idea how to determine these edge points.
My solution to this problem. Not ideal.
http://vkuchinov.github.io/BuildingCaps/
I am dealing with storage of shapes. After a day spent to include the routines now I have some doubts.
The main trouble is recognize perfectly the new shape and know if already included or not.
I wrote something, and it works. I select all the shapes with same area and same number of vertex, and than I perform an Heuristic comparison. But, so just to be sure, I would ask you, if you know some direct algorithms, such matrix, spectrum, G theorm that gave two set of point can understand if the two sets are the same shape?
Before somebody screams about gis, the shapes can contain negatives shapes, better known with the name of holes. That are not to analyze in own coordinate system but in owner shape coord sys, where is the hole inside the other shape and his orientation. As far as I know, can gis nest shapes in other shapes and recognize them as whole shape.
Second place, what is the best way to store shape? I was thinking to store as array but I find it uncomfortable.
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.
I'm using Geoserver version 2.1.1, Postgres 9 and PostGIS 2.0
What I want to achieve should (i think!) be quite straight forward. I want to render on a map a line that represents the Great Circle between two cities on the earths surface.
My database contains the city locations represented as geography points defined as latitude and lonfitude pairs.
I have a layer defining an SQL view in Geoserver which retrieves a linestring (st_makeline) from the two coordinates for the specified cities. I'm having to type cast the geographies to geometries to get this to work.
But when I draw the returned line on a map what i get is a straight line and not the curved line that I am expecting.
Can someone tell me how I should be going about this?
Thanks!
PostGIS offers mainly "constructors" of the base geometries point, linestring and polygone, like ST_MakeLine.
And what yo uwant to do depends also on the coordinate reference system you use when displaying your map layers.
Here's a nice trick about great circles or parts of:
https://gis.stackexchange.com/questions/5204/curved-point-to-point-route-maps
Yours, Stefan
P.S. Here's some related stuff:
Drawing circles on a sphere
And here's some math:
http://www.mathworks.ch/matlabcentral/newsreader/view_thread/277881
I had a similar problem in cartodb (which also uses PostGIS); I wanted to get curved lines from straight lines. Maybe this post can help.