# From polygon to continuous measure of diversity?

First of all; I have tried to find a similar question, without success. Maybe it's because I'm quite new to GIS and I don't really know what exactly I'm looking for. If someone points me to a similar problem, I'd be happy to remove this post.

I need to create a 'continuous' or raster (in small grid cells) variable of population diversity for a given country. I have a shapefile showing the spread of the ethnic groups in polygons (fig. 1), and the outcome I'm looking for is a the 'mean indicator of diversity' in each of the administrative units (AU's, in this case, the 360 Nigerian constituencies). Fig 1. Population groups polygons in Nigeria

The solution I came up with was to get the area percentage of each polygon in each AU, and calculate a heterogeneity index from that. But the problem is that I would be leaving aside quite a lot of information due to the distribution of administrative units. As shown in the fig. 2, the squares 'a', 'b', and 'c' would have the same 'segregation index', but it is clear that they are not in the same position vis-a-vis the 'hot spots'. Fig 2.

So I though that another solutions could be create a grid map, and calculate the distance to the nearest border, but again sharing only one border is not the same as being in the central part of the map, where several groups live together.

After finding this question, I guess that the polygons could be transformed into points using their centroids, and then apply the same method. But the truth is that I'm new to this, and that question is not really clearly answered. How could I made such a thing?

Using another example, I want to create something like this (images from this website):

Given the distribution of some points with different qualitative characteristics, get a measure of diversity from where I could estimate a the 'mean heterogeneity' of each administrative unit.

How could I do it? I use R and QGIS, so I don't mind in which platform is the solution based on.

I'd really give SpatiaLite a go for getting this done! Most conveniently you could use the QSpatiaLite plugin in QGIS.

Just set up a polygon grid with a sensible size for gridcells. Then intersect the grid with the ethnic group's polygon and calculate area of each intersection. With the resulting table you can calculate your indices by using the intersection areas, which are areas of ethnic groups in each gridcell, as 'abundance metric' (thats how an ecologist would name it)!

Assuming your ethnic groups layer is called 'EthnicGroups', with a field 'group' and the polygon-grid is named 'Grid' with a field 'ID', this SQL-query would apply:

``````SELECT
g.ID AS gID,
e.group AS egr,
AREA(INTERSECTION(e.geometry, g.geometry)) AS egr_area
FROM Grid AS g JOIN EthnicGroups AS e
ON INTERSECTS(g.Geometry, e.Geometry)
ORDER BY gID, egr_area ASC
``````

For calculating diversity-metrics with special formulas I would use R, collapsing these 'abundances', yielding one value for each gridcell, which finally could be joined back to your grid geometries!

To get your mean diversity for each AU you could than use the diversity indices which you have joined to the grid. Again by using SpatialLite grouping the values within AU-polygons with applying the mean-function.

Funny that I've just recently written a blogpost covering this issue, which might give you an idea: http://thebiobucket.blogspot.co.at/2014/12/usecase-find-dominant-species-and.html

As far as I'm concerned I'd advise to skip the idea of 'continuity' in this regard, because diversity is only meaningful in relation to the spatial unit it is based on. So I think all approaches and fancy techniques which use any sort of averaging or interpolating over other units than the spatial units that your indices rely on, will not add anything valueable, but rather obscure the outcome!

Here's a map showing amphibian (rather than ethnic;) diversity for which I've used quite the same method: ps: This link might be of interest, if you want to get diversity within a given search-radius!

In QGIS, you could generate a point grid on top of your polygons. You'll find this function under Vector -> Research tools (I think it's called that in English, my QGIS version is in another language.) You'll have to find some reasonable granularity when it comes to the point grid spacing.

Then under the Vector menu, you do a Join attributes by location (found under Data management,) using the points as the target and the ethnicity polygons as the source.

Now you have a point grid with an ethnicity attribute for each point.

Here is where it gets a bit tricky. You could generate a raster using these points, if you recode your attribute into a numerical value (for example using the Create equivalent numerical field tool in the QGIS processing toolbox.) You can then use Create grid under Raster -> Analysis. Here you could maybe experiment with Sliding average or Nearest neighbour analysis.Then you could use Zonal statistics (there are a number of options in the Processing toolbox, as well as in the raster menu.)

