In this #MapInfoMonday post, I will show you how you can use the Grid Maker tool to create vector grids of a given size for a dedicated area.
I will also show you how you can use specific functions in MapCAD to move and rotate your grid. MapCAD is an add-in that adds CAD-like functionality to MapInfo Pro. It has more than 30 different features for creating and modifying spatial data.
This specific use case comes from
Adrijana who responded to an earlier #MapInfoMonday post. Adrijana is looking for a way to divide a risen bed into 30 cm grid cells as that is the distance between the flowers in each direction.
Create the Vector Grid
The first step is to create a vector grid for our area. In the map below, you can see the risen bed as the red polygon.
That is the area I need to create a vector grid for.
From the
Tools window, make sure
Grid Maker has been loaded and then double-click on the tool to launch it.
You will see the
Grid Maker dialog appear.
Change these settings:
- Distance between lines: In my case, I change this to 0.3 meters
- Smoothness: I changed smoothness to 1 but as the grid cells are very small you could also change it to 0.
- New Table: I picked a different location for the vector grid file
- Projection: Make sure to switch to the same coordinate system as the table holding your area of interest. Also, note that as we are using small areas it is recommended to use a table with a bounded coordinate system where the resolution is higher than the typical 10 cm.
Make sure that the option
Select Area from Map has been checked. This allows you to draw a rectangle that you want the grid to cover.
Now hit the
OK button, and use the tool that you have been given to draw a rectangle in the map window.
When you have drawn the rectangle, the
Grid Maker dialog will appear again but this time it will show the coordinates from the rectangle you drew.
Hit
OK to accept the new extents and get the vector grid created.
In the map window below, you can see the vector grid I ended up creating.
Move the Vector Grid
Now it is time to adjust the vector grid to the existing polygon.
The first step is to move it so that the lower-left grid cells match up with the left corner of the existing polygon. It is not that important to use the lower-left grid cell. That depends on the existing polygon. The important thing is that you align a corner of a grid cell to a node in the existing polygon.
When creating the grid, you could have snapped the extent of the vector grid to that node in the existing polygon. That would have made this step unnecessary - at least for my specific polygon.
I will also recommend creating the vector grid in an area where it doesn't overlap the point on your existing polygon. If it does overlap, it can be hard to snap to the exact point.
- Make sure the add-in MapCAD has been loaded as we will be using tools from this add-in.
- Make sure the vector grid layer is editable
- Zoom into the map so that you can see the lower-left corner of the vector grid and the left corner of the existing polygon.
- Right-click the vector grid layer and select Select All from the context menu to select all the records in the vector grid table.
- From the Spatial table, in the Edit group, select the tool Move Along from the Transform dropdown.
- Hit the s key to turn on the snap feature. You can see that the word SNAP appears in the statusbar.
- Left-click in the corner of the vector grid cells and hold down the left mouse button, drag a line to the left corner of the existing polygon and let go of the mouse button.
Now MapCAD moves the vector grid cells to the new position. In the map below, you can see the moved vector grid cells.
Rotate the Vector Grid
In this example, the risen bed is rotated and we want to match this rotation in the vector grid cells.
First, we need to calculate the rotation. MapCAD has a tool for this:
Calculate Direction. It gives you the direction of a line or polygon segment when you click on it.
Select the tool
Calculate Direction from the
Calculate dropdown in the
Edit group on the
Spatial tab.
Click on the segment you want to get the direction for. In the map below, you can see I have marked the polygon segment, I click on with an orange arrow.
In the
Calculate Direction dialog, I can see the direction and I can also store it for later use when clicking on the
Store button.
Now I have calculated the direction and I am ready to rotate the vector grid cells.
- Make sure the layer with the vector grid cells is editable
- Right-click the vector grid layer and select Select All from the context menu to select all the records in the vector grid table.
- From the Spatial table, in the Edit group, select the tool Rotate Object (MapCAD) from the Transform dropdown.
- Activate snap if you haven't done this already: Hit the s key to turn on the snap feature. You can see that the word SNAP appears in the statusbar.
- With the tool, click on the left corner of the existing polygon to mark the rotation point that you want to rotate the vector grid cells around.
- In the dialog Rotation Angle, select the stored value from the popupmenu with the angles, and then hit the Left button to rotate the vector grid cells counter-clockwise.
- Hit OK to close the dialog.
In the map above, you can see how the vector grid cells now how the same rotation as the existing polygon.
Delete Grid Cells outside the existing polygon
The final step in my example is to delete the vector grid cells that are outside the risen bed.
Using the
Layer List, make sure the layer with the risen bed (the existing polygon) is on top of the vector grid cell layer.
From the
Mini Map Toolbar, select the
Boundary Selection tool from the
Select splitbutton and click inside the existing polygon. This will select all the vector grid cells inside the polygon. More precisely, all the vector grid cells with a centroid inside the polygon.
Now use
Invert Selection to select all the other records and hit the
Delete key on your keyboard to delete these.
The final result looks like this
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
------------------------------