I know, been there myself. In the very beginning I even used Textboxes for number inputs. But I'd say it's worth the effort. Having not to worry about the conversion forth and back is very comfortable. Something that definitely should be included in the rather sparse "Get started blog".
Original Message:
Sent: 06-06-2024 09:16
From: Fernando Calvo
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi again,
additionally, as I´m calculating a lot of heights, etc based on the picked Z values and showing them in different kind of field such us NumericEdits but also as Labels, etc, knowing now that conversion issue, I will rather change all those fields to DistanceEdits as they will be automatically converted and many TBC functions need those heights also in Metres and not in the current units, so I´ll try to unify...however there are dozens of controls to be changed and hundreds of lines where their value is used, so a sensible and time consuming task, but absolutely necessary.
Thanks again.
Regards,
Fernando
------------------------------
Fernando Calvo
calvo@calvo-geospatial.com
Original Message:
Sent: 06-06-2024 09:06
From: Fernando Calvo
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi Ronny,
thanks so much for your efforts and recommendations and sorry for the confusion.
Please find attached a video, as it´s easier to show this way what I mean and what I was able to clarify through your, Peter´s and Bryce´s feedbacks and recommendations, so thanks a lot for that ! ;-)
Regards,
Fernando
------------------------------
Fernando Calvo
calvo@calvo-geospatial.com
Original Message:
Sent: 06-06-2024 06:34
From: Ronny Schneider
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Do you look at the values in the object watcher? Here you'll get all 3 values always as metres. I's impossible that you get X/Y here in project units, but Z in metres.
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/f06bd8d8b6a84b089745ea759e72281a.png)
If you write them into a simple NumberEdit all 3 willl show up with their value as Meters and you will have to manually convert them, as you showed you do for the z-value. As an example, if you'd just write your Coordinatepicker.X into that Elevation NumberEdit you'll need to do a manual conversion.
Or do you mean the coordinate picker
when you write that you get x and y in project units? That would be correct, since the Edit converts it automatically for you. That's why you see it properly in project units without manual conversion. In the background it's still metres as well.
In regard to the coordinates you usually just don't realize that you work with metres, since you just add the point to a linestring or a new point or DTM..... And since internally everything is saved as Metres anyway you won't have to do any conversion. The conversion is only necessary if you present values to or take inputs from the user in the UI, or an output file.
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/a706048edc3e4b3c8de5ace5f979803e.png)
------------------------------
Ronny Schneider
Original Message:
Sent: 06-05-2024 23:30
From: Fernando Calvo
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi Peter,
thanks for asking and your proposal!
I had tried picking on 2d and 3D views and until now, picking on the point cloud, but I now tried also picking a previous created line just in case, and unfortunately, I still get always the Z coordinate from the CoordinateEdit control in Metres while XY in the current units.
Thanks.
Fernando
------------------------------
Fernando Calvo
calvo@calvo-geospatial.com
Original Message:
Sent: 06-05-2024 13:12
From: Peter Kistler
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Fernando,
Out of curiosity, what view are you picking the objects from? Technically is shouldn't matter, but I'm wondering if it might be a view specific problem.
Peter
Original Message:
Sent: 6/5/2024 1:12:00 PM
From: Fernando Calvo
Subject: RE: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi Ronny,
thanks a lot for your comments and recommendations !
I´ll have a look again to check why I´m getting other values than in your test, however I´m simply reading the XYZ given back from the control as follows:
ctrl = self.coordCtlRefPoint
coord1 = ctrl.Coordinate
dZ = coord1.Z
It has always worked so far for several years until I started supporting International and US Survey Feet (obviously if the most of the values, distances etc are given back in Metres ;-) ), so I need to check it in detail and as you propose, potentially change my NumeriEdit controls used for Z coordinates to ElevationEdits, however those fields are not meant to pick the elevation from there but to pick a point with XYZ and use the XY for some calculations and the Z for others, so I´ll check if it could work this way with ElevationEdit, as otherwise, I would need to pick twice, once for the XY and another one for Z and considering that we are picking a couple of thousand times per day such points, it would not make any sense to duplicate the clicks and time, but let´s see.
Thanks again for your help !
Regards,
Fernando
------------------------------
Fernando Calvo
calvo@calvo-geospatial.com
Original Message:
Sent: 06-05-2024 08:03
From: Ronny Schneider
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi Fernando,
I can't confirm what you're seeing with the CoordinateEdit control.
Simple test, I have a line, in a basic metric project, with a node at 1,1,1.
If I snap to that node while using my point macro the object watcher shows the following.
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/5302ff17f42f46868e9cc4052b9a27a4.png)
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/e3ef55132cf14e938495d4682975c237.png)
And if I switch the project to US survey foot, the object watcher looks exactly the same
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/f06bd8d8b6a84b089745ea759e72281a.png)
while the coordinate picker shows the foot values.
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/4297dfc311894cb989eff457b3d9af22.png)
The issue with your macro is, as Peter pointed out, that you're using the NumericEdit to show the Z-Value. As he wrote, is that one unitless and always shows whatever value you give it in your macro. It doesn't do any unit conversions before it shows it to the user in the UI. Since the CoordinateEdit in the background always uses metres you're always writing pure metres into that box.
The CoordinateEdit, DistanceEdit, ElevationEdit do the appropriate conversion for you, before showing the value on the screen, that's the beauty of those.
The best would be if you'd just change those NumericEdits to Wpf:ElevationEdit. And you're good to go without manual conversions. You'd only have to change the target for the elevation to self.numRefLevelZ.Elevation
in OnLoad you can i.e. set the CoordinateEdit to show the elevation as well.
self.coordpick1.ShowElevationIf3D = True
I only use the NumericEdit to request scale values, decimal places or increment numbers. For all the other values I try to use the appropriate control that does the conversion for me. I've got a few old macros where I did it manually, but I'll see that I'll change them if I have time.
------------------------------
Ronny Schneider
Original Message:
Sent: 06-04-2024 09:21
From: Fernando Calvo
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi Peter,
thanks so much for your reply and feedback !
Yes, I use the ElevationEdit in some masks, however I was reading the Z coordinate from the CoordinateEdit control in some others, so:
ctrl = self.coordCtlLevel
coord1 = ctrl.Coordinate
dZ = coord1.Z
and was surprised that the ctrl.Coordinate.Z is always given back in Metres while the X and Y in the current units settings.
I´ve been adding now the conversion for distances and picked Z values and it´s working fine so far, however I´ll recheck if using an ElevationEdit would be a better approach.
Thanks again.
Regards,
Fernando
------------------------------
Fernando Calvo
calvo@calvo-geospatial.com
Original Message:
Sent: 06-04-2024 09:08
From: Peter Kistler
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi Fernando,
The internal value is always meters for any distance value.
The problem might be the control you are using. The NumericEdit control should be used for unitless numbers. There is an ElevationEdit control which should be used for retrieve elevation / Z values. It uses meters internally but will display the value in the user's preferred units.
Peter
------------------------------
Peter Kistler
Original Message:
Sent: 06-04-2024 07:29
From: Fernando Calvo
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi Bryce,
thanks so much for your quick reply !
Sure, I mean when using an own macro and picking a point from a CoordinateEdit control, not using a standard TBC mask where you pick a point, as it probably gets its conversions before showing the Z coordinate.
For example, if I pick a point somewhere using the standard TBC point info function:
- US Survey Feet
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/5e318684e82843f5a1ed6a5bf241055e.png)
- Metres
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/cf7c34f0b3cf492d9887ec1250e04cd9.png)
However, if picking from an own macro via CoordinateEdit control as follows:
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/0333d1b25d684250b315ff4bdb193aef.png)
and after picking reading the XYZ of the picked point:
ctrl = self.coordCtlRefPoint
coord1 = ctrl.Coordinate
dZ = coord1.Z # in Metres?
The X and Y are correct depending on the current units, however the Z is always the same (in Metres) as you can see below:
- US Survey Feet:
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/0427ce14b6004e93905c9d521d7b5dd2.png)
- Metres:
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/607920116f354c57aeb42aaa5bb4c49b.png)
I hope this clarifies what I mean.
I tried applying the corresponding conversion factor as follows:
def coordCtlRefPoint_ValueChanged(self, sender, e):
ctrl = self.coordCtlRefPoint
coord1 = ctrl.Coordinate
self.lunits = self.currentProject.Units.Linear
self.lfp = self.lunits.Properties.Copy() # create a copy in order to set the decimals and enable/disable the suffix
dConvLinear = self.lunits.Convert(1, LinearType.Display)
dZ = coord1.Z # in Metres
dZ = dZ * dConvLinear # units conversion for Z (in case)
self.numRefLevelZ.Value = Math.Round(dZ,3)
And then I get the expected Z coordinate fitting the current units settings:
Thanks a lot for your support !
Regards,
Fernando
------------------------------
Fernando Calvo
calvo@calvo-geospatial.com
Original Message:
Sent: 06-04-2024 06:59
From: Bryce Haire
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi Fernando,
Can you please give steps to reproduce the issue you are seeing?
I did a simple test and did verify the Z value (elevation) can be read when the units are set to US Survey Foot.
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/73cef8d10e0a44258674ca6874d46433.png)
There is something I am missing in what you are doing, so please let me know what to do to reproduce the issue you believe you are seeing.
Thanks!
------------------------------
Bryce Haire
Original Message:
Sent: 06-04-2024 04:17
From: Fernando Calvo
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi Bryce,
coming back to this topic, I realized that the Wpf:CoordinateEdit reads the Easting and Northing fine (depening on the units set for lenghts) when picking any point, however the Z coordinate is read always in Metres. Could you confirm this please?
It´s a bit confusing as when reading the coordinates of a picked point from that CoordinateEdit control, we can use the XY but need to convert all the time from Metres to i.e. US Survey Feet to get the proper Z coordinate, but afterwards, if needing to create i.e. an horizontal cutting plane at a specific Z coordinate, we need to convert back from Feet to Metres.
Wouldn´t make rather sense to read X, Y and Z from a CoordinateEdit control either all in Metres or all in the corresponding current units?
Thanks.
Regards,
Fernando
------------------------------
Fernando Calvo
calvo@calvo-geospatial.com
Original Message:
Sent: 04-23-2024 21:47
From: Fernando Calvo
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi Bryce,
thanks again for this answer too !
As previously mentioned in my reply to Ronny, I´m already using that class but didn´t find the Convert method, or so far I remember something with "...ToFeet()" or similar but it didn´t work, and therefore I decided to make the conversions myself as it was pretty simple applying a conversion factor.
I´ll have a look at it and try to use the same conversion as TBC internally as it makes sense to avoid confusion when getting minor differences if using the internal TBC conversion factor or a slightly different one as "official" but giving at the end some decimals differences.
Thanks.
Regards,
Fernando
------------------------------
Fernando Calvo
calvo@calvo-geospatial.com
Original Message:
Sent: 04-23-2024 13:47
From: Bryce Haire
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Please look at the Linear class in the Trimble.Sdk.Units assembly.
It should have a Convert method that does what you are looking for.
![](https://higherlogicdownload.s3.amazonaws.com/TRIMBLE/MessageImages/08edae6a5fd644369491df7605f07416.png)
NOTE:
You need to pass a CultureInfo to the constructor. I would advise to use the static System.Globalization.CultureInfo.CurrentCulture
Hope this helps.
------------------------------
Bryce Haire
Original Message:
Sent: 04-23-2024 08:40
From: Fernando Calvo
Subject: Unit conversion inside TBC - Conversion factors used different than "official ones"
Hi,
so far I see the area and length values got back from function such us:
###################################
polyRoom = lRoom.ComputePolySeg()
polyRoom.Area( dArea, ptCentroid, sideDirection)
dLength = polyRoom.Length()
###################################
are always in Metres independently on the current unit settings inside TBC, correct?
As I´m also doing right now my own conversions from metres to Feet and US Survey Feet, as well as SquareMetres to SquareFeet and USSurveySquareFeet for my macros, I realized that TBC is using a different conversion factor than the "official" ones that I found on the internet. I obviously tried first to find existing functions inside the SDK to convert between those units but without success or the ones that I found that could sound to do that, didn´t work.
So, I found on the internet the following conversion factors:
- Metres to International Feet: 3,280839895
- Metres to US Survey Feet: 3,28083343833312
- Square Metres to International Square Feet: 10,76391042
- Square Metres to US Survey Square Feet: 10,7638673611
While if I create some lengths and areas inside TBC and show first the values in Metres and Square Metres and then change the units, I get the following factors comparing both shown values:
- Metres to International Feet: 3,28085 instead of 3,280839895 as above
- Square Metres to International Square Feet: 10,7639 instead of 10,76391042 as above
Could anyone clarify this please? if there is any internal function to convert those values using the same conversion factors as TBC does, even better obviously.
Thanks.
Regards,
Fernando
------------------------------
Fernando Calvo
calvo@calvo-geospatial.com
------------------------------