GIS torus

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

GIS torus

Grant, Tyler J [NREM]

Hi,

 

Could someone explain to me how to create a torus with a GIS landscape.  All my butterflies are flying off the ranch. 

 

Tyler

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 


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

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: GIS torus

Tatara, Eric R.
The Geography projection does not have a built in torus landscape function like the other abstract spatial projections in Repast.  However, you could simply modify the butterfly movement logic that checks if the new position goes beyond the boundaries that you would like to contain them.  In the case where the new x/y position exceeds the boundary x/y value, calculate the distance by which the new movement exceeds the boundary x/y and set the new position to the opposite boundary x/y +/- the exceeded distance.  This will warp the agent to the other edge of the containment space.

eric

Eric Tatara, PhD, PE
Software Engineer
Global Security Sciences Division
Argonne National Laboratory


From: Grant, Tyler J [NREM] [[hidden email]]
Sent: Monday, November 02, 2015 2:08 PM
To: [hidden email]
Cc: Demuth, Gabriel O [STAT]
Subject: [Repast-interest] GIS torus

Hi,

 

Could someone explain to me how to create a torus with a GIS landscape.  All my butterflies are flying off the ranch. 

 

Tyler

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 


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

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: GIS torus

Grant, Tyler J [NREM]

Eric,

 

In creating a torus, I’m trying to use getGeometry(), but I can’t figure what kind of object it returns (I know my limited Java experience is showing here.)  Here is the code I am trying to make work.  I assume geography.move() will put the agent at the new coordinates. 

 

?? loc = new ??

             loc = geography.getGeometry(this);

             double x = loc.getCoordinate().x;

             double y = loc.getCoordinate().y;

            

             if (x < xmin){

                    Coordinate tempcoord1 = new Coordinate(xmax - (xmin - x), y);

                    geography.move(this, tempcoord1);

             }

            

             if (x > xmax){

                    Coordinate tempcoord2 = new Coordinate(xmin + (x - xmax), y);

                    geography.move(this, tempcoord2);

             }

            

             if (y < ymin){

                    Coordinate tempcoord3 = new Coordinate(x, ymax - (ymin - y));

                    geography.move(this, tempcoord3);

             }

            

             if (y > ymax){

                    Coordinate tempcoord4 = new Coordinate(x, ymin + (y - ymax));

                    geography.move(this, tempcoord4);

             }

            

 

The agents may still be able to escape if they go outside the bounds of x and y in the same time step, but I’ll fix that with some more complicated if statements. 

 

The complete code for the GIS agent (Monarch) is below for reference. 

 

Thanks so much. 

 

Tyler

 

public class Monarch {

       private String name;

       //angle in radians that monarch is to move

       private double angleinRadians;

       //magnitude of change in direction

       private double angleChange;

       //directionality parameter constrains possible changes in direction

       private double directionality = 0.5;

       //current angle in radians that Monarch moves - initialize to random value

       private double currAngle = 2*Math.PI*Math.random();

       //temp variable needed when angle crosses 360/0 degrees

       private double tempAngle1 = 0;

       private double tempAngle2 = 0;

      

       //xy boundaries of the geographic area in lat/long

       static double xmin = -93.50925;

       static double xmax = -93.45775;

       static double ymin = 42.04425;

       static double ymax = 42.0964;

      

       public Monarch(String name) {

             this.name = name;

       }

      

       @ScheduledMethod(start = 1, interval = 1, priority = ScheduleParameters.FIRST_PRIORITY)

       public void step(){

             corrrandwalk();

       }

      

