Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given a polygon in a PostGIS database, what is the best way to create a graph of its distribution over a range of latitudes? I'm picturing a graph of a curve, where the proportion of the total area under the curve that lies between two points on the x-axis (latitude) represents the proportion of the polygon's area between those latitudes. The tools I have at my disposal are PostGIS and R. It seems like this should be a fairly routine exercise for which there are well established approaches that I simply haven't been able to find.

share|improve this question
Create a number of horizontal (or vertical?) slice rectangles that span your polygon. Give each one a latitude attribute. Then do an ST_overlay or ST_union or something, so that your polygon is sliced. Then compute the area of each slice. Would that do it? I've put this in a comment due to vagueness... – Spacedman May 1 '12 at 21:49
A simple modification of the line-sweep algorithm at will do it: you only have to compute the length of the intersection of the sweep line with the polygon at each event, provided you use an cylindrical equal-area projection. The result will be the density function; integrating that will give the requested cumulative function. – whuber Jun 5 '15 at 16:33

OKay, here in an answer, some R code - uses rgeos, sp:

For p = a single SpatialPolygon or single row of a SpatialPolygonsDataFrame:

slice <- function(p,n=20){
  bb = bbox(p)
  ys = seq(bb[2,1],bb[2,2],len=n)
  ll = list()
  for(s in 1:(n-1)){
    ll[[s]] = Polygons(list(

where n=number of slices, returns n rectangular slice polygons. Now overlay:

lls = slice(p,40)
ii = gIntersection(p,lls,byid=TRUE)

should show you the slices. Now get the areas:

a = sapply(slot(ii,"polygons"),slot,"area")

I'm just not sure how correct that will be if the polygons have holes in them. Try some tests first.

share|improve this answer
Thanks, that looks like it might work. I just installed rgeos and I'll post back when I have a chance to try it out, unfortunately it might be a few days or more. – Gregory May 2 '12 at 0:47
+1 - really nice solution! – Simbamangu May 2 '12 at 5:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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