How to remove z from xyz coordinates

25 views
Skip to first unread message

Srirama Bhamidipati

unread,
Aug 3, 2014, 2:54:08 AM8/3/14
to gama-p...@googlegroups.com
Hi

I have a list<points> that contains [{xyz}, {xyz}.......] and I would like to have [ {xy}, {xy} .......]

This is because, I am using a point shape file with (xyz) to come into a voronoi definition. But , voronoi definition only takes xy and I get ArrayStoreException. Therefore my question is:

1. how I can use a point shape file into voronoi or
2. how I can remove the z from a list of xyz 

thanks
Sri

Patrick Taillandier

unread,
Aug 3, 2014, 3:02:55 AM8/3/14
to gama-p...@googlegroups.com
Hi,

I am not sure to understand what do you mean by "voronoi definition only takes xy and I get ArrayStoreException" (I was not able to reproduce this). Do you have a simple model that reproduces this?

However, you can test this:

list<point> pts <- lits_of_3Dpoints collect {each.x,each.y};


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 http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Srirama Bhamidipati

unread,
Aug 3, 2014, 4:36:12 AM8/3/14
to gama-p...@googlegroups.com
Thank you Patrick. May be I did not express correctly. Please see attached model, may be my coding is wrong.

Thanks
Srirama
Copy of voronoi.gaml
Archive 2.zip

Patrick Taillandier

unread,
Aug 3, 2014, 4:41:25 AM8/3/14
to gama-p...@googlegroups.com
Ok, so the error is simple to fix ;) .

You should write:

list<geometry>station_voronoi <- voronoi(list_of_points_power_station);

instead of:

list<geometry>station_voronoi <- voronoi([list_of_points_power_station]);

Indeed, station_voronoi is already a list of points, so you do not need to create a new list with this list inside (list of list instead of list of points).
Cheers,

Patrick


--

Srirama Bhamidipati

unread,
Aug 3, 2014, 4:43:32 AM8/3/14
to gama-p...@googlegroups.com
Sorry I forgot to mention. I want to make a voronoi of the points from the shape file.

Srirama Bhamidipati

unread,
Aug 3, 2014, 4:46:19 AM8/3/14
to gama-p...@googlegroups.com
Oke. my silly mistakes never end. :) :) Thank you. I will try your suggestion. :) 

Srirama Bhamidipati

unread,
Aug 4, 2014, 12:52:26 AM8/4/14
to gama-p...@googlegroups.com
Hi Patrick,

regarding your suggestion:

However, you can test this:

list<point> pts <- lits_of_3Dpoints collect {each.x,each.y};


It did not work for me, from the same model of mine yesterday, i still get xyz. I just added ( I added pts in the global section as list<point>:


pts <-  list_of_points_power_station collect {each.x,each.y};

write pts;


The write statement with pts still gives me all three coordinates. Anything I missed ?


regards,

Srirama

Benoit Gaudou

unread,
Aug 4, 2014, 2:32:48 AM8/4/14
to gama-p...@googlegroups.com
Hi Srirama,

First of all, in GAMA now all points have 3 coordinates xyz, so
pts <-  list_of_points_power_station collect {each.x,each.y};
basically returns a list of points with the 2 coordinates of the points from the list list_of_points_power_station and with 0.0 for z.

But for the voronoi operator accepts points with 3 coordinates so on a simple example you can write: 

global {

init {

create points number: 10;

list<point> lpts3D <- points collect (each.location);

list<geometry> vorn <- voronoi(lpts3D);

loop geom over: vorn {

create voronShape {

shape <- geom;

}

}

}

}


species points {

aspect b {draw circle(2) color: #red;}

}

species voronShape{}


experiment testPoints3D type: gui {

output {

display agentst {

species voronShape;

species points aspect: b;

}

}

}


-----------

On your example, it becomes:

global {

file kv5_file <- file("../includes/kv10.shp");

geometry shape <- envelope(kv5_file);

init {

create points from: kv5_file;

list<point> lpts3D <- points collect (each.location);

list<geometry> vorn <- voronoi(lpts3D);

loop geom over: vorn {

create voronShape {

shape <- geom;

}

}

}

}


--------------


Cheers 


Benoit



--

Srirama Bhamidipati

unread,
Aug 4, 2014, 2:46:27 AM8/4/14
to gama-p...@googlegroups.com
Thanks for the clarification Benoit. I thought it should not even return the third coordinate when I explicitly write each.x each.y, and it got me confused. So if I have to access only x or only y coordinates, then I should probably be saying each.location.x ?

Your code is crispier, I will follow that. 

thanks
srirama

Benoit Gaudou

unread,
Aug 4, 2014, 2:55:41 AM8/4/14
to gama-p...@googlegroups.com
HI,
If you want to access the x location of an agent, yes you should use the_agent.location.x, and each.location.x if you get coordinates of agents over a list of agents.

Benoit


--
Reply all
Reply to author
Forward
0 new messages