       private void corrrandwalk(){

            

             Context context = ContextUtils.getContext(this);

             Geography<Monarch> geography = (Geography)context.getProjection("Monarchs");

            

             //retrieve any Monarchs that go outside the boundaries and return them to opposite side

            

             ?? loc = new ??

             loc = geography.getGeometry(this);

             double x = loc.getCoordinate().x;

             double y = loc.getCoordinate().y;

            

             if (x < xmin){

                    Coordinate tempcoord1 = new Coordinate(xmax - (xmin - x), y);

                    geography.move(this, tempcoord1);

             }

            

             if (x > xmax){

                    Coordinate tempcoord2 = new Coordinate(xmin + (x - xmax), y);

                    geography.move(this, tempcoord2);

             }

            

             if (y < ymin){

                    Coordinate tempcoord3 = new Coordinate(x, ymax - (ymin - y));

                    geography.move(this, tempcoord3);

             }

            

             if (y > ymax){

                    Coordinate tempcoord4 = new Coordinate(x, ymin + (y - ymax));

                    geography.move(this, tempcoord4);

             }

            

             //get new angle for correlated random walk and movebyVector

            

             angleChange = Math.PI*RandomHelper.nextDouble()*(1-directionality);

            

             if(Math.random() < 0.5){

                    tempAngle1 = currAngle + angleChange;

                    if(tempAngle1 > 2*Math.PI){

                           angleinRadians = tempAngle1 - 2*Math.PI;

                    }

                    else {

                           angleinRadians = tempAngle1;

                    }

             } else {

                    tempAngle2 = currAngle - angleChange;

                    if(tempAngle2 < 0){

                           angleinRadians = 2*Math.PI + tempAngle2;

                    }

                    else{

                           angleinRadians = tempAngle2;

                    }

             }

            

             geography.moveByVector(this, 50, angleinRadians);

       }

      

       public String getName() {

             return name;

       }

      

       @Override

       public String toString() {

             return name;

       }

      

}

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 

From: Tatara, Eric R. [mailto:[hidden email]]
Sent: Tuesday, November 03, 2015 9:34 AM
To: Grant, Tyler J [NREM] <[hidden email]>; [hidden email]
Cc: Demuth, Gabriel O [STAT] <[hidden email]>
Subject: RE: GIS torus

 

The Geography projection does not have a built in torus landscape function like the other abstract spatial projections in Repast.  However, you could simply modify the butterfly movement logic that checks if the new position goes beyond the boundaries that you would like to contain them.  In the case where the new x/y position exceeds the boundary x/y value, calculate the distance by which the new movement exceeds the boundary x/y and set the new position to the opposite boundary x/y +/- the exceeded distance.  This will warp the agent to the other edge of the containment space.

eric

 

Eric Tatara, PhD, PE
Software Engineer
Global Security Sciences Division
Argonne National Laboratory


From: Grant, Tyler J [NREM] [[hidden email]]
Sent: Monday, November 02, 2015 2:08 PM
To: [hidden email]
Cc: Demuth, Gabriel O [STAT]
Subject: [Repast-interest] GIS torus

Hi,

 

Could someone explain to me how to create a torus with a GIS landscape.  All my butterflies are flying off the ranch. 

 

Tyler

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 


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

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: GIS torus

Tatara, Eric R.

getGeometry() will return a com.vividsolutions.jts.geom.Geometry (http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html), which I’m assuming is a Point.  If so, a cast to Point will work:

 

Point loc = (Point) geography.getGeometry(this);

 

However, if it’s not a point geometry, you can just use

 

Geometry loc = geography.getGeometry(this);

Point center = loc.getCentroid();

 

 

 

From: Grant, Tyler J [NREM] [mailto:[hidden email]]
Sent: Tuesday, November 03, 2015 2:03 PM
To: Tatara, Eric R. <[hidden email]>; [hidden email]
Cc: Demuth, Gabriel O [STAT] <[hidden email]>
Subject: RE: GIS torus

 

Eric,

 

In creating a torus, I’m trying to use getGeometry(), but I can’t figure what kind of object it returns (I know my limited Java experience is showing here.)  Here is the code I am trying to make work.  I assume geography.move() will put the agent at the new coordinates. 

 

?? loc = new ??

             loc = geography.getGeometry(this);

             double x = loc.getCoordinate().x;

             double y = loc.getCoordinate().y;

            

             if (x < xmin){

                    Coordinate tempcoord1 = new Coordinate(xmax - (xmin - x), y);

                    geography.move(this, tempcoord1);

             }

            

             if (x > xmax){

                    Coordinate tempcoord2 = new Coordinate(xmin + (x - xmax), y);

                    geography.move(this, tempcoord2);

             }

            

             if (y < ymin){

                    Coordinate tempcoord3 = new Coordinate(x, ymax - (ymin - y));

                    geography.move(this, tempcoord3);

             }

            

             if (y > ymax){

                    Coordinate tempcoord4 = new Coordinate(x, ymin + (y - ymax));

                    geography.move(this, tempcoord4);

             }

            

 

