Here is one way to do it (the simplified way ) :
let's suppose that in each shapefile you have a unique column called index, if you don't you can create it by reindexing the DataFrame
lines.reset_index(inplace = True)
grids.reset_index(inplace = True)
1 - first apply a spatial join between both of your shapefiles, with operation within to avoid extreme ...
To my knowledge this requires multiple steps.
Note: This will give wrong results if you have overlapping polygons on one of your layers already.
Merge vector layers and select all the layers in question. This gives you one single layer to continue with. Also it adds a layer and path attribute to each feature to keep track of their provenience.
Union with ...
I've solved my problem. I had to move away from GeoTools and write a PostGIS query, because GeoTools doesn't appear have the features needed to do this successfully.
Here's the query:
SELECT intersection_query.census_block_group_gid, ST_Multi(ST_Union(intersection_query.geom)) AS geom
SELECT md_census_block_groups.gid AS census_block_group_gid, ...
I found a solution thanks to osgeo library that allows to interact with the single parts of a multipolygon geometry.
Help me the answer of Barret in this topic.
from osgeo import ogr
for feature in prv2.getFeatures():
g = feature.geometry()
g1wkt = ogr.CreateGeometryFromWkt(g.asWkt())
g2wkt = ogr.CreateGeometryFromWkt(...
In the Processing toolbox there is an option under QGIS geoalgorithms/Vector selection tools 'Select by location'. With this option you can select the features that are overlapping, intersecting and/or touching. The features can be saved to a new file by right-clicking the layer and choosing Save as. Check 'Save only selected features'.
I find this method ...
Or if you are happy with just plane trig solution in just 19 lines of code. Here it is in U-Basic.
This differs from the algorithms for geodesics solution by about 6mm at a distance of 175 meters.
5 'interx.ub adapted from code at
7 'In U Basic by yuji ...
Use the Select by location tool from the Processing Toolbox. Use "intersects" as the geometry predicate. This will select the intersecting polygons without cutting them.
If you want to extract the intersecting polygons to a separate layer, you can either
use the select by location tool to select the intersecting polygons, then right click on the layer > ...
From what I understand, your table uf has the geom of the federal units and municipios the geom of the municipalities, and you don't hvae any problem with the polygons (usually when you do this kind of things, the geom are not perfectly similar and there is approximation that make the correspondance between 2 tables difficult, but here I assume they come ...
OSM usually doesn't contain the exact outline of a junction or intersection (except in very few cases where area:highway has been mapped) and most roads don't have a width set.
However you can try to estimate it by looking at the highway class (i.e. primary, secondary, tertiary...) and the number of lanes.