combining Grid and Geography projections in one display.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

combining Grid and Geography projections in one display.

Meshal Al-Harbi
Hi everyone,

I have a grid projection that has number of agents that represents a certain shape. I also have a geography layer that shows ITN and topography layers. I would like to have the grid layer on top of the geography layer in one display. any help please ?


Thanks in advance ,,



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

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

Re: combining Grid and Geography projections in one display.

Tatara, Eric R.

You cannot directly use a Repast Grid projection in the GIS display, however it is possible to convert the Grid space coordinates into coordinates that can be stored and visualized with a Geography projections.  The idea is to select a pair geographic reference points that represent your Grid min and max values which provides the Grid bounds along with a scale factor to convert the Grid cords to geographic cords.

 

For example, let’s say you define a region in you Geography  with a reference envelope bounded by a set of lat/lons.  These numbers are similar to the region in the Repast Geography demo:

 

double lat1 = 41.4;  // y1

double lat2 = 42.0;  // y2

double lon1 = -88.2; // x1

double lon2 = -87.2; // x2

 

If you have a Grid projection of say 10x10, you can associate the grid coordinate (0,0) with lat1/lon1 (41.4,-88.2) and grid coordinate (10,10) with lat2/lon2 (42,-87.2).  The grid x scaling is (lon2 – lon1) / 10 = (0.1) and the grid y scaling is (lat2 – lat1) / 10 = (0.06). To transform a Grid coordinate to the geographic coordinate you simply multiply the grid coordinate with each scale factor and add the reference point.  For example the point (5,3) on the grid transforms to:

 

Lon = -88.2 + 5 * 0.1 = -87.7

Lat = 41.4 + 3 * 0.06 = 41.58

 

Note that the grid cell positions in the GIS display may not appear exactly square because of the distortion introduced by a flat map projection.   Any time you move an agent on the Grid projection, you would also apply the above transform and move the agent in the geography projection.  To display the gridlines in the GIS display, you can use a Geotools utility to create a set of polygons for the gridlines.  You will need to get the gt-grid-13.0.jar file from the Geootols distribution and add it to your project. 

 

https://sourceforge.net/projects/geotools/files/GeoTools%2013%20Releases/13.0/geotools-13.0-bin.zip/download

 

The following code with generate a set of grid “agents” that can be added to the GIS display like any other agent class.  I wrote this example so that it works in the Repast Geography demo and you can put this somewhere in the context builder.  The attached image shows the result.

 

double lon1 = -88.2;

double lon2 = -87.2;

double lat1 = 41.4;

double lat2 = 42.0;

 

ReferencedEnvelope gridBounds = new ReferencedEnvelope(

                   lon1, lon2, lat1, lat2, DefaultGeographicCRS.WGS84);

          

SimpleFeatureSource grid = Grids.createSquareGrid(gridBounds, 0.05);

             

SimpleFeatureIterator fiter = null;

List<SimpleFeature> features = new ArrayList<SimpleFeature>();

try {

       fiter = grid.getFeatures().features();

                    

       while(fiter.hasNext()){

              features.add(fiter.next());

       }

} catch (IOException e) {

       e.printStackTrace();

} finally{

       fiter.close();

}

          

for (SimpleFeature feature : features){

       Geometry geom = (Geometry)feature.getDefaultGeometry();

           

       geom  = (Polygon)feature.getDefaultGeometry();

 

       GridPolygon gp = new GridPolygon();

 

       context.add(gp);

       geography.move(gp, geom);       

}

 

It also assumes you have a simple GridPolygon agent class:

 

package geography;

 

public class GridPolygon {

 

}

 

And a style for the GridPolygon:

 

package geography;

 

import gov.nasa.worldwind.render.SurfacePolygon;

import gov.nasa.worldwind.render.SurfaceShape;

 

import java.awt.Color;

 

import repast.simphony.visualization.gis3D.style.SurfaceShapeStyle;

 

public class GridPolygonStyle implements SurfaceShapeStyle<GridPolygon>{

 

       @Override

       public SurfaceShape getSurfaceShape(GridPolygon object, SurfaceShape shape) {

              return new SurfacePolygon();

       }

 

       @Override

       public Color getFillColor(GridPolygon zone) {

              return null;

       }

 

       @Override

       public double getFillOpacity(GridPolygon obj) {

              return 0.0;

       }

 

       /**

       * If the zone has water then indicate with a BLUE outline.

       */

       @Override

       public Color getLineColor(GridPolygon zone) {

                     return Color.white;

       }

 

       @Override

       public double getLineOpacity(GridPolygon obj) {

              return 1.0;

       }

 

       @Override

       public double getLineWidth(GridPolygon obj) {

              return 3;

       }

}

 

 

 

From: Meshal Al-Harbi [mailto:[hidden email]]
Sent: Thursday, August 04, 2016 11:14 AM
To: [hidden email]; [hidden email]
Subject: [Repast-interest] combining Grid and Geography projections in one display.

 

Hi everyone,

 

I have a grid projection that has number of agents that represents a certain shape. I also have a geography layer that shows ITN and topography layers. I would like to have the grid layer on top of the geography layer in one display. any help please ?

 

Thanks in advance ,,

 

 


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

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