The agents may still be able to escape if they go outside the bounds of x and y in the same time step, but I’ll fix that with some more complicated if statements. 

 

The complete code for the GIS agent (Monarch) is below for reference. 

 

Thanks so much. 

 

Tyler

 

public class Monarch {

       private String name;

       //angle in radians that monarch is to move

       private double angleinRadians;

       //magnitude of change in direction

       private double angleChange;

       //directionality parameter constrains possible changes in direction

       private double directionality = 0.5;

       //current angle in radians that Monarch moves - initialize to random value

       private double currAngle = 2*Math.PI*Math.random();

       //temp variable needed when angle crosses 360/0 degrees

       private double tempAngle1 = 0;

       private double tempAngle2 = 0;

      

       //xy boundaries of the geographic area in lat/long

       static double xmin = -93.50925;

       static double xmax = -93.45775;

       static double ymin = 42.04425;

       static double ymax = 42.0964;

      

       public Monarch(String name) {

             this.name = name;

       }

      

       @ScheduledMethod(start = 1, interval = 1, priority = ScheduleParameters.FIRST_PRIORITY)

       public void step(){

             corrrandwalk();

       }

      

       private void corrrandwalk(){

            

             Context context = ContextUtils.getContext(this);

             Geography<Monarch> geography = (Geography)context.getProjection("Monarchs");

            

             //retrieve any Monarchs that go outside the boundaries and return them to opposite side

            

             ?? loc = new ??

             loc = geography.getGeometry(this);

             double x = loc.getCoordinate().x;

             double y = loc.getCoordinate().y;

            

             if (x < xmin){

                    Coordinate tempcoord1 = new Coordinate(xmax - (xmin - x), y);

                    geography.move(this, tempcoord1);

             }

            

             if (x > xmax){

                    Coordinate tempcoord2 = new Coordinate(xmin + (x - xmax), y);

                    geography.move(this, tempcoord2);

             }

            

             if (y < ymin){

                    Coordinate tempcoord3 = new Coordinate(x, ymax - (ymin - y));

                    geography.move(this, tempcoord3);

             }

            

             if (y > ymax){

                    Coordinate tempcoord4 = new Coordinate(x, ymin + (y - ymax));

                    geography.move(this, tempcoord4);

             }

            

             //get new angle for correlated random walk and movebyVector

            

             angleChange = Math.PI*RandomHelper.nextDouble()*(1-directionality);

            

             if(Math.random() < 0.5){

                    tempAngle1 = currAngle + angleChange;

                    if(tempAngle1 > 2*Math.PI){

                           angleinRadians = tempAngle1 - 2*Math.PI;

                    }

                    else {

                           angleinRadians = tempAngle1;

                    }

             } else {

                    tempAngle2 = currAngle - angleChange;

                    if(tempAngle2 < 0){

                           angleinRadians = 2*Math.PI + tempAngle2;

                    }

                    else{

                           angleinRadians = tempAngle2;

                    }

             }

            

             geography.moveByVector(this, 50, angleinRadians);

       }

      

       public String getName() {

             return name;

       }

      

       @Override

       public String toString() {

             return name;

       }

      

}

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 

From: Tatara, Eric R. [[hidden email]]
Sent: Tuesday, November 03, 2015 9:34 AM
To: Grant, Tyler J [NREM] <[hidden email]>; [hidden email]
Cc: Demuth, Gabriel O [STAT] <[hidden email]>
Subject: RE: GIS torus

 

The Geography projection does not have a built in torus landscape function like the other abstract spatial projections in Repast.  However, you could simply modify the butterfly movement logic that checks if the new position goes beyond the boundaries that you would like to contain them.  In the case where the new x/y position exceeds the boundary x/y value, calculate the distance by which the new movement exceeds the boundary x/y and set the new position to the opposite boundary x/y +/- the exceeded distance.  This will warp the agent to the other edge of the containment space.

eric

 

Eric Tatara, PhD, PE
Software Engineer
Global Security Sciences Division
Argonne National Laboratory


From: Grant, Tyler J [NREM] [[hidden email]]
Sent: Monday, November 02, 2015 2:08 PM
To: [hidden email]
Cc: Demuth, Gabriel O [STAT]
Subject: [Repast-interest] GIS torus

