blankblank blank




Centroids From A Polygon Shapefile With SAGA



TD asks:

Wondering if you know of an easy way to create centroids (points) from polygons – I am using MapWindow and various other free tools. What I am ultimately trying to do is assign attribute data (parcel #) to a polygon shapefile representing buildings.  In other words, for each building polygon I want to assign it the correct parcel #.

Yes, you can do both tasks with free GIS software. Today, I’ll do the centroids, tomorrow the assignment of attribute data from one shapefile to another. Based on your description, you probably don’t need to create a centroid file, but it provides a convenient excuse for me to go through the functionality of a program full of great GIS tools. While I find its data display interface a little clumsy for regular use, the freeware GIS SAGA has an enormous list of useful functions, many of which are non-existent or hard to find in other free GIS programs. The basic process for using any of these functions is pretty much the same, so the following procedure can be used as a general guideline for using any of the function modules.

Conveniently, one of those modules generates centroids from a vector polygon file, where a centroid is “the intersection of all straight lines that divide plane figure X into two parts of equal moment about the line”. Look in the Modules list in the “Shapes-Polygons” area for the “Polygon Centroids” function:

4-5-2009-12.57.26 PM

If you click on the function to select it, the object properties window for that function should become visible on the right-hand side; if not, go to the “Window” menu and select “Show Object Properties”. At the bottom of the object properties window will be a number of tabs, active or inactive depending on the function and the data loaded:

4-5-2009-1.03.08 PM

“Description” brings up a short description of the module, along with the input/output parameters and options:

4-5-2009-1.03.58 PM

Here, the polygon shapes are the input, and the centroids are the output.  The “Settings” tab lets you specify the input data:

4-5-2009-1.01.54 PM

In order to specify the polygon shapefile for which you want the centroids, you have to load it into SAGA first, using either the “Load” button (the blue folder button in the upper-left-hand corner), or with the File => Shapes => Load Shapes command. Loading in a building shapefile called “bldgtest”, clicking on the “Data” tab in the lower-left-hand corner will confirm that it has loaded:

4-5-2009-1.12.18 PM

Double-clicking on the shapefile listing brings up a map view of that shapefile:

4-5-2009-1.13.45 PM

Now in the object properties window, with the Settings tab selected, I can choose this shapefile as my input:

4-5-2009-1.15.55 PM

The only option is a Boolean to create the centroids, and since I want that, I checked the option box. Once the input and options are set, clicking the “Execute” button at the bottom of the object properties window creates the centroid data, and adds it to the data list:

4-5-2009-1.17.54 PM

Double-clicking on the new point data entry, I can either display it by itself in a new map window, or include it in the previous map display along with original polygons:

4-5-2009-1.23.02 PM

While centroids for every polygon have been created, added to the data list, and made viewable, the centroid data is only in RAM at this point; if you don’t save it to a file before closing the program, it will be lost. To save the centroid data, I right-click on the point data in the data listing, choose “Save Shapes As”, and then choose a name and location for the centroid shapefile.

A few more notes:

  • The centroid point shapefile contains all of the shapefile attribute data of the original polygon file. In this case, the polygon shapefile had three attributes: MWShapeID, SHAPE_AREA and SHAPE_LENGTH, and those attributes for every polygon were carried over to the attributes for every corresponding centroid in the point shapefile.
  • There are a few more buttons at the bottom of the object properties window. “Save” lets you save a particular configuration setting, useful for functions with lots of options; “Load” loads in that saved setting. If you change settings, you may need to press “Apply” to enter those changed settings; if you change settings but then want to go back to the previous settings, click on “Restore”.
  • You can access function modules either from the module workspace, or from the “Modules” menu. For the latter, the function will come up as a separate window on screen:

4-5-2009-1.37.16 PM

No Description tab, no Apply or Restore buttons. To execute the function, click Okay, and the window will disappear as the function executes.

  • There’s a status window at the bottom that gives text messages regarding module execution; if there’s a problem, this is the first place to look for an explanation:

4-5-2009-1.40.35 PM

Tomorrow: Adding the parcel polygon data  to the centroid points.


Looking for something else? Enter some keywords below, then click "Search".    




2 Responses to “Centroids From A Polygon Shapefile With SAGA”


  1. 1 Geosaurus

    Great demonstration of a great tool. Do you happen to know though whether SAGA checks if a centroid falls inside the polygon or not?

  2. 2 Leszek Pawlowicz

    Don’t think it checks.

Comments are currently closed; feel free to contact me with questions/issues.