What's new

Welcome to the GSA Community!

This is the Official User Community for GE's GeoSpatial Analysis products. By registering with us, you'll be able to discuss, share and private message with other members of our Community.
Registration is currently only allowed with a personalized invitation code, which you might have received previously. If you haven't got one:
please get in touch with your GE contact person or your regional moderator(s): see FAQ.

SignUp Now!

GSA 5.2.7. Pro, Finding the nearest neighbour within two or more classes

Björn Schaefer

Member
Confirmed GSA Customer
Joined
Oct 26, 2020
Messages
91
I have a given Point - Object with some attributes and of course a point geometry.
Now i want to find out, if its position is nearer to a line-object "type A" or "type B":

In Example:

1624438559237.png

the red dot shows the position, yellow lines is "type A", green doted lines "type B"

I may find the shortest, direct connection by something like this:
1624438772050.png

and then (Step 2)

1624438819950.png

the next neighbour...

this leads to an object like this:

1624438898579.png

But this one does not show directly, wich line-object is the closer one, so that there is no direct way to grab the ID of "type A" or "type B".

So I've tried to "calculate" the nearst Object afterwards by using incapsulated if Statements...
1624439178663.png

unfortunately, this is not working correctly... plenty of "TBM Objekt ID rechnerisch" is 0, though there are values "TBM Obj ID LA" or "TBM Obj ID HA LA" to choose

1624439315932.png


for easier copy & paste:

{
var LAID = [Befund Gas La Id Haa Id].[TBM Obj Id LA];
var HAID = [Befund Gas La Id Haa Id].[TBM Obj Id HA LA];
var KEHA = [Befund Gas La Id Haa Id].[Kürzeste Verbindung (2)];
var KELA = [Befund Gas La Id Haa Id].[Kürzeste Verbindung];

var TBMID = IF(HasValue(LAID) AND (Not (HasValue(HAID))), LAID,
IF(HasValue(HAID) AND (Not (HasValue(LAID))), HAID,
IF(HasValue(LAID) AND HasValue(HAID) AND KELA < KEHA, LAID, HAID
)
)
);

return TBMID;
}

Anyone an Idea, what's wrong here OR EVEN BETTER how to set up the analysis to find the nearest neighbour directly ?!?! :)
 

Frank Pistorius

Spatial Eye
Confirmed GSA Customer
Joined
May 26, 2020
Messages
36
Hi Björn,

It is indeed possible to solve this using the nearest analysis blocks, though its main purpose is a single (step) nearest analysis.

The expression could be changed to something like:

{
# ID of LA
var LAID = [Befund Gas La Id Haa Id].[TBM Obj Id LA];
# Distance of LA
var KELA = [Befund Gas La Id Haa Id].[Kürzeste Verbindung];

# ID of HA
var HAID = [Befund Gas La Id Haa Id].[TBM Obj Id HA LA];
# Distance of HA
var KEHA = [Befund Gas La Id Haa Id].[Kürzeste Verbindung (2)];

# Return the ID of the element with the smallest distance (larger than 0)
var TBMID = IFConvert(KELA > 0 && (KEHA = 0 OR KELA < KEHA), LAID, KEHA > 0, HAID, 0);

return TBMID;
}

This checks whether there is a KELA value larger than 0 (length of LA) and checks whether it is still smaller than the length of HA.
In that case, the ID of LA is used. Otherwise, the ID of HA is used (in case it has a proper length set).
The backstop id is 0, but you can change that to any value.

Since I don't have a project/data, I was not able to verify the expression. So, hopefully, there are no typos in there.

Another possible solution is to set this up as a business collection.
In case you want an example of that, please let me know and I'll try to cook up a sample project.

Regards,

Frank
 
Last edited:

Björn Schaefer

Member
Confirmed GSA Customer
Joined
Oct 26, 2020
Messages
91
Hi Frank!

Thanks for your quick response, unfortunately there is a parser error shown

1624447940498.png
 

Frank Pistorius

Spatial Eye
Confirmed GSA Customer
Joined
May 26, 2020
Messages
36
Hi Björn.

It appears that the IfConvert() function is not available during these expressions.
You can convert this to use multiple IFs instead. Something like:

IF(KELA > 0 && (KEHA = 0 OR KELA < KEHA), LAID, IF(KEHA > 0, HAID, 0));

Hope this does work.

Regards,

Frank
 

Björn Schaefer

Member
Confirmed GSA Customer
Joined
Oct 26, 2020
Messages
91
this is an export for that example, you may try
 

Attachments

  • Befund_Gas_TBM_Objekt_ID2.zip
    12.9 KB · Views: 0
Top