Hi,

 

Could someone explain to me how to create a torus with a GIS landscape.  All my butterflies are flying off the ranch. 

 

Tyler

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 


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

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: GIS torus

Grant, Tyler J [NREM]

Eric,

That worked, thanks.  I had to create the GeometryFactory in the Monarch class.  It’s also created in the ContextBuild.  I couldn’t figure out how to call it from the Monarch class though.  Could that be a problem?

 

                           GeometryFactory fac = new GeometryFactory();

                           Point loc = (Point)geography.getGeometry(this);

                           double x = loc.getCoordinate().x;

                           double y = loc.getCoordinate().y;

                          

                           if (x < xmin){

                                 Coordinate tempcoord1 = new Coordinate(xmax - (xmin - x), y);

                                 Point temp1 = fac.createPoint(tempcoord1);

                                 geography.move(this, temp1);

                           }

                          

                           if (x > xmax){

                                 Coordinate tempcoord2 = new Coordinate(xmin + (x - xmax), y);

                                 Point temp2 = fac.createPoint(tempcoord2);

                                 geography.move(this, temp2);

                           }

                          

                           if (y < ymin){

                                 Coordinate tempcoord3 = new Coordinate(x, ymax - (ymin - y));

                                 Point temp3 = fac.createPoint(tempcoord3);

                                 geography.move(this, temp3);

                           }

                          

                           if (y > ymax){

                                 Coordinate tempcoord4 = new Coordinate(x, ymin + (y - ymax));

                                 Point temp4 = fac.createPoint(tempcoord4);

                                 geography.move(this, temp4);

                           }

 

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 

From: Tatara, Eric R. [mailto:[hidden email]]
Sent: Tuesday, November 03, 2015 5:19 PM
To: Grant, Tyler J [NREM] <[hidden email]>; [hidden email]
Cc: Demuth, Gabriel O [STAT] <[hidden email]>
Subject: RE: GIS torus

 

getGeometry() will return a com.vividsolutions.jts.geom.Geometry (http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html), which I’m assuming is a Point.  If so, a cast to Point will work:

 

Point loc = (Point) geography.getGeometry(this);

 

However, if it’s not a point geometry, you can just use

 

Geometry loc = geography.getGeometry(this);

Point center = loc.getCentroid();

 

 

 

From: Grant, Tyler J [NREM] [[hidden email]]
Sent: Tuesday, November 03, 2015 2:03 PM
To: Tatara, Eric R. <[hidden email]>; [hidden email]
Cc: Demuth, Gabriel O [STAT] <[hidden email]>
Subject: RE: GIS torus

 

Eric,

 

In creating a torus, I’m trying to use getGeometry(), but I can’t figure what kind of object it returns (I know my limited Java experience is showing here.)  Here is the code I am trying to make work.  I assume geography.move() will put the agent at the new coordinates. 

 

?? loc = new ??

             loc = geography.getGeometry(this);

             double x = loc.getCoordinate().x;

             double y = loc.getCoordinate().y;

            

             if (x < xmin){

                    Coordinate tempcoord1 = new Coordinate(xmax - (xmin - x), y);

                    geography.move(this, tempcoord1);

             }

            

             if (x > xmax){

                    Coordinate tempcoord2 = new Coordinate(xmin + (x - xmax), y);

                    geography.move(this, tempcoord2);

             }

            

             if (y < ymin){

                    Coordinate tempcoord3 = new Coordinate(x, ymax - (ymin - y));

                    geography.move(this, tempcoord3);

             }

            

             if (y > ymax){

                    Coordinate tempcoord4 = new Coordinate(x, ymin + (y - ymax));

                    geography.move(this, tempcoord4);

             }

            

 

The agents may still be able to escape if they go outside the bounds of x and y in the same time step, but I’ll fix that with some more complicated if statements. 

 

The complete code for the GIS agent (Monarch) is below for reference. 

 

Thanks so much. 

 

Tyler

 

public class Monarch {

       private String name;

       //angle in radians that monarch is to move

       private double angleinRadians;

       //magnitude of change in direction

       private double angleChange;

       //directionality parameter constrains possible changes in direction

