question

MPeyman avatar image
0 Likes"
MPeyman asked Kavika F commented

creating GIS points from csv file with script

Hi, I try to write code in which instead of creating the several points, just read all the pints in my csv file and add it to the GIS map but I get an error. Also I would like to connect all points:

// Create a map object if one does not exist

Object map = model().find("BCNMap");

if (!map) {

map = createinstance(library().find("/GIS/Map"), model());

map.name = "BCNMap";

map.setSize(30, 20, 2);

map.setLocation(10, 0, 0);

map.setProperty("Latitude", 41.3979379766732);

map.setProperty("Longitude", 2.17978500482735);

map.setProperty("Zoom", 15.742556607617);

}

// The map should have asserted a GISNavigator when it was created

Object navigator = model().find("GISNavigator");

if (!navigator)

return 0;

Object map = model().find("BCNMap");


// Define the file path to the CSV file.

string filePath = "C:\Users\points.csv";


// Read the entire file into a string

string file = readfile(filePath);


// Split the string into an array of lines

string[] lines = split(file, "\n");


//get the GIS navigator from the model

Object navigator = model().find("GISNavigator");

if (!navigator)

return 0;


//Delete existing points

navigator.subnodes.clear();


//loop through the lines of the csv file

for (int i = 1; i < size(lines); i++) {

//split the line into an array of values

string[] values = split(lines[i], ",");

//Get the lat and long values from the current line.

double lat = toDouble(values[0]);

double lon = toDouble(values[1]);

//Create a new point object and set the lat and long values.

Object point = createinstance(library().find("/GIS/Point"), navigator);

point.setProperty("Latitude", lat);

point.setProperty("Longitude", lon);

FlexSim 23.0.0
gislogistics
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

Kavika F avatar image
0 Likes"
Kavika F answered Kavika F commented

Hey @MPeyman, if you save your points from your csv file to a Global Table, you can programmatically create your points with their proper latitude and longitude. Here's an example I did.

GIS_Coded_Points.fsm

First I made a Global Table with some fake points.

1673461962478.png

I added a GIS Map to my 3D Model. Then I wrote a simple script that, when executed, will look at the coordinates in my table and set the properties of that point.

1673462015240.png

Here's what it looks like in action:

gis-points-generated.gif


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