I have a .csv (exported to .shp) database with about two thousand entries of points. One column in this database has certain values (e.g. a point can be 'ash tree', 'beech tree', 'elm tree', etc). I want to visualise their relative counts within polygons (provinces in this case) in a pie chart. I'd also like to adjust the size of the pie chart based on the total sum in that province, but I suppose this will be easy.
Using ArcGIS 10.1 for Desktop.
Answer
First, what you need to end up with is your polygon file with an attribute column for each value or tree species. It's important to note the for each part of that, because right now you have, and any summary method will generate, rows for each species and not columns. At some point you have to make that conversion.
Let's start with the points. Each point is a distinct tree with a given species, but we need to know how many are in each province. Intersect the points with the polygons, and now each point has an attribute that says which province it's in. This could also be accomplished with a Spatial Join.
We want a total of each species in each province, so run Summary Statistics, with both province name and species ID fields as CASE fields. While we don't need a STATISTIC field since the tool creates a frequency field in the resulting table with the count we need, the tool does require you specify one to run. You can use species ID with a COUNT method and that should end up with the same values as the frequency field. The resulting table is not tied to any geometry but should have one row for each unique province/species combination with a count of how many points have that combination.
Now the row/column problem. If you join this table as-is to polygons, you have a one to many relationship (multiple table rows match one polygon shape/row). It will pick the first match to display. If (and only if) you're working in a geodatabase and export the join results, you'll get a duplicate polygon for each row in the summary table, meaning one copy of the province for each tree (if not in a geodatabase and version less than 10.1 you need to use the Make Query Table tool and export the result for this). You can't generate a pie chart from that. Two possible solutions (there may be others):
- Before joining, sort your summary table by species, and export each group of rows with the same species to a new table, then Join/Join Field all those individual tables to your polygon based on province ID. That will get you one row per province, and add a new column for each species count as you do each join.
- Make your duplicate polygons as above. Run Union with your original polygon layer and your duplicate, stacked polygon layer as inputs. If done correctly this should result in one row/shape per province with a column for each species count. Note this will not work if you Union the stacked polygon layer to itself. The attribute table is likely to be messy and require some cleanup.
Now you have a single feature class with one row/record per province and an attribute for each species with a count. For the pie chart scaling you need to add one more field - tree total - and then Field Calculate the sum of all the other counts. From there you can create your pie chart symbols and vary their size as explained at Creating Pie Chart with radius based on another field? There are some other things about the pie charts noted there you may want to read through (such as not being able to label them, how many categories you can have and still be legible, etc.).
No comments:
Post a Comment