       private double directionality = 0.5;

       //current angle in radians that Monarch moves - initialize to random value

       private double currAngle = 2*Math.PI*Math.random();

       //temp variable needed when angle crosses 360/0 degrees

       private double tempAngle1 = 0;

       private double tempAngle2 = 0;

      

       //xy boundaries of the geographic area in lat/long

       static double xmin = -93.50925;

       static double xmax = -93.45775;

       static double ymin = 42.04425;

       static double ymax = 42.0964;

      

       public Monarch(String name) {

             this.name = name;

       }

      

       @ScheduledMethod(start = 1, interval = 1, priority = ScheduleParameters.FIRST_PRIORITY)

       public void step(){

             corrrandwalk();

       }

      

       private void corrrandwalk(){

            

             Context context = ContextUtils.getContext(this);

             Geography<Monarch> geography = (Geography)context.getProjection("Monarchs");

            

             //retrieve any Monarchs that go outside the boundaries and return them to opposite side

            

             ?? loc = new ??

             loc = geography.getGeometry(this);

             double x = loc.getCoordinate().x;

             double y = loc.getCoordinate().y;

            

             if (x < xmin){

                    Coordinate tempcoord1 = new Coordinate(xmax - (xmin - x), y);

                    geography.move(this, tempcoord1);

             }

            

             if (x > xmax){

                    Coordinate tempcoord2 = new Coordinate(xmin + (x - xmax), y);

                    geography.move(this, tempcoord2);

             }

            

             if (y < ymin){

                    Coordinate tempcoord3 = new Coordinate(x, ymax - (ymin - y));

                    geography.move(this, tempcoord3);

             }

            

             if (y > ymax){

                    Coordinate tempcoord4 = new Coordinate(x, ymin + (y - ymax));

                    geography.move(this, tempcoord4);

             }

            

             //get new angle for correlated random walk and movebyVector

            

             angleChange = Math.PI*RandomHelper.nextDouble()*(1-directionality);

            

             if(Math.random() < 0.5){

                    tempAngle1 = currAngle + angleChange;

                    if(tempAngle1 > 2*Math.PI){

                           angleinRadians = tempAngle1 - 2*Math.PI;

                    }

                    else {

                           angleinRadians = tempAngle1;

                    }

             } else {

                    tempAngle2 = currAngle - angleChange;

                    if(tempAngle2 < 0){

                           angleinRadians = 2*Math.PI + tempAngle2;

                    }

                    else{

                           angleinRadians = tempAngle2;

                    }

             }

            

             geography.moveByVector(this, 50, angleinRadians);

       }

      

       public String getName() {

             return name;

       }

      

       @Override

       public String toString() {

             return name;

       }

      

}

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 

From: Tatara, Eric R. [[hidden email]]
Sent: Tuesday, November 03, 2015 9:34 AM
To: Grant, Tyler J [NREM] <[hidden email]>; [hidden email]
Cc: Demuth, Gabriel O [STAT] <[hidden email]>
Subject: RE: GIS torus

 

The Geography projection does not have a built in torus landscape function like the other abstract spatial projections in Repast.  However, you could simply modify the butterfly movement logic that checks if the new position goes beyond the boundaries that you would like to contain them.  In the case where the new x/y position exceeds the boundary x/y value, calculate the distance by which the new movement exceeds the boundary x/y and set the new position to the opposite boundary x/y +/- the exceeded distance.  This will warp the agent to the other edge of the containment space.

eric

 

Eric Tatara, PhD, PE
Software Engineer
Global Security Sciences Division
Argonne National Laboratory


From: Grant, Tyler J [NREM] [[hidden email]]
Sent: Monday, November 02, 2015 2:08 PM
To: [hidden email]
Cc: Demuth, Gabriel O [STAT]
Subject: [Repast-interest] GIS torus

Hi,

 

Could someone explain to me how to create a torus with a GIS landscape.  All my butterflies are flying off the ranch. 

 

Tyler

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 


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

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: GIS torus

Tatara, Eric R.

There’s no issue with creating the GeometryFactory in that way – it can be created as needed and is disposed when the method is completed.  There might be a small performance cost if you have many thousands of agents, in which case you can make it a static field in the class.  If you just declare it in the class as

 

