Geospatial Modelling Environment

graph.createfrompolygons (Generate Spatial Graph From Polygons)

Creates a spatial graph by connecting polygons based on a distance threshold, and exports node and edge data that can be imported into R


This tool creates a spatial graph based on discontinuous (non-touching) polygons. (To create a graph based on polygon adjacency see the calc.sharedborders command.) To create the nodes a single point is generated to represent each polygon using either the centroid or label point methods (see the genpointinpoly command for a description of these terms). Nodes are connected if the shortest distance between the polygons they represent is no larger than the distance threshold specified. The command generates two types of edge outputs: the straight lines connecting the node points, and the lines (links) representing the shortest distance between polygons. The length of both edges and links is written to both attribute tables, and the edge export file.

Nodes and edges are export as two delimited text files that can be easily read into R. The unique point ID field is preserved in the exported node data so that the connection with the original point data can be preserved. An optional node wieght field can also be specified, which results in an extra column of data being written to the export file.

The graph can be created in R using the igraph library as follows.



edata <- read.csv("exportedges.csv")

ndata <- read.csv("exportnodes.csv")

graph1 <-[,-1], directed=FALSE, vertices=NULL)


graph.createfrompolygons(in, uidfield, distance, outline, outpoint, outlink, exportnode, exportedge, [nodeweightfield], [centroid], [where]);

inthe input polygon data source that represents graph nodes
uidfieldthe unique feature ID field for the input data source
distancethe threshold distance for connecting nodes
outlinethe output line feature data source
outpointthe output point (node) feature data source
outlinkthe output link (line) feature data source
exportnodethe graph node export csv file
exportedgethe graph edge export csv file
[nodeweightfield]a field name containing node weights to be included in the export file)
[centroid](TRUE/FALSE) if TRUE uses the centroid point of the polygon for the node, if FALSE uses the label point)
[where]the selection statement that will be applied to the input feature data source to identify a subset of features to process (see full Help documentation for further details)


graph.createfrompolygons(in="C:\data\points.shp", uidfield="PNTID", outline="C:\data\graphedges.shp", outlink="C:\data\graphlinks.shp", exportnode="C:\data\exportnodes.csv", exportedge="C:\data\exportedges.shp");

graph.createfrompolygons(in="C:\data\patchpolygons.shp", uidfield="PATCHID", outline="C:\data\graphedges.shp", outlink="C:\data\graphlinks.shp", exportnode="C:\data\exportnodes.csv", exportedge="C:\data\exportedges.shp", nodeweightfield="AREA", where="POPULATION > 0");


Please consider making a purchase to support the continued development of these tools  Read more...

Tips on how to use this interface efficiently 


Open Source GIS

Copyright © 2001-2014 Hawthorne L. Beyer, Ph.D., Spatial Ecology LLC    Connect on LinkedIn