I have a single dataframe which contains shapely coordinates for lots of polygons. These polygons overlap and I want to get a count of all overlapping polygons so I can do a heatmap of the distribution. I've developed a solution for this in FME, but I now need to automate it as part of a larger workflow in python. What I've tried so far is:
use union overlay to get all possible geometries. I assume that for areas that overlap, there will be multiple identical polygons that link back to the original polygons.
df_union = gpd.overlay(df_in, df_in, how='union')
All the examples I found for using union overlay have two input dataframes, but I have just one so I'm not sure if the above is even correct.
If my assumptions are correct, what I can't figure out is now how to count the identical polygons in the single dataframe so that I have results like:
Count geometry
5 POLYGON ((xxxxxx...
1 POLYGON ((xxxxxx...
I've tried df_union.groupby('geometry') to see if there are identical geometries to count but that produces a result I can't view.
Any pointers on this would be greatly appreciated.
A trick around this case is to cast the geometries as strings and then groupy on them.
For example for a data frame of the type
df.head()
id geometry
0 6795584 MULTIPOLYGON (((652670.3 6862958.2, 652675.6 6...
1 6794255 MULTIPOLYGON (((652935.2 6862338.2, 652935 686...
2 6794256 MULTIPOLYGON (((652988.8 6862328.5, 652991.9 6...
3 6794289 MULTIPOLYGON (((653006.6 6862311.6, 653015.2 6...
4 6794290 MULTIPOLYGON (((652998 6862280.3, 652999.8 686..
we cast the geometry as a string
df.geometry= df.geometry.astype(str)
and then we can groupy on it
df.groupby('geometry')['id'].count()
Related
I would like to figure out a way to divide a map into polygons based on the half way positions of lat/long positions.
For example, if there are four lat/long positions on a map (titled "unknown Placemarkers" in the image), I'd like to create four polygons which represent the half way points between the four lat/long positiongs (shown as a yellow line in the image)
Similarly if there were three lat/long positions then the polygons would adjust to have areas which are split by the half way point between the three points.
And the final scenario is that if a lat/lng is surrounded by other polygons the polygon split would be fully enclosed according to the last image.
I've created a new file of intersecting polygons (20 metre buffer of points). I would like to combine the polygons using QGIS, but not to combine them into one layer, with one single attribute table entry if you see what I mean - in order to reduce the number of single polygons in the layer. I've created an attribute field in the table for each polygon as ROWID. I would then like to output the centroid co-ordinates of each combined polygon (eastings & northings) using QGIS.
I have a shapefile from GADM that has a lot of polygons showing the states and provinces of Colombia, but I'm only interested in one of them. Is it possible to extract this one polygon and plot it afterwards using python3?
I want ask how to create an object (coherent body), if I have 3 excel files (approximately 1mil. Rows each) with X Y Z coordinate. After importing to Paraview I have ‘object’ as in figure below, it consist of 25 ‘planes’ which consist of points from excel files. I need to make from this planes one object with coherent body, basically wrap this planes with something. Is it possible with use of some filters in Paraview or do I need some programmable filter ? I have tried few things but the result was not satisfying.
Apply Table to Points filter to generate a point set and then apply the Delaunay 3D filter to get a surface from those points.
The page linked to here has been a great help to me. The method of using the named function (=(ROW(INDIRECT("1:361"))-1)*PI()/180) to produce the circle data points is very slick compared to my original method that was to calculate them individually, writing them in to rows.
My data set includes some 50k rows of data, each one defining a circle. The set is divided into 50 groups and I need to plot one circle from each group as selected via a scroll bar controlling a LOOKUP routine.
Please can someone suggest how I might modify the function (=(ROW(INDIRECT("1:361"))-1)*PI()/180) to reduce the number of data points it produces? I want to reduce the computing load and also, it's not practical to display & format data markers with such high data density. My existing circles are produced with just 18 coordinate pairs and are satisfactorily rounded.
Thanks in advance. Steve.
This would give you 19 data points, 0 and 360 as the start/end points with another every 20%
=(ROW(INDIRECT("1:19"))-1)*PI()/9