public static GeometryFactory fac = new GeometryFactory();

 

and then just delete the exsting line that creates it in the method, it might be a bit more efficient.

 

From: Grant, Tyler J [NREM] [mailto:[hidden email]]
Sent: Wednesday, November 04, 2015 1:41 PM
To: Tatara, Eric R. <[hidden email]>; [hidden email]
Cc: Demuth, Gabriel O [STAT] <[hidden email]>
Subject: RE: GIS torus

 

Eric,

That worked, thanks.  I had to create the GeometryFactory in the Monarch class.  It’s also created in the ContextBuild.  I couldn’t figure out how to call it from the Monarch class though.  Could that be a problem?

 

                           GeometryFactory fac = new GeometryFactory();

                           Point loc = (Point)geography.getGeometry(this);

                           double x = loc.getCoordinate().x;

                           double y = loc.getCoordinate().y;

                          

                           if (x < xmin){

                                 Coordinate tempcoord1 = new Coordinate(xmax - (xmin - x), y);

                                 Point temp1 = fac.createPoint(tempcoord1);

                                 geography.move(this, temp1);

                           }

                          

                           if (x > xmax){

                                 Coordinate tempcoord2 = new Coordinate(xmin + (x - xmax), y);

                                 Point temp2 = fac.createPoint(tempcoord2);

                                 geography.move(this, temp2);

                           }

                          

                           if (y < ymin){

                                 Coordinate tempcoord3 = new Coordinate(x, ymax - (ymin - y));

                                 Point temp3 = fac.createPoint(tempcoord3);

                                 geography.move(this, temp3);

                           }

                          

                           if (y > ymax){

                                 Coordinate tempcoord4 = new Coordinate(x, ymin + (y - ymax));

                                 Point temp4 = fac.createPoint(tempcoord4);

                                 geography.move(this, temp4);

                           }

 

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 

From: Tatara, Eric R. [[hidden email]]
Sent: Tuesday, November 03, 2015 5:19 PM
To: Grant, Tyler J [NREM] <[hidden email]>; [hidden email]
Cc: Demuth, Gabriel O [STAT] <[hidden email]>
Subject: RE: GIS torus

 

getGeometry() will return a com.vividsolutions.jts.geom.Geometry (http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html), which I’m assuming is a Point.  If so, a cast to Point will work:

 

Point loc = (Point) geography.getGeometry(this);

 

However, if it’s not a point geometry, you can just use

 

Geometry loc = geography.getGeometry(this);

Point center = loc.getCentroid();

 

 

 

From: Grant, Tyler J [NREM] [[hidden email]]
Sent: Tuesday, November 03, 2015 2:03 PM
To: Tatara, Eric R. <[hidden email]>; [hidden email]
Cc: Demuth, Gabriel O [STAT] <[hidden email]>
Subject: RE: GIS torus

 

Eric,

 

In creating a torus, I’m trying to use getGeometry(), but I can’t figure what kind of object it returns (I know my limited Java experience is showing here.)  Here is the code I am trying to make work.  I assume geography.move() will put the agent at the new coordinates. 

 

?? loc = new ??

             loc = geography.getGeometry(this);

             double x = loc.getCoordinate().x;

             double y = loc.getCoordinate().y;

            

             if (x < xmin){

                    Coordinate tempcoord1 = new Coordinate(xmax - (xmin - x), y);

                    geography.move(this, tempcoord1);

             }

            

             if (x > xmax){

                    Coordinate tempcoord2 = new Coordinate(xmin + (x - xmax), y);

                    geography.move(this, tempcoord2);

             }

            

             if (y < ymin){

                    Coordinate tempcoord3 = new Coordinate(x, ymax - (ymin - y));

                    geography.move(this, tempcoord3);

             }

            

             if (y > ymax){

                    Coordinate tempcoord4 = new Coordinate(x, ymin + (y - ymax));

                    geography.move(this, tempcoord4);

             }

            

 

The agents may still be able to escape if they go outside the bounds of x and y in the same time step, but I’ll fix that with some more complicated if statements. 

 

The complete code for the GIS agent (Monarch) is below for reference. 

 

Thanks so much. 

 

Tyler

 

public class Monarch {

       private String name;

       //angle in radians that monarch is to move

