using QGIS 2.18.16 I am trying to figure out how to find out what polygons in layer one (blue) intersects the polygons in layer 2 (red\pink). I know that there will be more than one intersection for most of the polygons in layer 1 (blue) but not sure how to calc it. In a perfect world I would like to add it as a attribute to the polygon in layer 1.
[GIS] One to many intersection of polygons
intersectionpolygonqgis
Related Solutions
I'd go for SQL (QGIS natively supports the SpatiaLite 4.3.0 dialect for any layer query) and check for the spatial relation with the negative buffered polygons:
QGIS | DB Manager
- connect to
Virtual Layers
(double-click) in the left panel (make sure your layers are loaded in the project) open the
SQL Window
(second icon to the left)in the top panel, run (
Execute
)SELECT a.<id>, group_concat(b.<id>) AS its_lines, a.geometry FROM <polygon_layer> AS a JOIN <line_layer> AS b ON ST_Relate(ST_Buffer(a.geometry, -1), b.geometry, 'T********') GROUP BY a.id;
- load the produced table as a layer to the project by ticking the
Load as new layer
checkbox and fill in the fields
- connect to
The above query will return a table with all polygon <id>
s (paste the actual id field name here), their geometries
and a concatenated string of line <id>
s (same here) that intersect, but not touch, the negative buffered polygons of your layer.
Important:
Since you asked for meters, I put -1 in ST_Buffer
. However, the function will treat the passed number in CRS units; here, this implies that you are working with a CRS whose units are in meter! If you are working in LatLon, e.g. EPSG:4326, the parameter in ST_Buffer
will be treated as degrees...and thus makes no sense. In that case, a transformation into an appropriate projection is necessary; you can do that with
... ST_Buffer(ST_Transform(a.geometry, <srid_of_metric_CRS>), -1) ...
I tried to take your question becuase it is an interesting one to be solved with an SLQ statement.
Reading your tittle the case was either a linestring & polygon or a linestring & multipolygon type on the picture below (Source: Introduction to PostGIS):
But it seems you are mixing concepts. I GIS there is a limited number of geometry types compatred with the CAD paradigma. In GIS there are fewer vector types, the main ones are: points, lines and polygons (or nodes, edges and faces)
In GIS a point is an entity that had zero dimension (0D), it has only a location, a line has 1-D and it is made out of a set of points and a polygon is a 2D entity maede aout of a set of lines.
This picture will show the main three types of geometry entities (Source: A Gentle Introduction to GIS):
There are more types, but main differences with the CAD paradigma are in the confusion between lines, polylines and polygons. A polyline in CAD is just a line type in GIS, and a closed polyline in CAD could be read as line or a polygon type depending on the success of the importing tool.
Then we have the difference of the layer paradigma. CAD applications might store any kind of entity types in a layer, while GIS applications store only one type per layer.
Back to your question, it does not matter what the layer is called, it can store only one kind of data, and that can be read for the icon.
Line and polygon
has only line type entities and Muffe and Arrow
polygons.
My main suggestion now to you now is to read about GIS to get used to this new GIS paradigma about entity times and storage organization (layers). I highly recomend A Gentle Introduction to GIS Link to .pdf. Then, I suggest you to choose another file format than .dxf for your work in GIS, dxf does not fit very well with any gis analysis.
Best Answer
I found the following to work well on my small sample, though it involves repeated iteration through the layer1 features, so it might be slow on a large dataset. Also, I used QGIS 3.0.0. I am not sure how much it differs from 2.18.16.
First, load data (pardon my crooked quarter sections):
Second, use "Vector > Data Management Tools > Join Attributes By Location" to join the two layers. I selected "contains" in addition to "intersects" under geometric predicates to cover cases like polygon 2, where it doesn't cross the border of a quarter section. Use layer 1 (blue) as the input and the quarter sections as the join layer. Use the create separate feature for each located feature option under "join type".
This will create duplicate polygons wherever a layer1 polygon intersects with more than quarter section.
Lastly, we use the new joined layer to write the correct quarter section names into the original layer1 file with a bit of python.
There appears to be a trick to doing this in ArcGIS also (and it looks way easier). Spatial Join’s hidden trick or how to transfer attribute values in a One to Many relationship
Here are the steps (the post on Esri Australia Technical Blog also has screen captures). I didn't test this.