Can I have shapefiles as output from GAMA?

161 views
Skip to first unread message

Simone Zarpelon Leao

unread,
Jan 13, 2016, 5:53:35 AM1/13/16
to GAMA
Hi,

My GAMA model is moving agents from multiple origins to multiple destinations, drawing the paths along the movement.
Is it possible to have all individual paths stored as a shapefile at the end of the simulation (or a collection of geographic positions describing the paths for each agent in a csv that I can produce a shapefile later)?
I would like to process the validation of the model outputs into a GIS platform.

Regards,
Simone

Patrick Taillandier

unread,
Jan 13, 2016, 6:01:10 AM1/13/16
to gama-p...@googlegroups.com
Hi,

Of course, you have to use the save statement:
save myspecies type:"shp" to:"myshapefile.shp";

You can example in the model library: Model Library/Features/Save Statement 

Note that in GAMA 1.7, you can directly save a list of geometries in a shapefile. In GAMA 1.6.1, it is not possible, but can write something like: 
ask people {shape <- path_geometry;}
save people type:"shp" to:"myshapefile.shp";

Cheers,

Patrick

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at https://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Simone Zarpelon Leao

unread,
Jan 13, 2016, 8:20:47 PM1/13/16
to GAMA
Hi Patrick,

I have used the suggested syntax, but the model is not running properly ... first, the model is not saving any file in the appropriate folder; second, it is now moving only one of the 10 agents i have created; and third, i started receiving that error about overlapping movement again ...
Sorry to bother again, but can you have a look at the code below? My agents are moving on: road_network and drawing my_path ... I would like to save the path of each agent as a shapefile with the road segments they passed. It would be good if I could have one file with all the paths together.
The example below is expected to move 10 agents from origin Randwick to destination Sydney. I have attached the input shapefiles in case you would like to run the model.

global {
int nbRandwpeople <- 10;
float speed <- 8.0 #km/#h;
float step <-1 #minutes;
file roads_shapefile <- file("../includes/Roads_utm.shp");
file Randw_shapefile <- file ("../includes/Randwick.shp");
file dest_sydney_shapefile <- file ("../includes/Dest_Sydney4.shp");
file ocean_shapefile <- file ("../includes/Ocean2.shp");
geometry shape <- envelope(roads_shapefile);
graph road_network;
init {
create road from: roads_shapefile;
road_network <- as_edge_graph(road);
create ZnRandw from: Randw_shapefile; 
create ocean from: ocean_shapefile; 
create dest from: dest_sydney_shapefile;
create Randwpeople number: nbRandwpeople {
speed <- speed + rnd(6);
location <- any_location_in(one_of(ZnRandw));
target <- any_location_in(one_of(dest));
}
ask Randwpeople {
shape <- my_path;
save Randwpeople type:"shp" to: "../results/paths.shp" ;
}
}
}

species Randwpeople skills:[moving]{
geometry my_path;
point target;
reflex move {
path the_path <- goto (target: target, on: road_network, return_path: true);
if (the_path != nil and the_path.shape != nil) {
list<point> pts <- (the_path.segments accumulate each.points);
if (first(pts) != last(pts)) {
my_path <-my_path = nil ? the_path.shape :union(my_path,the_path.shape);
}
}
save my_path to:"../includes/results/paths.shp" type: "shp";
}
aspect circle {
draw circle(10) color: #red;
draw my_path color: #blue;
}
}

species road {
aspect geom{
draw shape color: #gray;
}
}

species ZnRandw {
aspect geom{
draw shape color: #gray;
}
}

species dest {
aspect geom{
draw shape color: #red;
}
}

species ocean {
aspect geom{
draw shape color: #lightblue;
}
}