       private double angleinRadians;

       //magnitude of change in direction

       private double angleChange;

       //directionality parameter constrains possible changes in direction

       private double directionality = 0.5;

       //current angle in radians that Monarch moves - initialize to random value

       private double currAngle = 2*Math.PI*Math.random();

       //temp variable needed when angle crosses 360/0 degrees

       private double tempAngle1 = 0;

       private double tempAngle2 = 0;

      

       //xy boundaries of the geographic area in lat/long

       static double xmin = -93.50925;

       static double xmax = -93.45775;

       static double ymin = 42.04425;

       static double ymax = 42.0964;

      

       public Monarch(String name) {

             this.name = name;

       }

      

       @ScheduledMethod(start = 1, interval = 1, priority = ScheduleParameters.FIRST_PRIORITY)

       public void step(){

             corrrandwalk();

       }

      

       private void corrrandwalk(){

            

             Context context = ContextUtils.getContext(this);

             Geography<Monarch> geography = (Geography)context.getProjection("Monarchs");

            

             //retrieve any Monarchs that go outside the boundaries and return them to opposite side

            

             ?? loc = new ??

             loc = geography.getGeometry(this);

             double x = loc.getCoordinate().x;

             double y = loc.getCoordinate().y;

            

             if (x < xmin){

                    Coordinate tempcoord1 = new Coordinate(xmax - (xmin - x), y);

                    geography.move(this, tempcoord1);

             }

            

             if (x > xmax){

                    Coordinate tempcoord2 = new Coordinate(xmin + (x - xmax), y);

                    geography.move(this, tempcoord2);

             }

            

             if (y < ymin){

                    Coordinate tempcoord3 = new Coordinate(x, ymax - (ymin - y));

                    geography.move(this, tempcoord3);

             }

            

             if (y > ymax){

                    Coordinate tempcoord4 = new Coordinate(x, ymin + (y - ymax));

                    geography.move(this, tempcoord4);

             }

            

             //get new angle for correlated random walk and movebyVector

            

             angleChange = Math.PI*RandomHelper.nextDouble()*(1-directionality);

            

             if(Math.random() < 0.5){

                    tempAngle1 = currAngle + angleChange;

                    if(tempAngle1 > 2*Math.PI){

                           angleinRadians = tempAngle1 - 2*Math.PI;

                    }

                    else {

                           angleinRadians = tempAngle1;

                    }

             } else {

                    tempAngle2 = currAngle - angleChange;

                    if(tempAngle2 < 0){

                           angleinRadians = 2*Math.PI + tempAngle2;

                    }

                    else{

                           angleinRadians = tempAngle2;

                    }

             }

            

             geography.moveByVector(this, 50, angleinRadians);

       }

      

       public String getName() {

             return name;

       }

      

       @Override

       public String toString() {

             return name;

       }

      

}

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 

From: Tatara, Eric R. [[hidden email]]
Sent: Tuesday, November 03, 2015 9:34 AM
To: Grant, Tyler J [NREM] <[hidden email]>; [hidden email]
Cc: Demuth, Gabriel O [STAT] <[hidden email]>
Subject: RE: GIS torus

 

The Geography projection does not have a built in torus landscape function like the other abstract spatial projections in Repast.  However, you could simply modify the butterfly movement logic that checks if the new position goes beyond the boundaries that you would like to contain them.  In the case where the new x/y position exceeds the boundary x/y value, calculate the distance by which the new movement exceeds the boundary x/y and set the new position to the opposite boundary x/y +/- the exceeded distance.  This will warp the agent to the other edge of the containment space.

eric

 

Eric Tatara, PhD, PE
Software Engineer
Global Security Sciences Division
Argonne National Laboratory


From: Grant, Tyler J [NREM] [[hidden email]]
Sent: Monday, November 02, 2015 2:08 PM
To: [hidden email]
Cc: Demuth, Gabriel O [STAT]
Subject: [Repast-interest] GIS torus

Hi,

 

Could someone explain to me how to create a torus with a GIS landscape.  All my butterflies are flying off the ranch. 

 

Tyler

 

Dr. Tyler J. Grant

Postdoctoral Associate

Department of Natural Resource Ecology and Management

Iowa State University

339 Science II

Ames, IA 50011

 


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

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest