Subscribe to this thread
Home - General / All posts - Labels in M9. using Transform Centroid to center labels, creates new component
tonyw
736 post(s)
#17-Mar-18 16:38

Currently for me in M9, labels for an area lie on one of the vertices making up the area boundary. My work around to put labels in the centre of an area is to copy the table (I'll call the new table "B") and make a new drawing from "B" then do a Transform Centroid and create labels from that. THis works and I can independently move labels so that close lying labels all are displayed. The problem is I'm constantly editing the original table "A" and then I have to delete table B re-copy and re-make and re-style my labels after each edit to Table A. The labels are no longer associated with the original table.

Is there a way to work with just one table and have the labels at least for areas in the centre? Right now with adjacent areas, the labels lie on a border and you can't tell which label goes with what area. See screenshot.

Attachments:
labels along border.JPG

Dimitri


7,413 post(s)
#17-Mar-18 17:43

Add a geom field to the table and create it as a computed field that takes the centroid of the Geom field.

Create a drawing from that and then create the label from that.

Now, all the action is in one table. Change a field and the label changes. You can't move the labels because they are created from the area centroid, but it's a lot better than having the labels be tied to some vertex on the area boundary. That will get improved soon.

tonyw
736 post(s)
#18-Mar-18 17:44

Thanks Dimitri

I'm on day 2 trying to add a new geom field to my Table named "A Table" and fill it with a computed field. Here's my best determination of the workflow.

1. In my table "A", click Edit > Schema (because the right-most column in my table A does not have an asterisk to click and add a new field)

2. In Schema, click <new field>, name it "Label Centroid" make it type "geom". Moved to Expression box however unable to proceed here as I don't know what to what to put in. Have read the help manual but did not find anything applicable. Proceded with adding a new field, it is filled with <NULL>.

3. Open Command window CTRL Tilde. Drag my Table A into right hand column to see fields. Searched in lower left box for "centroid", could not find any centroid functions. Did find some functions containing the word "center". Selected GeomCenter(<geom>, <tolerance>): <valuex2> as most likely. Created query with my limited knowledge of SQL.

Select * from [A Table]

SET [Label Centroid]=GeomCenter([Geom], 0)

4. When run I get an "invalid object reference".

Add a geom field to the table and create it as a computed field that takes the centroid of the Geom field.

Dimitri, can you provide a bit more detail please on how to do this? I've read what I think are relevant parts of the manual on editing tables and adding new fields. I have a map mostly ready for a meeting but having labels in the centre of areas would be better than at a point along an area border.

I have to print the maps today so have reverted back to making a copy of table "A", transforming area to points to use as label centres then creating and styling the labels.

tjhb
10,094 post(s)
#18-Mar-18 18:50

Tony,

Since you're in a hurry, this is just a simple fix.

In step 2, enter this as the Expression:

GeomCenter([Geom], 0)

You can do nearly the same with an UPDATE query as in your step 3--the main difference being that new areas won't be given centroids automatically. I'll come back to the syntax for that.

tjhb
10,094 post(s)
#18-Mar-18 22:29

For step 3, an UPDATE query needs syntax like this.

UPDATE

  (

  SELECT

    [mfd_id],

    [Geom][Label Centroid]

  FROM [A Table]

  )

SET [Label Centroid] = GeomCenter([Geom], 0)

;

In the wrapped SELECT, you could use * rather than enumerating the 3 required fields.

In any case, the SELECT list must include [mfd_id], or some other field(s) for which a BTREE index is defined. Without a BTREE index the SQL engine can't tell one record from another, so can't address records to update them. (This is a new requirement in Manifold 9.)

tonyw
736 post(s)
#19-Mar-18 04:52

Thanks tjjhb (Tim I think, is it?)

Entering "GeomCenter([Geom], 0)" in my step 2 worked. So that filled the new field "Label Centroids" with <NULL>. Then in the second step I created a new Drawing based on the Table but referencing the second Geom field "Label Centroids". This created a drawing of points. Third step I created labels using the new drawing and the property number field. Worked great.

I was confused initially when the new Label Centroids field was filled with <NULL> values. <NULL> also fills new but empty fields so for awhile I thought nothing had happened but create a new but empty field. I started from scratch a couple of times. Then like Indiana Jones in the Last Crusade, on faith only, navigating booby traps to fetch the goblet, I just went ahead and created a new drawing and lo and behold, I had my points.

JIT. Just in time for the meeting tomorrow. I did finish my map earlier in M8 for printing as I needed to add a legend, scale and various text with date, client name, etc. However I have what I need in M9 too.

Thanks!

Manifold User Community Use Agreement Copyright (C) 2007-2021 Manifold Software Limited. All rights reserved.