MapInfo Pro

 View Only
  • 1.  Create square grids from points or rotate individual diamonds on their centroid

    Posted 05-31-2023 07:12

    Hi, I am struggling to convert a list of over 2000 points into 120m squres. By buffering object I managed to convert them to diamonds, but i can't seem to be able to rotate those diamonds on their own centroid. So can anyone please let me know how to rotated individual polygons on their centroids or a way to create squares directly from points.
    Thanks



    ------------------------------
    Paulo Nunes

    ------------------------------


  • 2.  RE: Create square grids from points or rotate individual diamonds on their centroid
    Best Answer

    Employee
    Posted 06-01-2023 03:10

    Hi

    I'm assuming you are using MapInfo Pro v2019 or newer.

    You can create a SQL Select statement that creates these squares. The trick is to create a 45-degree line through the point by offsetting the points 60 meters to the south and east and 60 meters to the north and west. You then create a minimum bounding rectangle around this line, and end up with a square around the input point.

    Let me show you this in two steps. First the 45-degree line:

    I use the SQL window to run my query. I use the MapBasic function CreateLine() to create a line. This function takes two coordinate pair, the start and end point.

    To calculate these points, I use the MapBasic function CartesianOffsetXY(). This function takes four parameters. The object to offset. The change in X and the change in Y, and finally the distance units for the change in X and Y.

    To extract the coordinates from the moved point, I use the MapBasic functions CentroidX() and CentroidY() which return the X and Y coordinates for the centroid of an object, in this case, the point itself.

    The Select statement looks like this. I have split it across multiple lines to make it easier to read.

    Set Coordsys Table Incidents
    Select i.*, 
          CreateLine(
                CentroidX(CartesianOffsetXY(i.OBJ, -60, -60, "m")),
                CentroidY(CartesianOffsetXY(i.OBJ, -60, -60, "m")),
                CentroidX(CartesianOffsetXY(i.OBJ, 60, 60, "m")),
                CentroidY(CartesianOffsetXY(i.OBJ, 60, 60, "m"))
          ) Object
    From Incidents As "i"
    Into Selection

    You can see the result below on the map as the red lines go through the orange dots. Oh, and notice the Object keyword I use after the CreateLine() function. This tells MapInfo Pro to use the resulting object as the spatial object for the query. This only works in MapInfo Pro v2019 or newer.

    That's more than half the job done. We only need to add a function that returns the MBR of the line instead of the line. The MapBasic function MBR() does this.

    Set Coordsys Table Incidents
    Select i.*, 
       MBR(
          CreateLine(
                CentroidX(CartesianOffsetXY(i.OBJ, -60, -60, "m")),
                CentroidY(CartesianOffsetXY(i.OBJ, -60, -60, "m")),
                CentroidX(CartesianOffsetXY(i.OBJ, 60, 60, "m")),
                CentroidY(CartesianOffsetXY(i.OBJ, 60, 60, "m"))
             )
          ) Object
    From Incidents As "i"
    Into Selection

    Now you can save the result into a new table to maintain the squares.



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



  • 3.  RE: Create square grids from points or rotate individual diamonds on their centroid

    Posted 06-01-2023 04:10

    Good morning Peter,

    thank you so much for the prompt answer. I am indeed using the last version of Mapinfo and it was worked a treat. I am not ashamed to admit I wouldn't have managed to get there by myself, so a huge thank you for this.

    Kind regards,



    ------------------------------
    Paulo M Carochas Nunes
    RF COM SOLUTIONS LTD
    Bristol
    ------------------------------