Jump to content
Sign in to follow this  
Dexie

How to display Record data attached to polygons

Recommended Posts

I have just imported some shape files exported from a GIS system. The information comes in three parts -1. Area, 2. contours, 3. anno.

Each of these catagories has - .dbf, prj, sbn, sbx, shp, shp.wml, shx components.

The shape file for 3. anno (annotation) displays lots of single ploygons which represents the position of text for the map eg. road names. In the Object Info pallet under Data there is a record attached to each polygon which includes a field called DescTerm which includes the text that should be located on the appropriate polygon.

eg.

Toid: 1000000969961542

Featcode: 10169

Version: 2

VerDate: 2007-07-27

Theme: Road Tracks and Paths

Change: 2007-07-06 Modified

textangle: 310.0000000000

DescGroup: Road Or Track

DescTerm: Road Name or

make:

PhysLevel: 50

PhysPres:

Text: SOUTHBROOK ROAD

textfont:1

textpos: 4

textheight: 3.00000000000

shape_Leng: 0.00000000000

Is there a routine that will display the correct text eg. (Text: Southbrook Road) from attached records onto the drawing in the location of its polygon from the database file.

Share this post


Link to post

Doable as static text, but I don't know of any publicly available, free routines for this. I'm not allowed to post my VectorScript-routines here: it is too annoying to some members, because I claim ?.

Share this post


Link to post
I'm not allowed to post my VectorScript-routines here: it is too annoying to some members, because I claim ?.

Geez ... would you get over it !

Nobody is beating you with a stick... you have the right to put a little ? on anything and everything you so desire.

So Just Do It ...

You may be the most dysfunctional & annoying of all contributors but your knowledge transcends your need for self-flagilation.

Dexie is asking for our advise and assistance ... let's not let that little ? stand in the way of it.. ; )

Share this post


Link to post

I don't think the above was in professional and polite tone.

Besides, I've helped as much as I can: I don't know of such a free and publicly available routine; the question was "is there?"

Share this post


Link to post

Dixie,

I think some of us who have been doing computer programming for a long time have an idea of how to do this.

But should we give the answer for free? I cannot see a person coding for hours or days without any incentive.

Bill Gates did not become the richest man by giving software for free. When I created the Wallframer script for

MiniCad, which is now Vectorworks, the incentive was not only to make it work but also to profit from it. In my

opinion, the only purpose of free software nowadays is to gain market share.

Luckily for you, I already had created such a script for my own purposes and I do not mind sharing it. But since

I am giving my script for free, the only thing I can come away with is the satisfaction that I helped someone.

For the scipt to work, you will need to do the following:

1. Change the order of the fields so that the name field is at the top (i.e. the top field is "Text"). In the Resource

Browser, look for the record format attached to the polys. Edit the record and move the "Text" field to the top.

2. In the Vectorscript Plug-in Editor, create a new tool and give it a name. Click on the script button and paste

the following:

PROCEDURE LabelShape;

{Debug}

CONST

kFLDNO = 1;

kTHICK = 20;

kHGLIT = 7; {Highlight color = Red}

kTEXT = 10;

TYPE

U_Pt2D = STRUCTURE

x: REAL;

y: REAL;

END;

VAR

classColor,classThick: BOOLEAN;

thick: INTEGER;

colorR,colorG,colorB: LONGINT;

hglitR,hglitG,hglitB: LONGINT;

prvLabel,curLabel: STRING;

labelVec: VECTOR;

prvShapeHdl,curShapeHdl,labelHdl: HANDLE;

mouse,tmp,pt1,pt2: U_Pt2D;

FUNCTION GetlabelField(objHdl: HANDLE; VAR fieldVal: STRING): BOOLEAN;

VAR

result: BOOLEAN;

rec: HANDLE;

recName,fldName: STRING;

BEGIN

result:= FALSE;

IF NumRecords(objHdl) > 0 THEN

BEGIN

rec:= GetRecord(objHdl,1);

recName:= GetName(rec);

fldName:= GetFldName(rec,kFLDNO);

fieldVal:= GetRField(objHdl,recName,fldName);

IF Len(fieldVal) > 0 THEN

result:= TRUE;

END

ELSE

fieldVal:= 'No Record';

GetlabelField:= result;

END;

BEGIN

PushAttrs;

TextJust(2);

TextVerticalAlign(5);

prvShapeHdl:= NIL;

labelHdl:= NIL;

prvLabel:= '';

ColorIndexToRGB(kHGLIT,hglitR,hglitG,hglitB);

GetMouse(tmp.x,tmp.y);

Repeat

GetMouse(pt1.x,pt1.y);

IF labelHdl <> NIL THEN

HMoveBackward(labelHdl,TRUE);

curShapeHdl:= PickObject(pt1.x,pt1.y);

IF curShapeHdl <> NIL THEN

IF GetType(curShapeHdl) = kTEXT THEN

curShapeHdl:= NIL;

IF labelHdl <> NIL THEN

HMoveForward(labelHdl,TRUE);

IF curShapeHdl = NIL THEN

BEGIN

SetCursor(arrowC);

curLabel:= 'No Object';

IF prvShapeHdl <> NIL THEN

BEGIN

IF classColor THEN

SetPenColorByClass(prvShapeHdl)

ELSE

SetPenFore(prvShapeHdl,colorR,colorG,colorB);

