1

I have a spatial dataset with two major columns: county_name and group_ID. The spatial polygons are represented by each county_name. Some counties share the same group_ID, while some counties contain more than one group_ID: i.e., I want to merge polygons with the same group_ID into one, and split the polygon which contains many group_ID (randomly or evenly) into sub-polygons with the same number of group_ID, and assign the group_ID feature to each split new sub-polygons.

I am very new to QGIS and spatial in python, is there a way to do both at the same time, or just part of that?

0

Merging is fairly easy I think, just use Dissolve in the Geoprocessing Toolbox and choose the group ID as the dissolve attribute.

As for splitting polygons, I would go about it like this if I did it with the QGIS GUI:

  1. Use the field calculator to count the number of unique IDs in the group_ID that belong to more than one group (for example by counting a separator like ','), and save that to a numeric attribute.
  2. Use Generate Random Points in Polygon based on the county layer as input and using the numeric value you created in step 1, so you get a number of points in each county polygon that correspond to the amount of group IDs it belongs to.
  3. If the random points lack attributes (don't remember if the parent feature's attributes are carried over), use Join attributes by location in the Geoprocessing Toolbox to re-add them to the points.
  4. Divide the concatenated multiple group ID value from the parent polygon among the random points so that each points receives one of the group IDs of the polygon it resides in.
  5. Generate Voronoi polygons with the random points as input via the Geoprocessing Toolbox.
  6. Intersect the voronoi polygons with the counties that had multiple IDs, using the Geoprocessing Toolbox Intersect tool. Now you should have randomly split counties, with a point in each fragment.
  7. I'm not sure if the Voronoi polygons inherit the attributes of the input points, but if not you could rejoin the group ID via Join attributes by location in the Geoprocessing Toolbox.
  8. Now should have fragmented counties and whole counties with a group_ID each, that you can run Dissolve on using the group_ID.
  • Thank you! But I am having two files, one file is the county polygon shp file, and the other is a CSV file with the records of county and group. I think the first step is for me to generate the number of unique IDs in the step one you wrote above. But I did it in the CSV file. Is there a way for me to merge the CSV file with the county shapefile (as a one-to-many) relationship to do the following steps? Or I do not need to merge? – Yijiao Liu Oct 9 '18 at 17:47
  • Hey I tried to follow your suggestions, which are very helpful! Except that I do clip' instead of intersect'. I tried both but it seems that the clip output a better map. Am I doing it correctly? – Yijiao Liu Oct 9 '18 at 21:13
  • Sorry, for the late response. But I think if you're getting the output you want, then you're doing it right! – hexamon Oct 18 '18 at 9:05
  • Okay thank you, and for the later users to see this, in step 6, we can do 'clip' instead of intersect. – Yijiao Liu Oct 18 '18 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.