grid.jpg (551K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: combining Grid and Geography projections in one display.

Tatara, Eric R.
In reply to this post by Meshal Al-Harbi

You can also find more info on the Geotoolsg Grids classes:

 

http://docs.geotools.org/latest/userguide/extension/grid.html

 

 

 

From: Meshal Al-Harbi [mailto:[hidden email]]
Sent: Thursday, August 04, 2016 11:14 AM
To: [hidden email]; [hidden email]
Subject: [Repast-interest] combining Grid and Geography projections in one display.

 

Hi everyone,

 

I have a grid projection that has number of agents that represents a certain shape. I also have a geography layer that shows ITN and topography layers. I would like to have the grid layer on top of the geography layer in one display. any help please ?

 

Thanks in advance ,,

 

 


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

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

Re: combining Grid and Geography projections in one display.

Meshal Al-Harbi
In reply to this post by Tatara, Eric R.
Eric,

Thank you for your prompt reponse. I will work on it and keep you updated.

Thanx,

On Aug 4, 2016, at 10:46 PM, Tatara, Eric R. <[hidden email]> wrote:

You cannot directly use a Repast Grid projection in the GIS display, however it is possible to convert the Grid space coordinates into coordinates that can be stored and visualized with a Geography projections.  The idea is to select a pair geographic reference points that represent your Grid min and max values which provides the Grid bounds along with a scale factor to convert the Grid cords to geographic cords.

 

For example, let’s say you define a region in you Geography  with a reference envelope bounded by a set of lat/lons.  These numbers are similar to the region in the Repast Geography demo:

 

double lat1 = 41.4;  // y1

double lat2 = 42.0;  // y2

double lon1 = -88.2; // x1

double lon2 = -87.2; // x2

 

If you have a Grid projection of say 10x10, you can associate the grid coordinate (0,0) with lat1/lon1 (41.4,-88.2) and grid coordinate (10,10) with lat2/lon2 (42,-87.2).  The grid x scaling is (lon2 – lon1) / 10 = (0.1) and the grid y scaling is (lat2 – lat1) / 10 = (0.06). To transform a Grid coordinate to the geographic coordinate you simply multiply the grid coordinate with each scale factor and add the reference point.  For example the point (5,3) on the grid transforms to:

 

Lon = -88.2 + 5 * 0.1 = -87.7

Lat = 41.4 + 3 * 0.06 = 41.58

 

Note that the grid cell positions in the GIS display may not appear exactly square because of the distortion introduced by a flat map projection.   Any time you move an agent on the Grid projection, you would also apply the above transform and move the agent in the geography projection.  To display the gridlines in the GIS display, you can use a Geotools utility to create a set of polygons for the gridlines.  You will need to get the gt-grid-13.0.jar file from the Geootols distribution and add it to your project. 

 

https://sourceforge.net/projects/geotools/files/GeoTools%2013%20Releases/13.0/geotools-13.0-bin.zip/download

 

The following code with generate a set of grid “agents” that can be added to the GIS display like any other agent class.  I wrote this example so that it works in the Repast Geography demo and you can put this somewhere in the context builder.  The attached image shows the result.

 

double lon1 = -88.2;

double lon2 = -87.2;

double lat1 = 41.4;

double lat2 = 42.0;

 

ReferencedEnvelope gridBounds = new ReferencedEnvelope(

                   lon1, lon2, lat1, lat2, DefaultGeographicCRS.WGS84);

          

SimpleFeatureSource grid = Grids.createSquareGrid(gridBounds, 0.05);

             

SimpleFeatureIterator fiter = null;

List<SimpleFeature> features = new ArrayList<SimpleFeature>();

try {

       fiter = grid.getFeatures().features();

                    

       while(fiter.hasNext()){

              features.add(fiter.next());

       }

} catch (IOException e) {

       e.printStackTrace();

} finally{

       fiter.close();

}

          

for (SimpleFeature feature : features){

       Geometry geom = (Geometry)feature.getDefaultGeometry();

           

       geom  = (Polygon)feature.getDefaultGeometry();

 

       GridPolygon gp = new GridPolygon();

 

       context.add(gp);

       geography.move(gp, geom);       

}

 

It also assumes you have a simple GridPolygon agent class:

 

package geography;

 

public class GridPolygon {

 

}

 

And a style for the GridPolygon:

 

package geography;

 

import gov.nasa.worldwind.render.SurfacePolygon;

import gov.nasa.worldwind.render.SurfaceShape;

 

import java.awt.Color;

 

import repast.simphony.visualization.gis3D.style.SurfaceShapeStyle;

 

public class GridPolygonStyle implements SurfaceShapeStyle<GridPolygon>{

 

       @Override

       public SurfaceShape getSurfaceShape(GridPolygon object, SurfaceShape shape) {

              return new SurfacePolygon();

       }

 

       @Override

       public Color getFillColor(GridPolygon zone) {

              return null;

       }

 

       @Override

       public double getFillOpacity(GridPolygon obj) {

              return 0.0;

       }

 

       /**

       * If the zone has water then indicate with a BLUE outline.

       */

       @Override

       public Color getLineColor(GridPolygon zone) {

                     return Color.white;

       }

 

       @Override

       public double getLineOpacity(GridPolygon obj) {

              return 1.0;

       }

 

       @Override

       public double getLineWidth(GridPolygon obj) {

              return 3;

       }

}

 

 

 

From: Meshal Al-Harbi [[hidden email]]
Sent: Thursday, August 04, 2016 11:14 AM
To: [hidden email]; [hidden email]
Subject: [Repast-interest] combining Grid and Geography projections in one display.

 

Hi everyone,

 

I have a grid projection that has number of agents that represents a certain shape. I also have a geography layer that shows ITN and topography layers. I would like to have the grid layer on top of the geography layer in one display. any help please ?

 

Thanks in advance ,,

 

 

<grid.jpg>

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

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