MapInfo Pro

 View Only
Expand all | Collapse all

MapInfo Monday: Moving the Centroid for Polygons

  • 1.  MapInfo Monday: Moving the Centroid for Polygons

    Employee
    Posted 10-25-2021 05:01
    Edited by Peter Møller 10-26-2021 12:27

    Happy #MapInfoMonday!

    I got a question​ last week from @Dennis Coppens. He couldn't remember how to manually move the centroid for his polygon layer. Here's a brief walk-through of how to do this.

    Do note that this is only possible for polygons. For points, lines, polylines, and other object types, the centroid is automatically calculated and isn't stored with the object.

    One example of why you may want to move the centroid of a polygon is to control the location of the labels. Typically, labels are located at the centroid of the polygon. Below you can see a map of municipalities of The Nederlands. Most labels are nicely placed inside the polygons but a few are located in a way that makes them cross into neighboring polygons.


    Here I have selected one polygon where the label could be placed a bit better inside the polygon.


    Please note that before starting the manually move all the centroids of your polygons, try out some of the label placement improvements we made a while back. From the Labels tab, check out the Label Rules dropdown.


    Or check out the Labelling Rules tab from the Layer Properties dialog.


    Note that the behavior of these depends on the object types in the table.

    Manually moving the centroid of a polygon

    Anyway, back to the main idea behind this article: Moving the centroid of a polygon.

    The first thing you need to do is to turn on Show Centroids for the layer via the Style tab. Make sure you have selected the layer that you want to edit the centroids on.


    If you have labels turned on, it can be hard to see the centroids as the labels are positioned right on top of the centroids. In the map below, I have turned off the labels so that you better can see the blue dots representing the centroids for the polygons.


    If you have labels turned on to be able to see the new location of these as you move the centroids, I'd recommend that you make the labels not selectable. This prevents you from selecting the labels instead of the centroids.

    Now make the layer editable, select a polygon and turn on Reshape. You can activate Reshape from the Map Mini Toolbar or via the keyboard shortcut Ctrl + R. You can also access Reshape from the Nodes dropdown on the Spatial tab.

    Reshape allows you to change the form of the polygon by moving existing nodes and adding new nodes. When Show Centroids is activated, it's also possible to move the centroid. Simply hold the mouse on top of the centroid click and hold down your left mouse key, drag the centroid to the new position and release the mouse key.


    When you release the mouse key, the centroid is moved, and if the layer is configured to place the label on top of the centroid, the label is also repositioned as you can see below.


    ​Do note that a centroid needs to be placed inside the polygon. You can not drag it outside of the polygon. If you try, you will see this error.


    Remember to save the changes to the table.


    I hope you have found this article useful. Have you ever moved the centroids of polygons? If yes, can you share why you did so?



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------


  • 2.  RE: MapInfo Monday: Moving the Centroid for Polygons

    Employee
    Posted 10-26-2021 08:18
      |   view attached
    Attaching a tool created by Bill Thoen back in 2010 that will help locate the 'Center of Gravity' of a Polygon.  Feel free to modify source code as needed.

    ------------------------------
    Bill Wemple
    Principal Software Engineer, Quality Management
    Precisely, Inc
    precisely.com
    ------------------------------

    Attachment(s)

    zip
    CenterOfGravity.zip   11 KB 1 version


  • 3.  RE: MapInfo Monday: Moving the Centroid for Polygons

    Posted 10-26-2021 08:20
    Good old Bill Thoen. Nice to see him mentioned!

    ------------------------------
    Steve Wallace
    Florida Farm Bureau Insurance
    ------------------------------