question

Kadircan T avatar image
0 Likes"
Kadircan T asked Kadircan T commented

Connecting GIS Points from Global Table

Network_Test.fsmHello,

I created points on GIS Module by Script as follows;

Table points = Table("Locations");
Model.find("GISNavigator").subnodes.clear();
for (int i = 1; i <= points.numRows; i++) {
    string id = points [i][1];
    double lat = points[i][2];
    double long = points[i][3];
    Object point = Object.create("GIS::Point");
    point.setProperty("Latitude", lat);
    point.setProperty("Longitude", long);
    setname(point, id);
}


I want to connect points according to the "Connections" global table according to cells that contains value "1"

for (int i = 1; i <= routes.numRows; i++ ) {
    for (int j = i+1; j <= routes.numCols; j++ ) {
        if    (routes[i][j] == 1 ) {
        contextdragconnection ( connections[i], connections[j], "A");
        }
    }
}

I tried to connect with contextdragconnection command but failed. How should I update my script?

Thank you,

FlexSim 23.1.1
flexsim scriptnetworkgis map
network-test.fsm (28.0 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Felix Möhlmann avatar image
1 Like"
Felix Möhlmann answered Kadircan T commented

I don't know how you got to using connections[], but it is just a shortcut to access the node where the port connections of an object are stored in its attribute tree. So using this here will naturally not do anything/produce errors.

Your logic makes sense if you add the created points to an array and use those entries in contextdragconnection().

Table points = Table("Locations");
Array GISPoints = []; Model.find("GISNavigator").subnodes.clear(); for (int i = 1; i <= points.numRows; i++) {     string id = points [i][1];     double lat = points[i][2];     double long = points[i][3];     Object point = Object.create("GIS::Point");     point.setProperty("Latitude", lat);     point.setProperty("Longitude", long);     setname(point, id);     GISPoints.push(point); } Table routes = Table ("Connections"); for (int i = 1; i <= routes.numRows; i++ ) {     for (int j = i+1; j <= routes.numCols; j++ ) {         if    (routes[i][j] == 1 ) {         contextdragconnection (GISPoints[i], GISPoints[j], "A");         }     } }

Furthermore, I would suggest to format your table differently, otherwise you will have to take into account an offset in the index between the locations and connections table.

capture1.png

Additionally your code currently only looks at the upper right half of the table (which makes sense if the table were symmetric).


capture1.png (6.9 KiB)
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Kadircan T avatar image Kadircan T commented ·

Thank you @Felix Möhlmann , This is what I am looking for.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.