String Maths Expressions1
String Maths Expressions1
NEW REMARKS
_layer_next_slope >>> to place Gradient from 1st pt. to next pt. in D field.
_STRING_AREA
D1=_file_segment_no
All >> d1>> = FRANDOM() to place a random number between 0 and 1 in desc
field.
String maths
Plan to section
Y=Z
Z=Y
Y=Z
X=Y
Z=X
x= -1 * x
put the volume in the ore blocks in the d4 field using the expression below (d5 contains
the thickness of the ore block). The volume in the string file has a large number of
decimal places, up to 17.
I am also plotting the d4 field on a map and if there are more than 12 decimal places it
plots them all, despite the fact that the number of decimal places in the entity is set to
zero
Try this
D4 = format(d5*_segment_area,2)
X= X=X/10
Y= Y=Y/10
I have imported a set of contours from mapinfo into surpac and would like to assign the z
value to the contours to construct a dtm. The z value is stored in D4 of the first point in
each segment. All the remaining points in each segment have no attributes.
It’s a bit of a trick. Normally when you do things with string maths, you are treating each point
separately. In this case you have something stored in one field of 1 point and you want to apply it
to each point so it’s a bit more difficult. The good news is it can be done.
You have to use two lines in String Maths. See the attached image to see how it is set out. You
must use a temporary field.
4
-----------------------------------------------
New string maths--- text in d fields --- d1 = ‘this is a label’
----------------------------------------
I have a string file with Y, X,Z points with several data fields D1 to D13. Can I create a D14 field
ie a new data field which is the product of D10 and D12 fields without having to reimport a csv file
with the added fields
Yes, you can create a value in the D14 field using string maths in the edit menu.
The question is what is the result you are chasing.
To add the two you would do the following: D14 = D10+D12
To stick the two values together (i.e text) use: D14 = STRCAT(D10,D12)
If you hit the help button on the string maths form and follow the link to expressions you will be
taken to a comprehensive list of mathematical expressions that can be used.
--------------------------------------
_xext*_yext*_zext
I have imported a set of contours from mapinfo into surpac and would like to assign the z value to
the contours to construct a dtm. The z value is stored in D4 of the first point in each segment. All
the remaining points in each segment have no attributes.
I am not sure of the correct syntax to use for this expression “for each segment, z = D4 of first
point
It’s a bit of a trick. Normally when you do things with string maths, you are treating each point
separately. In this case you have something stored in one field of 1 point and you want to apply it
to each point so it’s a bit more difficult. The good news is it can be done.
You have to use two lines in String Maths. See the attached image to see how it is set out. You
must use a temporary field.
----------------------------------------------------------------
The function to look in the reverse direction is
Database>>sections>>reverse view direction.
Aaron here believes this statement should work, please give this a try.
6
iif(d1=1,"RED",iif(d1=2,"MELON",iif(d1=3,"MAIZE",iif(d1=4,"GREEN",iif(d1
=5,"BLUE","")))))
You will note that at the end of the slicing the string files will
have the string numbers the same as the original object …
ie 350.
1. iif(ore==”highgrade”,1,0) where ore is the attribute you want to source from and
highgrade is the text you want to look at.
2. The same argument can be extended for multiple outcomes :
iif(ore==”highgrade”,1,iif(ore==”lowgrade”,2,0))
7
------------------------------------------------
Attached is a typical survey file - the string concerned is 575. There are 3 different
segments with D1 = xxx. This is to be deleted and everything else remains - or even on
the rest of string 575 is to be placed into a separate file. The string 575 is then used in
running a macro for drive solid modelling minus the 'xxx' segments. I need the 'xxx'
segments to remain as string 575 for processing by others.
Z = iif(d1==”xxx”,0,d1)
This says if d1 is xxx then make the z value 0. You can then quickly check the result to make sure
that it is correct and delete the information that is not required.
Whenever using string maths you must put all character based entries in double quotes
eg d1 = “Stage 4”
-------------------------------------------------
We have some problems, using Surpac 5.1, with Arc View shape files after
the importation.
The string file created has a lack of data. Only the first points of the
segments have descriptions. It keeps the coordinates but with no
descritions.
You can use layer maths or string maths to set the elevations for each
point. See below
frm00702={
strrange="Y"
}]
----------------------------
I'm trying to change some descriptors in a string file, it has a
character descriptor and I want to change in a numeric descriptor...
You could see in the attached file, I have in the 2nd descriptor
geological information as a character and I want to have it like numeric
information to have each string like a different geological unit...ex
Unidad 4----string 1
Might be a bit messy, depends how many codes you have. There will be a
limit to how many characters can be entered into the STR MATHS field.
1. Create D3 = D1-90
2. Create new string file (bodi1.str) from your old string file
(bodi11.str) using string maths: x = x + l*SIN(D1/180*3.14);
y=y+l*COS(D1/180*3.14)
3. Use GEODIP, GEODIP2 entities and GEODIP map for your string
file
-------------------------------
How do you write an expression in block maths to assign a value of
attribute mcost = $11,500 to all blocks east of co-ordinate y=5550 and
above RL= 499?
9
- Create the attribute mcost if you have not already done so.
can you create a D1 field entry in every point on a segment , with the
distance along the segment , as in chainage from 0.0 being the start
point chainage ?
Just use Edit >> Segment >> Maths and follow the form below and then
select the segment you want to apply chainages to. Note in the 3rd
expression I have used the format qualifier to format the result to 2
decimal places – you may want to change this.
Au_OZ = (_xext*_yext*_zext*sg*au)/31.1034
Expression
The syntax that you need in your new calculated attribute or just using
block maths is:
New_attribute=
iif(numproduit=”lp”,2,iif(numproduit=”lv”,3,numproduit))
You can use the layer maths function to asssign the x value of the FIRST point in a
segment to the d1 fields.
To concatenate two fields together you can use the layer maths for that as well. Use the D1 field
and an expression of STRCAT(D1,D2).
As for your suggestion on naming the D1 field something more useful, the file structure
of a string file is the reason why they are called D1,D2,...
This allows the surpac user to have a greater flexiblity to store information. If we were to
have fields like "GRADE" then not all users would use that and the string files would
become too large.
--------------------------------------------------------------------------------
The file was generated by importing a MapInfo table of ground contours, which had the Z value
stored in a separate field in the table. It appears that the import process has only assigned this Z
value to the D1 field of the first point of every segment. I would like to assign this D1 value to the
Z of every segment/string. Can you suggest a way of achieving this?
Constraint = _first_string_point
Field = tmp1
Expression = D1
This first line puts the value of the d1 field of the first point into a temporary field.
12
field = z
Expression = tmp1
This will assign the value stored in tmp1 to the z of all the points so long as you have the
constraint blank.
I was wondering how to get field and then note. In the file attached I wwould like it to look like
'0.75g/t' not how it is displayed now as G/T0.75 how do I do this? ALso I want to display string
segment 12.1, 12.2 etc how do I do I seem to get 12.0 please look at my entity in the attachment.
Unfortunately the note+field only works by putting the note part first, then the field. As a way
around this, you could use string maths and setup and equation such as:
D2 = STRCAT(d1,”g/t”) - assuming your grade is stored in the D1 field. This will concatenate the
two values together to form one string. Then you just need to plot the field d2.
I think the problem with the segment number is that programmers start counting from 0 so the first
segment is actually segment 0. Again I would probably use string maths to put the value into a
description field and then plot that description field.
13
For example:
D3 = STRCAT(_file_string_no,”.”,_string_segment_no)
---------------------------------------------------------------------------------------------
Does anyone out there have a nice method for creating DTM’s from vertically oriented string
files? I have an Xplorpac client that would like to import vertical sections of IP data into Xplorpac
as text files. The client would then like to build DTM’s and colour these DTM’s by the attribute
that he has stored in the d1 field.
I have considered contouring (since these can be re-transformed into a sectional orientation after
contouring is complete) but would prefer to use DTM’s. I understand why this will not work with
the standard DTM tool and if anyone can offer me a work around I would appreciate it greatly.
Please see the attached image for an example of what I would like to do (except that the
attached image is the sectional data already rotated into plan view).
If you transform the section to plan, then create a DTM, you can
use layer maths on the DTM layer to transform the DTM back to
section in the same way as you suggest for contours and
the triangles will be transformed to be vertical instead of
horizontal.
I am generating a file for uploading to a Survey instrument and wish to place the value 1A, 2A, 3A
etc in the D1 field of each successive point. I thought I would be able to use the STRCAT function
to do this as in: STRCAT(_string_point_no, A) to do this.
The problem here is that Surpac is looking for some kind of field value called A, which of course
does not exist. If you want to use a string of text, you need to enclose it in quotations.
D1 = STRCAT(_string_point_no,”A”)
The file was generated by importing a MapInfo table of ground contours, which had the Z value
stored in a separate field in the table. It appears that the import process has only assigned this Z
value to the D1 field of the first point of every segment. I would like to assign this D1 value to the
Z of every segment/string. Can you suggest a way of achieving this?
Constraint = _first_string_point
Field = tmp1
Expression = D1
This first line puts the value of the d1 field of the first point into a temporary field.
on the next line do the following:
field = z
Expression = tmp1
This will assign the value stored in tmp1 to the z of all the points so long as you have the
constraint blank.
Could you please confirm the following is true: “not < 48.5” is the same as “>=48.5”. Testing it
with a block model seems to indicate that it is the same, but am not 100% sure.
Yep. Logic is absolutely correct. In fact thats how Surpac records it when you do it in a macro
------------------------------------------------------------------------------------------------------------
When using string maths to make D1 = point number ('ptno') actual point number changes to ptno not the
point number as help suggest.
The use of 'ptno' is for use with the old string maths function which is still available use, however
does not provide a great deal of functionality. The new string maths uses the following format:
d1 = _string_point_no
@slope is the option you want to use in the create centroids from dtm
> triangles function, with Z as the required field.
>
> This will create a string file with z representing the slope of the
> triangles.
>
> You have several options from here, you could use string maths to copy
> the slope into a dfield and then drape the string file over the dtm.
>
> Another possibility is to do a countour of the raw string file and
> then drape the resultant contour lines.
Is there a way to truncate a string using string maths? For example I have d1 = 16/01/2007 and I
only want it to say 16/01
This should be possible. To give you a head start on figuring it out, you need to use the string
handling functions in the expression toolkit. Something like this should work, or at least go close:
15
To explain how this works, rindex(d1, "/") returns the offset to the last instance of / in the d1 field
substr gives a substring of the d1 field starting at offset 0, the start of the string, for a length of the
value returned by the rindex() function. In the example you provided rindex() will evaluate to 5 so
the the resultant string will be "16/01" which is what you want.
Now this may not work if the D1 field DOESN'T have / characters. If you need to make it bullet-
proof you should use an iif() expression as well.
Could you please look at this file and suggest any way of automatically
> calculating the dip run North South and East West between each points.
For getting the values E-W, I sorted your string file in Excel and then
made a string file and then string maths again.
I was wondering whether I could just rotate the blk model data by bearing about a point and then
shift it manually so no scale factor is involved….. have to make sure I get the right matching co-
ords first.
The scale factor formula would be: (new cords) Square root((x1-x2)2 + (y1-y2)2) / (old cords)
Square root((x1-x2)2 + (y1-y2)2) = ~1
Please advise if there is an option to CONCATENATE D-fields using string maths: say, d1 is
“CH00” and d2=_string_id. I’d like to get d3=CH001.
You can use STRCAT (d1,d2), which will give you the desired result
This should write the first point values in the d1 field in all of the z values for all strings.
Layer Maths-
16
What we are chasing is to scale the contour plan in the x direction only. Points of reference will be
each end of the most southern contour and approximately 81.5% from the right hand side,
Sorted out the problem with a simple formula (applying string maths)
x = iif(x<10000,0.181*(10000-x)+x,x)
1. To place the accumulated 2d distance along a string in the D1 field, and the complete
distance along the string in the D2 field the following can be used:
D1 _tmp1
_string_D2 _tmp1
17
1. If string 1 has the grade for each point in D1 with missing values being set to -1 then the
average grade for each segment can be calculated to D2 using the first block of
expressions below. The second block places the grade as a percentage of the average
grade for the segment in D3 with missing values set to nothing. Note that the second
block is started by a non-blank string range value and is not processed until after all the
points have been processed with the first block.
1 _first_segment_point _tmp1 0
_first_segment_point _tmp2 0
D1 < 0 D3 ""
all X Y
Y X
Note that since the fields for a point are not assigned until after all expressions for the
point are calculate it is not necessary to use a temporary when swapping values.
18
is there a TCL command for rounding numbers to x decimal points? In the old CMD language I
used to use the INT command to round numbers – this doesn’t work for me in the TCL language.
d3 = _segment_ave_x
d4 = _segment_ave_y
d5 = _segment_ave_z
this will give the average x, y, and z of all the segments you select and put the result in the d3 ,
d4 and d5 fields
19
1) appending the string data from all solids into one file (let’s just call it alldata.str)
2) create a DTM from alldata.str using all strings as spot heights
3) use DTM boundary to get the convex hull of alldata.dtm
4) set Z value of the resultant string using string maths (if needed)
String Maths allows you to modify the data in a string file (or a number of string files)
replacing the fields associated with each point (x, y, z, and the description fields D1, …)
with values calculated using generic expressions.
Similarly, the GRAPHICS variants all work on the current active layer, or the selected
portions of the current active layer. All these functions also use generic expressions.
Note: These functions are enhanced versions of the older, redundant functions. The older
functions are still available so that any existing macros which use them will still run
correctly although the menu options will invoke the new function instead of the old ones.
The old functions that relate to these new functions are :
20
STRING MATHS
GRAPHICS STRING MATHS
GRAPHICS SEGMENT MATHS
GRAPHICS POINT MATHS
Choose String Maths from the File Tools menu to display the STRING MATHS form,
or select one of the Edit->(graphics part type)->Maths functions to display the
GRAPHICS STRING MATHS form.
Specify the range of files to be processed by entering the Location and ID Range. This
field has no bearing on the GRAPHICS functions and so does not exist on the form.
Define the Location code for the range of files to be created. This Location can be the
same as the Location given above if you desire the output files to have the same names
as the input files.
This field has no bearing on the GRAPHICS functions and so does not exist on the form.
A scrolling region exists for defining the expressions to be assigned to fields. The
columns in this scrolling region are:
String Range
The range of strings to apply this assignment and the assignments in subsequent rows up
to the next non-blank String Range. The special value of "all" can be used to indicate that
the range applies to all strings in the file.
The string range field only applies to the STR MATHS and GRAPHICS LAYER MATHS
functions, all others do not display this field.
Each block of assignments for a particular string range is completely processed before the
next string range is considered. In this way it is possible to calculate the average grade for
each segment and assign it to a _segment_Dn field and then use that average grade value
in a block of assignments for a later string range.
Inappropriate use of non-blank string ranges, especially all, can cause very different
results to what might be expected. Results of an operation are committed as soon as a the
next non-blank range is encountered, or the last operation is processed. Inappropriate
placing of non-blank string ranges may cause operations to produce unexpected results.
This example swaps the contents of the X and Y fields by first assigning the the X field to
the Y field. Recall that this operation is not committed at this time because if it were then
both the X and Y fields would contain the value of the X field. The Y field is then
assigned to X field. As this is the last operation the results are now committed to the
target fields.
This example attempts to swap the contents of the X and Y fields as in the above
example. The result though is not as expected because the presence of a non-blank range
for the second operation causes the first operation to be committed. The outcome is that
the X and Y fields both contain the same value, that of the original X field.
Constraint
An extra constraint to limit which points will be updated using this assignment. This is a
generic expression which must have a boolean value. As an example the Constraint can
be used to limit the assignment to the first point in each segment, or to only apply the
assignment to closed segments.
Field
The field to be assigned with the result of the following expression. The field can be one
of X, Y, Z, or Dn where n is an integer greater than or equal to one. Dn represents the
nth description field. As well as these values for the fields of a point they can be prefixed
by _segment_ , _string_, or _file_ to update the field for all the points in the segment,
string, or file respectively. When these special prefixed fields are used the expression is
calculated at the end of processing for the respective segment, string or file and then the
22
field in all the associated points is update. That is rows assigning explicit point fields are
completed for each point of the segment, string or file before the expression for segment,
string, or file fields is evaluated. Within the assignments for a given string range it is also
possible to use temporary variables known as _tmp1, _tmp2, … to store intermediate
values.
Expression
The expression whose result will be assigned to the indicated field. The variables which
can be used in an expression are detailed below:
X The value of the X coordinate of the point
Y The value of the Y coordinate of the point
Z The value of the Z coordinate of the point
The value of the nth description field for the
Dn
point
The value of the nth temporary variable for this
_tmpn
string range grouping
An aggregate value of the form:
_<entity>_<value>
Return a calculated value for the current file,
<entity> is one of file, segment, or
string, or segment. The values which can be
string, and
returned are the total area, 2d length, 3d length,
or a true/false value depending on whether or not
<value> is one of area, 2dlen, 3dlen,
all the segments are closed.
or closed.
<field> is one of x, y, z, or Dn. the segment (excluding the final closing point). If
one of these values is used for the first point in
For example, the x coordinate for the an open segment it returns zero.
previous point is given by: _prev_x
_next_<field> Return the value of the field for the next point in
the segment. If one of these values is used for the
where: last point of a closed segment (excluding the
final closing point) it returns the value for the
<field> is one of x, y, z, or Dn. first point in the segment before any assignments
were made to the first point. If one of these
For example, the x coordinate for the values is used for the last point in an open
next point is given by: _next_x segment it returns zero.
A derived value of the form:
The last point for closed segments is a repeat of the first point. This point is not processed
like the other points in a segment and is set to have the same x, y, z and description fields
as the first point in the segment. This allows expressions used to accumulate values to
ignore any special processing for the last closing point in a closed segment. Thus it is not
possible to change a closed segment to an open segment or vice-versa using string maths.
Examples
1. To place the accumulated 2d distance along a string in the D1 field, and the
complete distance along the string in the D2 field the following can be used:
String Range Constraint Field Expression
all _first_string_point _tmp1 0
D1 _tmp1
_tmp1 _tmp1 + _next_2dlen
_string_D2 _tmp1
2. If string 1 has the grade for each point in D1 with missing values being set to -1
then the average grade for each segment can be calculated to D2 using the first
block of expressions below. The second block places the grade as a percentage of
the average grade for the segment in D3 with missing values set to nothing. Note
that the second block is started by a non-blank string range value and is not
processed until after all the points have been processed with the first block.
String
Constraint Field Expression
Range
1 _first_segment_point _tmp1 0
_first_segment_point _tmp2 0
D1 >= 0.0 _tmp1 _tmp1 + D1
D1 >= 0.0 _tmp2 _tmp2 + 1
IIF(_tmp2 > 0, _tmp1/_tmp2,
_segment_D2
0.0)
IIF(D2 != 0.0, D1/D2*100.0,
1 D1 >= 0 D3
0.0)
D1 < 0 D3 ""
3. To swap the x and y fields:
String Range Constraint Field Expression
all X Y
26
Y X
4. Note that since the fields for a point are not assigned until after all expressions for
the point are calculate it is not necessary to use a temporary when swapping
values.
Examples comparing of the old STRING MATHS and the new STR MATHS
functions
Using string maths d1=_string_point_no then I would say d2= 308+d1 (as your starting
point number)
Blk maths.
As discussed on the phone. I have a str file (blast pickup) which all the correct holes numbers
that i have picked up in the field for individual holes have been saved into the D1 field. The string
file attached contains the blast boundary and every 5 diagonal line through out the the shot.
I used to be able to use the grade control function in design,hole numbers options, create new
points etc which would insert the right number of holes between the diagonal lines ( 4 holes with
the correct id's). As the function uses only the point id not the D1 field. Is there a way around
this???? Can i make point number = D1! and use the above function.
. You don’t need to do string maths for this. Infact the function wants the hole name in d1.
Only problem being that hole numbers less than 100 become 091,034,025 for example. This will
produce a result similar to what you see below. Is this what you were hoping to achieve?
In the example above we are taking the Z value from string one, putting it into a temporary field
and then make the z value on string 2 equal to this temporary field. This is a good way to copy
data between one string and another.