what is wrong with this formula?
I have run the "chainage" tool on a set of points that are close to a line so that the point attributes now include DIST_TO_LINE and SIDE_OF_LINE. SIDE_OF_LINE is either "L" or "R".
I want to convert the distances on the left side to negative so have created a calculation for a new attribute "OFFSET" which is calculated using the following
IF((SIDE_OF_LINE = 'L'), (-1*DIST_FROM_LINE),(DIST_FROM_LINE))
When I run this, all OFFSETS end up being negative.
When testing, it seems as that the IF statement isn't working. The second option never gets applied. I tried it with the "extra" brackets and without. Also IF and if.
Comments
-
Hi Ron,
Not sure what's going on with that particular formula -- it looks fine, and it should work, though. I made up an example in version 24.0, and it appeared to work fine. Not sure what version you're using; it might help to add that information here.
Beyond that, it looks like you're looking to make the new OFFSET attribute always be positive. In that case, you should be able to use the following simpler formula that takes the absolute value of the distance, and is always greater than or equal to 0:
ABS( DIST_FROM_LINE )
I'll note that I wrote the original extended formula stuff, but I'm not working for Blue Marble any longer, so I don't have access to the code for debugging purposes, and I don't have a more recent version of Global Mapper.
Hope that this helps,
~Jeff
-
Hi Jeff,
Thanks for looking at it.
I am also using 24.0.
To clarify, I am trying to make a new OFFSET negative if the it is on the left side of the line (SIDE_OF_LINE = L), otherwise it will stay as it is (positive).
-
Hi again - OK, still unable to replicate the problem. I did this:
Loaded a .shp file consisting of areas that I had handy. The file had, for each polygon, a 'SHAPE_AREA' attribute. In order to make a SIDE_OF_LINE attribute, I used the following, somewhat arbitrary, formula:
if ( Shape_Area < 100000, "L", "R" )
. This resulted in some labelled with 'L', and the rest with 'R',Then I tried a number of variations to add a OFFSET attributes, to test other scenarios: using "L" rather than 'L', removing extraneous parentheses, using a simpler result, etc.:
IF( (SIDE_OF_LINE = 'L'), (-1*SHAPE_AREA), (SHAPE_AREA) )
IF( (SIDE_OF_LINE = "L"), (-1*SHAPE_AREA), (SHAPE_AREA) )
IF( SIDE_OF_LINE = 'L', -SHAPE_AREA, SHAPE_AREA )
These all worked as expected: each of the new attributes (e.g. 'OFFSET', 'OFFSET2', 'OFFSET3', etc.) all had negative values when its associated 'SIDE_OF_LINE' attribute was 'L' (or "L").
I'm a bit at a loss to explain what's happening in your case.
~Jeff
-
One more thing --
I wasn't familiar with the chainage stuff, so I looked into it and figured out how to do it. Loaded a point layer, and created a new line that ran through the point layer. Then I selected all the points and the line, and ran the chainage functionality, and wound up with a new layer of line (which are irrelevant to our example). Looked at the point layer's attributes, and saw that the SIDE_OF_LINE and DIST_FROM_LINE attributes had been added, with some SIDE_OF_LINE attributes being 'L', and the others 'R'. So far so good.
Then I opened up the attribute calculator on the point layer, and ran the exact formula that you gave initially (
IF((SIDE_OF_LINE = 'L'), (-1*DIST_FROM_LINE),(DIST_FROM_LINE))
) being used to generate a new OFFSET attribute.. This resulted in a OFFSET values that were negative for items with the SIDE_OF_LINE = 'L', and positive for the others.So again, this seems to be working. This is in version v24.0 (b072922). I'm a puzzled as to why it's not working for you.
best regards,
~Jeff
Categories
- 12.8K All Categories
- 5.7K Features Discussion
- 345 Downloading Imagery
- 1.3K Elevation Data
- 385 Georeferencing Imagery Discussion
- 636 GM Script Language
- 54 User Scripts
- 114 GPS Features
- 417 Projection Questions
- 825 Raster Data
- 1.3K Vector Data
- 6.6K Support
- 178 Announcement and News
- 912 Bug Report
- 558 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 569 Other Discussion
- 131 GIS Data Sources
- 27 Global Mapper Showcase
- 238 How I use Global Mapper
- 107 Global Mapper Forum Website