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

I have hundreds of polygons that represent plants geographical ranges around the globe. For each species I have both a shapefile and collection of findings as points.
I would like to analytically find each pair of species that common range boundary at least at one point. Or, even better, which species has a boundary in certain proximity from another species. Any idea how to do this? I use QGIS and prefer Perl, but solution in any other language would be fine also.

share|improve this question

If you put your polygon shapefile into spatialite, this is easy. Say your species polygon table has columns "pk" as the primary key, "species_name", and "geometry" (which is created when you import a shapefile into spatialite) then you need a query such as:

SELECT, s1.species_name,, s2.species_name
FROM species AS s1, species AS s2
ST_Intersects(s1.geometry, s2.geometry);

I'd mention a few points:

  1. This query will run slowly since it checks every polygon against every other for intersection. You say you have several hundred polygons, so that would mean several 10's of thousands of database scans. That number would probably be OK, but if it grows any larger, then you'll want to add a spatial index to the table, and use it in the query.
  2. If you want to know whether the borders touch, but the polygons do not overlap, then replace the ST_Intersects() with ST_Touches().
  3. You can also find with pairs do not touch at all with ST_Disjoint()
  4. And to find those polygon pairs that are within a distance of one another, try, in the WHERE clause: ST_Distance(s1.geometry, s2.geometry) < your_threshold;
share|improve this answer
Thanks a lot Micha! SpatiaLite seems to be a perfect solution not only for this but for other problems I have! – Alex Druk Dec 7 '12 at 22:50

I'm not sure whether your range polygons have exactly precise shared boundaries, like country borders.

If so, and if you work with GeoJSON and/or JavaScript, I'd highly recommend Mike Bostock’s TopoJSON, which extracts topology from a GeoJSON object by finding all exactly shared boundaries. This results in a smaller file since the shared polyline coordinates only need to be written once. It also uses delta-encoding to further reduce the file size.

share|improve this answer

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.