IF classThick THEN

SetLWByClass(prvShapeHdl)

ELSE

SetLW(prvShapeHdl,thick);

prvShapeHdl:= NIL;

Redraw;

END;

IF labelHdl <> NIL THEN

BEGIN

DelObject(labelHdl);

labelHdl:= NIL;

Redraw;

END;

END

ELSE

BEGIN

NameClass(GetClass(curShapeHdl));

IF curShapeHdl = prvShapeHdl THEN

BEGIN

IF NOT GetlabelField(curShapeHdl,curLabel) THEN

BEGIN

IF Len(curLabel) = 0 THEN

curLabel:= 'No Data';

END;

IF (tmp.x <> pt1.x) | (tmp.y <> pt1.y) THEN

BEGIN

SetCursor(smCrossC);

IF labelHdl <> NIL THEN

DelObject(labelHdl);

TextOrigin(pt1.x,pt1.y);

BeginText;

curLabel

EndText;

labelHdl:= LNewObj;

SetFPat(LNewObj,0);

tmp:= pt1;

Redraw;

END;

END

ELSE

BEGIN

IF prvShapeHdl <> NIL THEN

BEGIN

IF classColor THEN

SetPenColorByClass(prvShapeHdl)

ELSE

SetPenFore(prvShapeHdl,colorR,colorG,colorB);

IF classThick THEN

SetLWByClass(prvShapeHdl)

ELSE

SetLW(prvShapeHdl,thick);

END;

classColor:= IsPenColorByClass(curShapeHdl);

IF NOT classColor THEN

GetPenFore(curShapeHdl,colorR,colorG,colorB);

SetPenFore(curShapeHdl,hglitR,hglitG,hglitB);

classThick:= IsLWByClass(curShapeHdl);

IF NOT classThick THEN

thick:= GetLW(curShapeHdl);

SetLW(curShapeHdl,kTHICK);

IF NOT GetlabelField(curShapeHdl,curLabel) THEN

BEGIN

IF Len(curLabel) = 0 THEN

curLabel:= 'No Data';

END;

prvLabel:= curLabel;

prvShapeHdl:= curShapeHdl;

SetCursor(smCrossC);

IF labelHdl <> NIL THEN

DelObject(labelHdl);

TextOrigin(pt1.x,pt1.y);

BeginText;

curLabel

EndText;

labelHdl:= LNewObj;

SetFPat(LNewObj,0);

tmp:= pt1;

Redraw;

END;

END;

Until Mousedown(mouse.x,mouse.y);

IF (curLabel = 'No Record') | (curLabel = 'No Data') THEN

BEGIN

IF classColor THEN

SetPenColorByClass(curShapeHdl)

ELSE

SetPenFore(curShapeHdl,colorR,colorG,colorB);

IF classThick THEN

SetLWByClass(curShapeHdl)

ELSE

SetLW(curShapeHdl,thick);

curShapeHdl:= NIL;

IF labelHdl <> NIL THEN

BEGIN

DelObject(labelHdl);

labelHdl:= NIL;

Redraw;

END;

END;

IF curShapeHdl <> NIL THEN

BEGIN

SetCursor(smCrossC);

tmp:= pt1;

Repeat

GetMouse(pt2.x,pt2.y);

IF (tmp.x <> pt2.x) | (tmp.y <> pt2.y) THEN

BEGIN

labelVec[1]:= pt2.x - pt1.x;

labelVec[2]:= pt2.y - pt1.y;

IF labelHdl <> NIL THEN

DelObject(labelHdl);

TextRotate(Vec2Ang(labelVec));

BeginText;

curLabel

EndText;

labelHdl:= LNewObj;

SetFPat(LNewObj,0);

tmp:= pt2;

Redraw;

END;

Until MouseDown(mouse.x,mouse.y);

IF classColor THEN

SetPenColorByClass(curShapeHdl)

ELSE

SetPenFore(curShapeHdl,colorR,colorG,colorB);

IF classThick THEN

SetLWByClass(curShapeHdl)

ELSE

SetLW(curShapeHdl,thick);

SetDSelect(labelHdl);

END;

PopAttrs;

END;

Run(LabelShape);

3. Click OK to accept the script.

4. Add the tool that was created to your workspace. If you did not assigned it to a group, it will be under

Miscellaneous.

5. After selecting the tool, the first click will activate the script, If you are over the polygon, the value of the first

field will appear. If you click in an open space, the string "No Record" will appear. During this time, you can

move the mouse around and it will pick up the name as you get closer to a polygon.

6. Click again to set the center of the string. After clicking, the string will stay in its place. If you move the

mouse to the left and in a circular motion, you will see the string move around its center. If you double click

instead of a single click, the angle of the string will be zero, which means it will stay horizontal.

7. Click again to set the angle of the string.

Repeat steps 5 to 7 until you finish labeling all the streets.

Another solution to this, of course, would be to reverse-engineer what Esri does to label all the polygons at

once. This was something I was not willing to spend the time doing.

Enjoy!

Share this post


Link to post

I forgot to mention that the text will be displayed with the document default attributes. So before running the script click on an open space and set the default text font, size and style you want the field value to display.

Share this post


Link to post

Sorry to take so long in replying. I have been on holiday for a week or so. Thanks very much for the reply and I will give it a try and would like to thank you in advance for your generous help.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...