question

Alyson P avatar image
0 Likes"
Alyson P asked Ryan Clark commented

Get distance between two points in GIS

Hello guys,

I created a map in Flexsim that has some cities, each city is represented by a Point.

Now I need, through Flexscript, to get the Driving Roads distance between two of these cities or to get a Route object so that I can access its properties. Is there any way I can do it in the source code or this distance is only showed in Route Properties?


Thanks for your attention.

FlexSim 21.2.4
gisdistancedistancetotravelroutepoints
5 |100000

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

Phil BoBo avatar image
2 Likes"
Phil BoBo answered Alyson P commented
treenode point1 = Model.find("GISNavigator/Point1");
treenode point2 = Model.find("GISNavigator/Point2");
double distance = function_s(point1, "getDistance", point2);

Task executer's path record within a map (GIS) - FlexSim Community

· 5
5 |100000

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

Alyson P avatar image Alyson P commented ·

Thanks for your answer.

I found this in another topic and already tried it, but unfortunatelly I am getting an exception and still don't know how to solve it.


This is the exception

exception: Exception caught in TreeNode::callMemberFunction() c++/dll execution. Throwing... MAIN:/project/library/GIS/Point>behaviour/eventfunctions/getDistance c: /GISNavigator/SAO PAULO thisClass: MAIN:/project/library/GIS/Point
exception: FlexScript exception: MODEL:/Tools/GUIs/GUI 1/Mostrar Cluster>OnPress c: MODEL:/Tools/GUIs/GUI 1/Mostrar Cluster i: MAIN:/project/model


The main part of my code is as follows:

Object navigator = model().find("GISNavigator");
Array vetor = navigator.subnodes.toArray();
Object point1 = navigator.find(cidade);

for(int i = 1; i <= vetor.length; i++){
            if(vetor[i].getProperty("Latitude") <= lat_max && vetor[i].getProperty("Latitude") >= lat_min && vetor[i].getProperty("Longitude") >= long_min && vetor[i].getProperty("Longitude") <= long_max){
                double distance = function_s(point1, "getDistance", vetor[i]);
                vetor[i].color = Color.blue;
                cluster.append(vetor[i]);               
          }
}


I would be thankful if you could help me one more time.

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Alyson P commented ·

I can't tell you what's wrong from just an incomplete code snippet.

Post your model with replication steps.

0 Likes 0 ·
Alyson P avatar image Alyson P Phil BoBo ♦♦ commented ·

Oh, sure.

My model is still very messy, it began as a test and started growing, I still need to rewrite some codes but it is possible to test where the problem is happening.

All the maps and points are already plotted and all you have to do is open the GUI and click on "Mostrar Cluster". It will automatically get the cities in GlobalTable2, use one by one to create a cluster of cities and find the distance among them, the model may freeze a little but it will work.

Because the map is plotted, the file is too large for upload, so I put it on Google Drive on this link https://drive.google.com/file/d/1pC-mayaHMW-FRsYAMXm_BPv9AGG_cYkX/view?usp=sharing


Thank you very much for tour help again

0 Likes 0 ·
Show more comments
Miguel_ngel Ra avatar image
1 Like"
Miguel_ngel Ra answered Ryan Clark commented

Hello Alyson i have the same problem, could you paste here all your code to get the full distance matrix please

· 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.

Ryan Clark avatar image Ryan Clark commented ·

Hi @Miguel_ngel Ra,

Please post this as a new question. You can link to this post if that would be helpful. Please see Best practices for using this Answers site - FlexSim Community for more info. Thanks!

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.