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);