experiment main_experiment type:gui {
output{
display map{
species Randwpeople aspect: circle;
species road aspect: geom transparency: 0.8;
species ZnRandw aspect: geom transparency: 0.8;
species dest aspect: geom transparency: 0.8;
species ocean aspect: geom transparency: 0.7;
Cycle2Sydney.zip

Simone Zarpelon Leao

unread,
Jan 13, 2016, 8:20:48 PM1/13/16
to GAMA
And the Roads shapefile, which was missing in the previous message ....


On Wednesday, 13 January 2016 22:01:10 UTC+11, Patrick Taillandier wrote:
Cycle2Sydney.zip

Srirama Bhamidipati

unread,
Jan 14, 2016, 10:09:19 AM1/14/16
to GAMA
Hi

If you intention is only to capture path, there are other ways. What is your final purpose? just show the path? 
see attachment, path shown in gama and QGIS with another method without any overlapping error.

I am sure though that GAMA team will look into the error if you want to pursue that previous method, because they are busy cleaning the bugs.

regards,
Srirama
simoneCapture.JPG

Simone Zarpelon Leao

unread,
Jan 17, 2016, 9:05:44 PM1/17/16
to GAMA
Hi Srirama,

No, my model has higher ambitions than just showing the path; however, I need the paths in a shapefile format to validate the results of my simulations against some field data before i progress. Good to see your jpeg with the paths from GAMA to QGIS, but I still do not know how to do it. Could you help me with the coding of saving the paths as shapefile? 

Regards,
Simone

Srirama Bhamidipati

unread,
Jan 19, 2016, 4:29:15 AM1/19/16
to gama-p...@googlegroups.com
Hi,

Oke it means your objective from gama is to just have the path. I just added 3 lines of code to your original code. I add additional lines so that you can see continuum with your code. :) :) 

species comm2SY skills:[moving]{
geometry my_path;
  TZ my_TZ;
  point target;
  path Fpath;
 
  init {
  Fpath<-  path_between (road_network,location,target);
  create shpfile from: geometry(Fpath.shape);
  save shpfile to:"../includes/results/paths.shp" type: "shp";
  }
 

Patrick Taillandier

unread,
Jan 19, 2016, 7:10:01 AM1/19/16
to gama-p...@googlegroups.com
Hi,

Sorry, I did not see that Srirama has already answer your question, but here a possible solution.
As you did not send to me all the data, I had to modify a bit the code. 

Cheers,
Patrick


model simone


global {

int nbRandwpeople <- 10;

float speed <- 8.0 #km/#h;

float step <-1 #minutes;

file roads_shapefile <- file("../includes/Roads_utm.shp");

//file Randw_shapefile <- file ("../includes/Randwick.shp");

//file dest_sydney_shapefile <- file ("../includes/Dest_Sydney4.shp");

//file ocean_shapefile <- file ("../includes/Ocean2.shp");

geometry shape <- envelope(roads_shapefile);

graph road_network;

init {

create road from: roads_shapefile;

road_network <- as_edge_graph(road);

//create ZnRandw from: Randw_shapefile; 

//create ocean from: ocean_shapefile; 

//create dest from: dest_sydney_shapefile;

create Randwpeople number: nbRandwpeople {

speed <- speed + rnd(6);

location <- any_location_in(one_of(road));

target <- any_location_in(one_of(road));

}

}

reflex end_simulation  when: empty(Randwpeople where (not each.is_arrived)){

ask Randwpeople {

shape <- my_path;

}

file fold <- new_folder("../results/");

save Randwpeople type:"shp" to: "../results/paths.shp" ;

do pause;

}

}


species Randwpeople skills:[moving]{

geometry my_path;

point target;

bool is_arrived <- false;

reflex move when: not is_arrived{

path the_path <- goto (target: target, on: road_network, return_path: true);

if (the_path != nil and the_path.shape != nil) {

list<point> pts <- (the_path.segments accumulate each.points);

if (first(pts) != last(pts)) {

my_path <-my_path = nil ? the_path.shape :union(my_path,the_path.shape);

}

}

is_arrived <- location = target;

}

aspect circle {

draw circle(10) color: #red;

draw my_path color: #blue;

}

}


species road {

aspect geom{

draw shape color: #gray;

}

}


species ZnRandw {

aspect geom{

draw shape color: #gray;

}

}


species dest {

aspect geom{

draw shape color: #red;

}

}


species ocean {

aspect geom{

draw shape color: #lightblue;

}

}


experiment main_experiment type:gui {

output{

display map type: opengl{

species road aspect: geom transparency: 0.5 refresh: false;

species ZnRandw aspect: geom transparency: 0.8 refresh: false;

species dest aspect: geom transparency: 0.8 refresh: false;

species ocean aspect: geom transparency: 0.7 refresh: false;

species Randwpeople aspect: circle;

}

}

}



2016-01-19 16:29 GMT+07:00 Srirama Bhamidipati <b.sr...@gmail.com>:
Hi,

Oke it means you objective from gama is to just have the path. I just added 3 lines of code to your original code. I add additional lines so that you can see continuum with your code. :) :) 

Simone Zarpelon Leao

unread,
Jan 21, 2016, 6:54:08 PM1/21/16
to GAMA
Thanks Patrick, Etiene and Srirama for your assistance,

I have received from you three different suggestions for solving my coding issue. Etiene, Unfortunately you suggestion did not produce any shapefile. I believe i have some part missing, and therefore there is no content for a file to be produced. Srirama, your code sounds very logic, however it saves the point of origin of my agents and not the paths. Patrick, your code worked well, and I have now validated my simulations (one question answered and a number of new ones open from the validation process). 

I am preparing a paper for a conference and all your names are in the acknowledgements. I really appreciate your time and effort. I have also included some of your published articles as references in my paper.

Kind regards,
Simone

Srirama Bhamidipati

unread,
Jan 21, 2016, 9:31:05 PM1/21/16
to gama-p...@googlegroups.com
Hi,

Glad that something worked for you. 
I am sure you got only points in my code. That is because you collected my path after the simulation. My code gives you path as soon as you load the model. No need to run the model. :)

By not running the model you save time, you avoid slowness in the model, you avoid overlap error that you were having.

Cheers
Srirama

Simone Zarpelon Leao

unread,
Jan 24, 2016, 9:55:09 PM1/24/16
to GAMA
Hi Srirama,
That would be a great way around the overlap issue, if visualisation was not important.
Anyway, I tried again, now just loading the model, without running it. It still saves only a point shapefile, and not the paths.
Is there anything missing? Can i specify that i want a 'polyline shapefile' ?
Cheers,
Simone
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platform+unsubscribe@googlegroups.com.

Srirama Bhamidipati

unread,
Jan 25, 2016, 6:06:06 AM1/25/16
to GAMA
Attached is the code.
new.gaml
simone.wmv
Reply all
Reply to author
Forward
0 new messages