The trick is how to get the heterogenity index while ignoring the arbitrary value created by recoding the attributes into a numerical index, but you might have some idea of your own here. Not quite sure how to go about that without taking too much time from what I'm SUPPOSED to be doing right now :)

Another idea is to load your point grid into a Spatialite database (or PostGIS, but that's a bigger operation to get running.) Then you could use SQL and spatial functions in the database to test say all points within a set radius from each point to give it a local variance index, and then generating a raster from that value. I worked a bit with this recently.

Hope this gives you some ideas! Feel free to use the comments if you want to discuss further.

• Thanks a lot!! I'm gonna try to solve it and will come back to you if I have further problems (sure I'll do). – Fran Villamil Dec 4 '14 at 10:47

There are a number of assumptions in your question which need to be addressed before you get to the implementation question. The example you provide is a biodiversity analysis that is based on a sample of varieties of a given plant species. I looked at the manual for the software that was used to generate this raster, and there is no indication that this is appropriate for or has been applied to human populations. The centroid of a human cultural area (which you propose to use for your analysis) is not in any way analogous to a sample (i.e., actual observation) of a plant collection.

Proximity of human subgroups (divided along any dimension, here the dimension is ethnicity) may be expressed as a diversity measure or a segregation measure. One widely used diversity measure is the Herfindahl index, which varies from 0 to 1 and is small when an area has many small groups and large when an area has many large groups. It is calculated within a population or area without reference to anything outside that population or area. This is problematic since you are interested in spatial interaction across administrative boundaries.

One widely used measure of segregation is the index of dissimilarity, which varies from 0 to 1 and is small when subareas have the same population distribution as the greater region, and large when subareas are exclusively one group or another. It is usually calculated within a region for which demographic information is available for many subareas (e.g., you can calculate the Black-White index of dissimilarity for metropolitan area based on demographic data for all Census tracts within the metropolitan area). Wong (2002) has modeled local segregation by calculating the index of dissimilarity for each subarea based on the population of neighboring (i.e., contiguous) subareas rather than the region as a whole. A limitation of this measure is that it can only work for two groups at a time. However, I have used it in my own research by using the two most populous groups within each zone of neighbors.

You have indicated that you want to calculate diversity for each administrative unit (AU). But you also say that you need to create a continuous raster of diversity. It's not clear to me if you actually want a continuous raster of diversity or if you think you need that in order to calculate AU diversity. If you do in fact want continuous diversity, I would recommend taking a look at O'Sullivan & Wong (2007), which visualizes continuous diversity using a kernel density estimator. This has the effect of accounting for population interaction across administrative boundaries, which you indicate that you want.

OTOH, if you really want diversity by administrative unit, you could do that using either the Herfindahl index or the local index of dissimilarity. But that requires information about demographic characteristics within each AU. I assume that the reason you are using the ethnic areas map is because you don't have ethnic population data for the AUs. But if you know the population of each AU, and you intersect it with the ethnic areas grid, you can allocate the population of AUs to ethnic areas. The important assumption with this and the other answers proposed so far is that they assume that population density is constant throughout either the AU or the ethnic area. This assumption seems prima facie implausible, but you know the data better than me, and may be comfortable with this assumption.

Based on my understanding of your goals, I think my approach would be as follows:

1. Model population within subunits where subunits may be the intersection of AUs and ethnic areas, or a vector or raster grid. Given enough time, I would want to try it both ways.
2. Calculate the Herfindahl index for each AU, but, following Wong (2002), I would calculate the Herfindahl index based on the neighborhood of each AU rather than just the population within the AU. Given enough time I would experiment with both contiguity-based and distance-based neighborhoods.

Of course, none of this gets to technical implementation, but if you give me some feedback on this, we can move on from there.

PS: The academic papers I linked to are gated. If OP does not have access to an academic library, feel free to contact me via email and I will provide them for you.

• +1 Perhaps not technically detailed but still very useful and informative! – Joseph Dec 11 '14 at 10:47