Visualizing 2D and 3D GIS objects

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

Visualizing 2D and 3D GIS objects

Yared Abayneh
Hi,

I have a question on how to visualize GIS objects - shape files of points, polylines and polygon features. Using the Geography model as an example, I managed to load point, line and polygon features. However, in the RS runtime environment, I see all the features I loaded as points. I also created style classes (like BufferZoneStyle.java and WaterLineStyle.java in Geography model) and created a GIS Display under the Scenario tree in the RS runtime environment though both did not help.

How does RS identify the feature of a shape file and visualize it accordingly? Should I do something with files in the *.rs folder, for example, editing files such as repast.simphony.action.display.xml and scenario.xml to visualize GIS features as in ArcGIS? Is there any new xml file that I need to create? 

Cheers,
Yared
-------------------------------------------------
Yared Abayneh Abebe,
MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands



------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: Visualizing 2D and 3D GIS objects

Tatara, Eric R.
Yared,

There are two GIS display types - "GIS" which is a 2D projection, and "GIS 3D", which is actually a 2D projection wrapped around a globe, similar to Google Earth.  The GIS 3D display works the same as the other Repast display in that you simply define the style class for each agent class to appear in the display.  The key difference though between the GIS 3D display and the other Repast 2D/3D Cartesian displays, is that the style class for the GIS 3D display needs to reflect the geometry type (point, line, polygon) of the agent layer.  Point layer style classes should implement Repast's MarkStyle or extend Repast's DefaultMarkStyle.  Line or polygon layers should implement Repast's SurfaceShapeStyle interface or extend Repast's DefaultSurfaceShapeStyle.  The SurfaceShapeStyle interface returns a gov.nasa.worldwind.render.SurfaceShape, with common choices for style classes returning either a SurfacePolugon or SurfacePolyline for polygon or line layers.

The GIS 2D display uses Style Layer Descriptor files rather than style classes.  When creating a GIS display, the agent classes can be assigned an SLD file that's created with an SLD editor via the SLD button, or you can use Repast's built in editor using the edit button.  Each agent is assigned a geometry type in the agent style dialog.  The editor will allow basic shapes for points and colors and line thickness for lines and polygons.  The SLD editor also allows you to define Range or Value rules that can change the appearance of the shapes based on the agent properties.  I would advise against using the GIS display with SLD styling (in favor of the GIS 3D with style classes) simply because it can be difficult to setup the proper styling rules compared to the GIS 3D display.

eric

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


From: Yared Abayneh [[hidden email]]
Sent: Wednesday, September 23, 2015 8:50 AM
To: [hidden email]
Subject: [Repast-interest] Visualizing 2D and 3D GIS objects

Hi,

I have a question on how to visualize GIS objects - shape files of points, polylines and polygon features. Using the Geography model as an example, I managed to load point, line and polygon features. However, in the RS runtime environment, I see all the features I loaded as points. I also created style classes (like BufferZoneStyle.java and WaterLineStyle.java in Geography model) and created a GIS Display under the Scenario tree in the RS runtime environment though both did not help.

How does RS identify the feature of a shape file and visualize it accordingly? Should I do something with files in the *.rs folder, for example, editing files such as repast.simphony.action.display.xml and scenario.xml to visualize GIS features as in ArcGIS? Is there any new xml file that I need to create? 

Cheers,
Yared
-------------------------------------------------
Yared Abayneh Abebe,
MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands



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

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

Re: Visualizing 2D and 3D GIS objects

Yared Abayneh
Eric,

Thank you for the explanation. As you mentioned, I found the GIS 3D display with style classes a more convenient implementation than the GIS display.

Regarding the GIS 2D display, I have tried to configure the display using the built in editor (in the runtime environment under Displays > Display Configuration). However, after selecting the layer in the "Agent Selection" window, I do not see the selected layers in the "Agent Style" window. In this window, since the default geometry type is POINT, the display apparently shows all kinds of feature types as point. Would you please comment on why the selected layers do not appear in the "Agent Style" window? I also found out that the repast.simphony.action.display_*.xml file stores the configuration of appearances of the shape files. But I agree that it is painful to edit this file manually. 

I have a couple more related questions.
  1. In my work, for some reason, I want to check the topography (elevation) of a point. As you may know, raster files give a better advantage by representing the whole cell by a single value. However, if I convert that into a shape file of point features, that represents just single points at the centroid of raster cells and other parts of the cell will not have a value. Therefore, the ideal way of dealing with topography is using raster files. The question is, is it possible to work with raster (ASCII) files? If so, which libraries to use? Do you have any example on how to load and if possible visualize topography maps in the RS environment?
  2. I will use the Geography model to formulate this question. In that model, there are three agents loaded from a shape file (radio tower agents, water line agents and zone agents) and GIS agents located randomly with in the geography projection. What if I want to create the GIS agents randomly but only inside the zone agents (the polygons), and in cases where water line agents crosses zone agents, GIS agents should not be created with in some distance of the water line agents? Assume that GIS agents are stationary. I really appreciate any kind of implementation help including which geotools or opengis or jts methods to use, or any peace of code developed before.
 
Thanks for the help!
Yared

-------------------------------------------------
Yared Abayneh Abebe,
MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands




On Friday, September 25, 2015 5:42 AM, "Tatara, Eric R." <[hidden email]> wrote:


Yared,

There are two GIS display types - "GIS" which is a 2D projection, and "GIS 3D", which is actually a 2D projection wrapped around a globe, similar to Google Earth.  The GIS 3D display works the same as the other Repast display in that you simply define the style class for each agent class to appear in the display.  The key difference though between the GIS 3D display and the other Repast 2D/3D Cartesian displays, is that the style class for the GIS 3D display needs to reflect the geometry type (point, line, polygon) of the agent layer.  Point layer style classes should implement Repast's MarkStyle or extend Repast's DefaultMarkStyle.  Line or polygon layers should implement Repast's SurfaceShapeStyle interface or extend Repast's DefaultSurfaceShapeStyle.  The SurfaceShapeStyle interface returns a gov.nasa.worldwind.render.SurfaceShape, with common choices for style classes returning either a SurfacePolugon or SurfacePolyline for polygon or line layers.

The GIS 2D display uses Style Layer Descriptor files rather than style classes.  When creating a GIS display, the agent classes can be assigned an SLD file that's created with an SLD editor via the SLD button, or you can use Repast's built in editor using the edit button.  Each agent is assigned a geometry type in the agent style dialog.  The editor will allow basic shapes for points and colors and line thickness for lines and polygons.  The SLD editor also allows you to define Range or Value rules that can change the appearance of the shapes based on the agent properties.  I would advise against using the GIS display with SLD styling (in favor of the GIS 3D with style classes) simply because it can be difficult to setup the proper styling rules compared to the GIS 3D display.

eric

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


From: Yared Abayneh [[hidden email]]
Sent: Wednesday, September 23, 2015 8:50 AM
To: [hidden email]
Subject: [Repast-interest] Visualizing 2D and 3D GIS objects

Hi,

I have a question on how to visualize GIS objects - shape files of points, polylines and polygon features. Using the Geography model as an example, I managed to load point, line and polygon features. However, in the RS runtime environment, I see all the features I loaded as points. I also created style classes (like BufferZoneStyle.java and WaterLineStyle.java in Geography model) and created a GIS Display under the Scenario tree in the RS runtime environment though both did not help.

How does RS identify the feature of a shape file and visualize it accordingly? Should I do something with files in the *.rs folder, for example, editing files such as repast.simphony.action.display.xml and scenario.xml to visualize GIS features as in ArcGIS? Is there any new xml file that I need to create? 

Cheers,
Yared
-------------------------------------------------
Yared Abayneh Abebe,
MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands





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

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

Re: Visualizing 2D and 3D GIS objects

Tatara, Eric R.

Yared,

 

It seems like there is some issue with the GIS 2D display editor itself that I will investigate further. 

 

There are a few ways to use raster data in your model.   The GeoTools GIS libraries used by Repast include support for a number of raster formats.  GeoTools GridCoverage interface provides a mechanism to store and evaluate 2D grid data and the GeoTools library also supports loading a number of image formats with embedded geography information.  See http://docs.geotools.org/latest/userguide/library/coverage/grid.html for some example code.   Note that the GridCoverage class is included with the GeoTools bundled with Repast, however the complete GeoTools library contains separate library jar files for different raster file types.   If you would like to use GeoTools GridCoverage reader classes, you will need to download GeoTools and include the relevant jar files in your model classpath.

 

Alternately, you could use a custom class to store the 2D raster data in a double array or hashmap and then simply look up values using the agent’s position.  Since the raster data and agent’s position information may be at different resolutions however, you would need to include some simple interpolation or rounding of the position values.

 

To create points inside of a polygon, the most direct way would be to use the mathematical definition of the polygon and then derive agent locations that fall within it, although this may be needlessly complex.  The simplest way would be to start by getting the polygon envelope by using geography.getGeometry(object).getEnvelope() which will give you the min/max x,y coordinate rectangle.  The envelope is a box around the polygon and you can use its dimensions from which to randomly select a set of x,y values for a new random point.  Since there’s a chance the point may actually lie outside the polygon border, you should last check if the point lies within the polygon by using some of the JTS Geometry class methods such as Geometry.within(otherGeom).  See http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html for more details.  Note – you don’t need to use a Repast Geography query for this since it’s directly supported by the JTS Geometry class.

                                               

To restrict the agent points being created close to a line feature, you can further add constraints to the above approach to see if the point lies within a boundary polygon around a line feature.   The BufferZone agent in the Geography demo provides an example of how to do this with GeometryUtils.generateBuffer(), but instead of using the zone agent, you can use an agent with a line feature.  The returned buffer Geometry object will always be a polygon around the provided geometry.

 

eric

 

From: Yared Abayneh [mailto:[hidden email]]
Sent: Thursday, October 01, 2015 4:01 AM
To: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Visualizing 2D and 3D GIS objects

 

Eric,



Thank you for the explanation. As you mentioned, I found the GIS 3D display with style classes a more convenient implementation than the GIS display.



Regarding the GIS 2D display, I have tried to configure the display using the built in editor (in the runtime environment under Displays > Display Configuration). However, after selecting the layer in the "Agent Selection" window, I do not see the selected layers in the "Agent Style" window. In this window, since the default geometry type is POINT, the display apparently shows all kinds of feature types as point. Would you please comment on why the selected layers do not appear in the "Agent Style" window? I also found out that the repast.simphony.action.display_*.xml file stores the configuration of appearances of the shape files. But I agree that it is painful to edit this file manually. 



I have a couple more related questions.

  1. In my work, for some reason, I want to check the topography (elevation) of a point. As you may know, raster files give a better advantage by representing the whole cell by a single value. However, if I convert that into a shape file of point features, that represents just single points at the centroid of raster cells and other parts of the cell will not have a value. Therefore, the ideal way of dealing with topography is using raster files. The question is, is it possible to work with raster (ASCII) files? If so, which libraries to use? Do you have any example on how to load and if possible visualize topography maps in the RS environment?
  2. I will use the Geography model to formulate this question. In that model, there are three agents loaded from a shape file (radio tower agents, water line agents and zone agents) and GIS agents located randomly with in the geography projection. What if I want to create the GIS agents randomly but only inside the zone agents (the polygons), and in cases where water line agents crosses zone agents, GIS agents should not be created with in some distance of the water line agents? Assume that GIS agents are stationary. I really appreciate any kind of implementation help including which geotools or opengis or jts methods to use, or any peace of code developed before.

 

Thanks for the help!

Yared


-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands

 

 

On Friday, September 25, 2015 5:42 AM, "Tatara, Eric R." <[hidden email]> wrote:

 

Yared,

There are two GIS display types - "GIS" which is a 2D projection, and "GIS 3D", which is actually a 2D projection wrapped around a globe, similar to Google Earth.  The GIS 3D display works the same as the other Repast display in that you simply define the style class for each agent class to appear in the display.  The key difference though between the GIS 3D display and the other Repast 2D/3D Cartesian displays, is that the style class for the GIS 3D display needs to reflect the geometry type (point, line, polygon) of the agent layer.  Point layer style classes should implement Repast's MarkStyle or extend Repast's DefaultMarkStyle.  Line or polygon layers should implement Repast's SurfaceShapeStyle interface or extend Repast's DefaultSurfaceShapeStyle.  The SurfaceShapeStyle interface returns a gov.nasa.worldwind.render.SurfaceShape, with common choices for style classes returning either a SurfacePolugon or SurfacePolyline for polygon or line layers.

The GIS 2D display uses Style Layer Descriptor files rather than style classes.  When creating a GIS display, the agent classes can be assigned an SLD file that's created with an SLD editor via the SLD button, or you can use Repast's built in editor using the edit button.  Each agent is assigned a geometry type in the agent style dialog.  The editor will allow basic shapes for points and colors and line thickness for lines and polygons.  The SLD editor also allows you to define Range or Value rules that can change the appearance of the shapes based on the agent properties.  I would advise against using the GIS display with SLD styling (in favor of the GIS 3D with style classes) simply because it can be difficult to setup the proper styling rules compared to the GIS 3D display.

eric

 

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


From: Yared Abayneh [[hidden email]]
Sent: Wednesday, September 23, 2015 8:50 AM
To: [hidden email]
Subject: [Repast-interest] Visualizing 2D and 3D GIS objects

Hi,



I have a question on how to visualize GIS objects - shape files of points, polylines and polygon features. Using the Geography model as an example, I managed to load point, line and polygon features. However, in the RS runtime environment, I see all the features I loaded as points. I also created style classes (like BufferZoneStyle.java and WaterLineStyle.java in Geography model) and created a GIS Display under the Scenario tree in the RS runtime environment though both did not help.



How does RS identify the feature of a shape file and visualize it accordingly? Should I do something with files in the *.rs folder, for example, editing files such as repast.simphony.action.display.xml and scenario.xml to visualize GIS features as in ArcGIS? Is there any new xml file that I need to create? 



Cheers,

Yared

-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands

 


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

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

Re: Visualizing 2D and 3D GIS objects

Yared Abayneh
Eric,

Thank you for your time!

I tried to use raster data (in tif format) using geotools libraries. This is part of my context builder which creates grid projection and loads the tif file.
   
    public Context build(Context context) {
        GridPointTranslator borderRule = new repast.simphony.space.grid.StrictBorders();
        GridBuilderParameters gridParams = GridBuilderParameters.singleOccupancy2D(new SimpleGridAdder(), borderRule, 1929, 1136);
        Grid grid = GridFactoryFinder.createGridFactory(null).createGrid("Grid", context, gridParams);
        try {
            loadRaster(context, grid);
        } catch (IOException e) {
            System.out.println("test error");
        }
        return context;
    }

    private void loadRaster (Context context, Grid grid) throws IOException {
        File file = new File("data/gis_data/test.tif");
        AbstractGridFormat format = GridFormatFinder.findFormat(file);
        GridCoverage2DReader reader = format.getReader(file);
               
        if (reader != null) {
            GridCoverage2D coverage = reader.read(null);
            GridSampleDimension[] gsd = coverage.getSampleDimensions(); // this is just to check if it works
            int dim = gsd.length;
            System.out.println("dim = " + dim);
        } else {
            throw new IOException("No reader");
        }
        context.add(reader);
    }

The problem is that there is error while initializing the simulation (full stack trace shown below). I think I added all the necessary geotools jar files in my model class path. I googled if I could get help online and it looks like that the problem is related to JAI. I can see that the jai_codec, jai_core and jai_imageio jar files are already under C:\RepastSimphony-2.3.1\eclipse\plugins\libs.ext_2.3.1\lib (and I see them under Repast Simphony Development Libraries). What might be the problem?   
 
ERROR [AWT-EventQueue-0] 14:05:28,314 repast.simphony.ui.RSApplication - Error while initializing simulation
java.lang.IllegalArgumentException: ImageRead: No OperationDescriptor is registered in the current operation registry under this name.
    at javax.media.jai.JAI.createNS(JAI.java:1070)
    at javax.media.jai.JAI.create(JAI.java:973)
    at org.geotools.gce.geotiff.GeoTiffReader.read(GeoTiffReader.java:565)
    at stMaarten.StMaartenBuilder.loadRaster(StMaartenBuilder.java:237)
    at stMaarten.StMaartenBuilder.build(StMaartenBuilder.java:88)
    at repast.simphony.dataLoader.engine.ClassNameContextBuilder.build(ClassNameContextBuilder.java:41)
    at repast.simphony.dataLoader.engine.DataLoaderControllerAction.runInitialize(DataLoaderControllerAction.java:48)
    at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:214)
    at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:1)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:292)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
    at repast.simphony.util.collections.NaryTree.preOrderTraversal(NaryTree.java:288)
    at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:212)
    at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:383)
    at repast.simphony.ui.RSApplication.initSim(RSApplication.java:157)
    at repast.simphony.ui.action.InitRun.actionPerformed(InitRun.java:17)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
    at java.awt.Component.processMouseEvent(Component.java:6535)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6300)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4891)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)






On Tuesday, October 6, 2015 1:20 AM, "Tatara, Eric R." <[hidden email]> wrote:


Yared,
 
It seems like there is some issue with the GIS 2D display editor itself that I will investigate further. 
 
There are a few ways to use raster data in your model.   The GeoTools GIS libraries used by Repast include support for a number of raster formats.  GeoTools GridCoverage interface provides a mechanism to store and evaluate 2D grid data and the GeoTools library also supports loading a number of image formats with embedded geography information.  See http://docs.geotools.org/latest/userguide/library/coverage/grid.html for some example code.   Note that the GridCoverage class is included with the GeoTools bundled with Repast, however the complete GeoTools library contains separate library jar files for different raster file types.   If you would like to use GeoTools GridCoverage reader classes, you will need to download GeoTools and include the relevant jar files in your model classpath.
 
Alternately, you could use a custom class to store the 2D raster data in a double array or hashmap and then simply look up values using the agent’s position.  Since the raster data and agent’s position information may be at different resolutions however, you would need to include some simple interpolation or rounding of the position values.
 
To create points inside of a polygon, the most direct way would be to use the mathematical definition of the polygon and then derive agent locations that fall within it, although this may be needlessly complex.  The simplest way would be to start by getting the polygon envelope by using geography.getGeometry(object).getEnvelope() which will give you the min/max x,y coordinate rectangle.  The envelope is a box around the polygon and you can use its dimensions from which to randomly select a set of x,y values for a new random point.  Since there’s a chance the point may actually lie outside the polygon border, you should last check if the point lies within the polygon by using some of the JTS Geometry class methods such as Geometry.within(otherGeom).  See http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html for more details.  Note – you don’t need to use a Repast Geography query for this since it’s directly supported by the JTS Geometry class.
                                               
To restrict the agent points being created close to a line feature, you can further add constraints to the above approach to see if the point lies within a boundary polygon around a line feature.   The BufferZone agent in the Geography demo provides an example of how to do this with GeometryUtils.generateBuffer(), but instead of using the zone agent, you can use an agent with a line feature.  The returned buffer Geometry object will always be a polygon around the provided geometry.
 
eric
 
From: Yared Abayneh [mailto:[hidden email]]
Sent: Thursday, October 01, 2015 4:01 AM
To: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Visualizing 2D and 3D GIS objects
 
Eric,


Thank you for the explanation. As you mentioned, I found the GIS 3D display with style classes a more convenient implementation than the GIS display.



Regarding the GIS 2D display, I have tried to configure the display using the built in editor (in the runtime environment under Displays > Display Configuration). However, after selecting the layer in the "Agent Selection" window, I do not see the selected layers in the "Agent Style" window. In this window, since the default geometry type is POINT, the display apparently shows all kinds of feature types as point. Would you please comment on why the selected layers do not appear in the "Agent Style" window? I also found out that the repast.simphony.action.display_*.xml file stores the configuration of appearances of the shape files. But I agree that it is painful to edit this file manually. 



I have a couple more related questions.
  1. In my work, for some reason, I want to check the topography (elevation) of a point. As you may know, raster files give a better advantage by representing the whole cell by a single value. However, if I convert that into a shape file of point features, that represents just single points at the centroid of raster cells and other parts of the cell will not have a value. Therefore, the ideal way of dealing with topography is using raster files. The question is, is it possible to work with raster (ASCII) files? If so, which libraries to use? Do you have any example on how to load and if possible visualize topography maps in the RS environment?
  2. I will use the Geography model to formulate this question. In that model, there are three agents loaded from a shape file (radio tower agents, water line agents and zone agents) and GIS agents located randomly with in the geography projection. What if I want to create the GIS agents randomly but only inside the zone agents (the polygons), and in cases where water line agents crosses zone agents, GIS agents should not be created with in some distance of the water line agents? Assume that GIS agents are stationary. I really appreciate any kind of implementation help including which geotools or opengis or jts methods to use, or any peace of code developed before.
 

Thanks for the help!
Yared

-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands
 
 
On Friday, September 25, 2015 5:42 AM, "Tatara, Eric R." <[hidden email]> wrote:
 
Yared,

There are two GIS display types - "GIS" which is a 2D projection, and "GIS 3D", which is actually a 2D projection wrapped around a globe, similar to Google Earth.  The GIS 3D display works the same as the other Repast display in that you simply define the style class for each agent class to appear in the display.  The key difference though between the GIS 3D display and the other Repast 2D/3D Cartesian displays, is that the style class for the GIS 3D display needs to reflect the geometry type (point, line, polygon) of the agent layer.  Point layer style classes should implement Repast's MarkStyle or extend Repast's DefaultMarkStyle.  Line or polygon layers should implement Repast's SurfaceShapeStyle interface or extend Repast's DefaultSurfaceShapeStyle.  The SurfaceShapeStyle interface returns a gov.nasa.worldwind.render.SurfaceShape, with common choices for style classes returning either a SurfacePolugon or SurfacePolyline for polygon or line layers.

The GIS 2D display uses Style Layer Descriptor files rather than style classes.  When creating a GIS display, the agent classes can be assigned an SLD file that's created with an SLD editor via the SLD button, or you can use Repast's built in editor using the edit button.  Each agent is assigned a geometry type in the agent style dialog.  The editor will allow basic shapes for points and colors and line thickness for lines and polygons.  The SLD editor also allows you to define Range or Value rules that can change the appearance of the shapes based on the agent properties.  I would advise against using the GIS display with SLD styling (in favor of the GIS 3D with style classes) simply because it can be difficult to setup the proper styling rules compared to the GIS 3D display.

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

From: Yared Abayneh [[hidden email]]
Sent: Wednesday, September 23, 2015 8:50 AM
To: [hidden email]
Subject: [Repast-interest] Visualizing 2D and 3D GIS objects
Hi,


I have a question on how to visualize GIS objects - shape files of points, polylines and polygon features. Using the Geography model as an example, I managed to load point, line and polygon features. However, in the RS runtime environment, I see all the features I loaded as points. I also created style classes (like BufferZoneStyle.java and WaterLineStyle.java in Geography model) and created a GIS Display under the Scenario tree in the RS runtime environment though both did not help.


How does RS identify the feature of a shape file and visualize it accordingly? Should I do something with files in the *.rs folder, for example, editing files such as repast.simphony.action.display.xml and scenario.xml to visualize GIS features as in ArcGIS? Is there any new xml file that I need to create? 


Cheers,
Yared
-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands
 



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

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

Re: Visualizing 2D and 3D GIS objects

Tatara, Eric R.
Yared,

I researched this and discovered that it's caused by strange behavior in the JAI library plugin loader on which the Geotools TIFF reader depends.  Repast does include the JAI libraries as you noticed, however the JAI plugin loader apparently only works using Java's default classloader.  Repast uses it's own plugin loader to load itself and user model libraries and this is conflicting with the JAI plugin process.

To fix this, simply add the JAI libraries to your model /lib folder and ALSO add them to the model runtime classpath.  The JAI libraries (jai_codec.jar, jai_core.jar, jai_imageio.jar) are located in the C:\RepastSimphony-2.3.1\eclipse\plugins\libs.ext_2.3.1\lib folder (as you mentioned).  For TIFF support you also need the following Geotools libraries: gt-geotiff-13.0.jar, imageio-ext-tif-1.1.10.jar, and imageio-ext-utilities-1.1.10.jar and add them to your /lib folder, but DO NOT add them to the runtime classpath as Repast will automatically load these.

Normally, I would advise against mixing libraries that already exist in Repast, however none of the Repast classes use the JAI libraries anymore (they're only included to support Geotools), so I don't think this will cause an issue.

eric

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

From: Yared Abayneh [[hidden email]]
Sent: Thursday, October 08, 2015 7:32 AM
To: [hidden email]; Tatara, Eric R.
Subject: Re: [Repast-interest] Visualizing 2D and 3D GIS objects

Eric,

Thank you for your time!

I tried to use raster data (in tif format) using geotools libraries. This is part of my context builder which creates grid projection and loads the tif file.
   
    public Context build(Context context) {
        GridPointTranslator borderRule = new repast.simphony.space.grid.StrictBorders();
        GridBuilderParameters gridParams = GridBuilderParameters.singleOccupancy2D(new SimpleGridAdder(), borderRule, 1929, 1136);
        Grid grid = GridFactoryFinder.createGridFactory(null).createGrid("Grid", context, gridParams);
        try {
            loadRaster(context, grid);
        } catch (IOException e) {
            System.out.println("test error");
        }
        return context;
    }

    private void loadRaster (Context context, Grid grid) throws IOException {
        File file = new File("data/gis_data/test.tif");
        AbstractGridFormat format = GridFormatFinder.findFormat(file);
        GridCoverage2DReader reader = format.getReader(file);
               
        if (reader != null) {
            GridCoverage2D coverage = reader.read(null);
            GridSampleDimension[] gsd = coverage.getSampleDimensions(); // this is just to check if it works
            int dim = gsd.length;
            System.out.println("dim = " + dim);
        } else {
            throw new IOException("No reader");
        }
        context.add(reader);
    }

The problem is that there is error while initializing the simulation (full stack trace shown below). I think I added all the necessary geotools jar files in my model class path. I googled if I could get help online and it looks like that the problem is related to JAI. I can see that the jai_codec, jai_core and jai_imageio jar files are already under C:\RepastSimphony-2.3.1\eclipse\plugins\libs.ext_2.3.1\lib (and I see them under Repast Simphony Development Libraries). What might be the problem?   
 
ERROR [AWT-EventQueue-0] 14:05:28,314 repast.simphony.ui.RSApplication - Error while initializing simulation
java.lang.IllegalArgumentException: ImageRead: No OperationDescriptor is registered in the current operation registry under this name.
    at javax.media.jai.JAI.createNS(JAI.java:1070)
    at javax.media.jai.JAI.create(JAI.java:973)
    at org.geotools.gce.geotiff.GeoTiffReader.read(GeoTiffReader.java:565)
    at stMaarten.StMaartenBuilder.loadRaster(StMaartenBuilder.java:237)
    at stMaarten.StMaartenBuilder.build(StMaartenBuilder.java:88)
    at repast.simphony.dataLoader.engine.ClassNameContextBuilder.build(ClassNameContextBuilder.java:41)
    at repast.simphony.dataLoader.engine.DataLoaderControllerAction.runInitialize(DataLoaderControllerAction.java:48)
    at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:214)
    at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:1)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:292)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
    at repast.simphony.util.collections.NaryTree.preOrderTraversal(NaryTree.java:288)
    at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:212)
    at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:383)
    at repast.simphony.ui.RSApplication.initSim(RSApplication.java:157)
    at repast.simphony.ui.action.InitRun.actionPerformed(InitRun.java:17)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
    at java.awt.Component.processMouseEvent(Component.java:6535)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6300)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4891)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)






On Tuesday, October 6, 2015 1:20 AM, "Tatara, Eric R." <[hidden email]> wrote:


Yared,
 
It seems like there is some issue with the GIS 2D display editor itself that I will investigate further. 
 
There are a few ways to use raster data in your model.   The GeoTools GIS libraries used by Repast include support for a number of raster formats.  GeoTools GridCoverage interface provides a mechanism to store and evaluate 2D grid data and the GeoTools library also supports loading a number of image formats with embedded geography information.  See http://docs.geotools.org/latest/userguide/library/coverage/grid.html for some example code.   Note that the GridCoverage class is included with the GeoTools bundled with Repast, however the complete GeoTools library contains separate library jar files for different raster file types.   If you would like to use GeoTools GridCoverage reader classes, you will need to download GeoTools and include the relevant jar files in your model classpath.
 
Alternately, you could use a custom class to store the 2D raster data in a double array or hashmap and then simply look up values using the agent’s position.  Since the raster data and agent’s position information may be at different resolutions however, you would need to include some simple interpolation or rounding of the position values.
 
To create points inside of a polygon, the most direct way would be to use the mathematical definition of the polygon and then derive agent locations that fall within it, although this may be needlessly complex.  The simplest way would be to start by getting the polygon envelope by using geography.getGeometry(object).getEnvelope() which will give you the min/max x,y coordinate rectangle.  The envelope is a box around the polygon and you can use its dimensions from which to randomly select a set of x,y values for a new random point.  Since there’s a chance the point may actually lie outside the polygon border, you should last check if the point lies within the polygon by using some of the JTS Geometry class methods such as Geometry.within(otherGeom).  See http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html for more details.  Note – you don’t need to use a Repast Geography query for this since it’s directly supported by the JTS Geometry class.
                                               
To restrict the agent points being created close to a line feature, you can further add constraints to the above approach to see if the point lies within a boundary polygon around a line feature.   The BufferZone agent in the Geography demo provides an example of how to do this with GeometryUtils.generateBuffer(), but instead of using the zone agent, you can use an agent with a line feature.  The returned buffer Geometry object will always be a polygon around the provided geometry.
 
eric
 
From: Yared Abayneh [mailto:[hidden email]]
Sent: Thursday, October 01, 2015 4:01 AM
To: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Visualizing 2D and 3D GIS objects
 
Eric,


Thank you for the explanation. As you mentioned, I found the GIS 3D display with style classes a more convenient implementation than the GIS display.



Regarding the GIS 2D display, I have tried to configure the display using the built in editor (in the runtime environment under Displays > Display Configuration). However, after selecting the layer in the "Agent Selection" window, I do not see the selected layers in the "Agent Style" window. In this window, since the default geometry type is POINT, the display apparently shows all kinds of feature types as point. Would you please comment on why the selected layers do not appear in the "Agent Style" window? I also found out that the repast.simphony.action.display_*.xml file stores the configuration of appearances of the shape files. But I agree that it is painful to edit this file manually. 



I have a couple more related questions.
  1. In my work, for some reason, I want to check the topography (elevation) of a point. As you may know, raster files give a better advantage by representing the whole cell by a single value. However, if I convert that into a shape file of point features, that represents just single points at the centroid of raster cells and other parts of the cell will not have a value. Therefore, the ideal way of dealing with topography is using raster files. The question is, is it possible to work with raster (ASCII) files? If so, which libraries to use? Do you have any example on how to load and if possible visualize topography maps in the RS environment?
  2. I will use the Geography model to formulate this question. In that model, there are three agents loaded from a shape file (radio tower agents, water line agents and zone agents) and GIS agents located randomly with in the geography projection. What if I want to create the GIS agents randomly but only inside the zone agents (the polygons), and in cases where water line agents crosses zone agents, GIS agents should not be created with in some distance of the water line agents? Assume that GIS agents are stationary. I really appreciate any kind of implementation help including which geotools or opengis or jts methods to use, or any peace of code developed before.
 

Thanks for the help!
Yared

-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands
 
 
On Friday, September 25, 2015 5:42 AM, "Tatara, Eric R." <[hidden email]> wrote:
 
Yared,

There are two GIS display types - "GIS" which is a 2D projection, and "GIS 3D", which is actually a 2D projection wrapped around a globe, similar to Google Earth.  The GIS 3D display works the same as the other Repast display in that you simply define the style class for each agent class to appear in the display.  The key difference though between the GIS 3D display and the other Repast 2D/3D Cartesian displays, is that the style class for the GIS 3D display needs to reflect the geometry type (point, line, polygon) of the agent layer.  Point layer style classes should implement Repast's MarkStyle or extend Repast's DefaultMarkStyle.  Line or polygon layers should implement Repast's SurfaceShapeStyle interface or extend Repast's DefaultSurfaceShapeStyle.  The SurfaceShapeStyle interface returns a gov.nasa.worldwind.render.SurfaceShape, with common choices for style classes returning either a SurfacePolugon or SurfacePolyline for polygon or line layers.

The GIS 2D display uses Style Layer Descriptor files rather than style classes.  When creating a GIS display, the agent classes can be assigned an SLD file that's created with an SLD editor via the SLD button, or you can use Repast's built in editor using the edit button.  Each agent is assigned a geometry type in the agent style dialog.  The editor will allow basic shapes for points and colors and line thickness for lines and polygons.  The SLD editor also allows you to define Range or Value rules that can change the appearance of the shapes based on the agent properties.  I would advise against using the GIS display with SLD styling (in favor of the GIS 3D with style classes) simply because it can be difficult to setup the proper styling rules compared to the GIS 3D display.

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

From: Yared Abayneh [[hidden email]]
Sent: Wednesday, September 23, 2015 8:50 AM
To: [hidden email]
Subject: [Repast-interest] Visualizing 2D and 3D GIS objects
Hi,


I have a question on how to visualize GIS objects - shape files of points, polylines and polygon features. Using the Geography model as an example, I managed to load point, line and polygon features. However, in the RS runtime environment, I see all the features I loaded as points. I also created style classes (like BufferZoneStyle.java and WaterLineStyle.java in Geography model) and created a GIS Display under the Scenario tree in the RS runtime environment though both did not help.


How does RS identify the feature of a shape file and visualize it accordingly? Should I do something with files in the *.rs folder, for example, editing files such as repast.simphony.action.display.xml and scenario.xml to visualize GIS features as in ArcGIS? Is there any new xml file that I need to create? 


Cheers,
Yared
-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands
 



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

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

Re: Visualizing 2D and 3D GIS objects

Tatara, Eric R.
Another solution that I just tried is to insert the following line in your ContextBuilder class on a line before you call loadRaster(...):

Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

With this approach, you don't need to copy the JAI libraries or add them to the classpath as I described in my previous message. 

eric

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


From: Tatara, Eric R.
Sent: Thursday, October 08, 2015 8:51 PM
To: Yared Abayneh; [hidden email]
Subject: RE: [Repast-interest] Visualizing 2D and 3D GIS objects

Yared,

I researched this and discovered that it's caused by strange behavior in the JAI library plugin loader on which the Geotools TIFF reader depends.  Repast does include the JAI libraries as you noticed, however the JAI plugin loader apparently only works using Java's default classloader.  Repast uses it's own plugin loader to load itself and user model libraries and this is conflicting with the JAI plugin process.

To fix this, simply add the JAI libraries to your model /lib folder and ALSO add them to the model runtime classpath.  The JAI libraries (jai_codec.jar, jai_core.jar, jai_imageio.jar) are located in the C:\RepastSimphony-2.3.1\eclipse\plugins\libs.ext_2.3.1\lib folder (as you mentioned).  For TIFF support you also need the following Geotools libraries: gt-geotiff-13.0.jar, imageio-ext-tif-1.1.10.jar, and imageio-ext-utilities-1.1.10.jar and add them to your /lib folder, but DO NOT add them to the runtime classpath as Repast will automatically load these.

Normally, I would advise against mixing libraries that already exist in Repast, however none of the Repast classes use the JAI libraries anymore (they're only included to support Geotools), so I don't think this will cause an issue.

eric

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

From: Yared Abayneh [[hidden email]]
Sent: Thursday, October 08, 2015 7:32 AM
To: [hidden email]; Tatara, Eric R.
Subject: Re: [Repast-interest] Visualizing 2D and 3D GIS objects

Eric,

Thank you for your time!

I tried to use raster data (in tif format) using geotools libraries. This is part of my context builder which creates grid projection and loads the tif file.
   
    public Context build(Context context) {
        GridPointTranslator borderRule = new repast.simphony.space.grid.StrictBorders();
        GridBuilderParameters gridParams = GridBuilderParameters.singleOccupancy2D(new SimpleGridAdder(), borderRule, 1929, 1136);
        Grid grid = GridFactoryFinder.createGridFactory(null).createGrid("Grid", context, gridParams);
        try {
            loadRaster(context, grid);
        } catch (IOException e) {
            System.out.println("test error");
        }
        return context;
    }

    private void loadRaster (Context context, Grid grid) throws IOException {
        File file = new File("data/gis_data/test.tif");
        AbstractGridFormat format = GridFormatFinder.findFormat(file);
        GridCoverage2DReader reader = format.getReader(file);
               
        if (reader != null) {
            GridCoverage2D coverage = reader.read(null);
            GridSampleDimension[] gsd = coverage.getSampleDimensions(); // this is just to check if it works
            int dim = gsd.length;
            System.out.println("dim = " + dim);
        } else {
            throw new IOException("No reader");
        }
        context.add(reader);
    }

The problem is that there is error while initializing the simulation (full stack trace shown below). I think I added all the necessary geotools jar files in my model class path. I googled if I could get help online and it looks like that the problem is related to JAI. I can see that the jai_codec, jai_core and jai_imageio jar files are already under C:\RepastSimphony-2.3.1\eclipse\plugins\libs.ext_2.3.1\lib (and I see them under Repast Simphony Development Libraries). What might be the problem?   
 
ERROR [AWT-EventQueue-0] 14:05:28,314 repast.simphony.ui.RSApplication - Error while initializing simulation
java.lang.IllegalArgumentException: ImageRead: No OperationDescriptor is registered in the current operation registry under this name.
    at javax.media.jai.JAI.createNS(JAI.java:1070)
    at javax.media.jai.JAI.create(JAI.java:973)
    at org.geotools.gce.geotiff.GeoTiffReader.read(GeoTiffReader.java:565)
    at stMaarten.StMaartenBuilder.loadRaster(StMaartenBuilder.java:237)
    at stMaarten.StMaartenBuilder.build(StMaartenBuilder.java:88)
    at repast.simphony.dataLoader.engine.ClassNameContextBuilder.build(ClassNameContextBuilder.java:41)
    at repast.simphony.dataLoader.engine.DataLoaderControllerAction.runInitialize(DataLoaderControllerAction.java:48)
    at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:214)
    at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:1)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:292)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
    at repast.simphony.util.collections.NaryTree.preOrderTraversal(NaryTree.java:288)
    at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:212)
    at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:383)
    at repast.simphony.ui.RSApplication.initSim(RSApplication.java:157)
    at repast.simphony.ui.action.InitRun.actionPerformed(InitRun.java:17)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
    at java.awt.Component.processMouseEvent(Component.java:6535)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6300)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4891)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)






On Tuesday, October 6, 2015 1:20 AM, "Tatara, Eric R." <[hidden email]> wrote:


Yared,
 
It seems like there is some issue with the GIS 2D display editor itself that I will investigate further. 
 
There are a few ways to use raster data in your model.   The GeoTools GIS libraries used by Repast include support for a number of raster formats.  GeoTools GridCoverage interface provides a mechanism to store and evaluate 2D grid data and the GeoTools library also supports loading a number of image formats with embedded geography information.  See http://docs.geotools.org/latest/userguide/library/coverage/grid.html for some example code.   Note that the GridCoverage class is included with the GeoTools bundled with Repast, however the complete GeoTools library contains separate library jar files for different raster file types.   If you would like to use GeoTools GridCoverage reader classes, you will need to download GeoTools and include the relevant jar files in your model classpath.
 
Alternately, you could use a custom class to store the 2D raster data in a double array or hashmap and then simply look up values using the agent’s position.  Since the raster data and agent’s position information may be at different resolutions however, you would need to include some simple interpolation or rounding of the position values.
 
To create points inside of a polygon, the most direct way would be to use the mathematical definition of the polygon and then derive agent locations that fall within it, although this may be needlessly complex.  The simplest way would be to start by getting the polygon envelope by using geography.getGeometry(object).getEnvelope() which will give you the min/max x,y coordinate rectangle.  The envelope is a box around the polygon and you can use its dimensions from which to randomly select a set of x,y values for a new random point.  Since there’s a chance the point may actually lie outside the polygon border, you should last check if the point lies within the polygon by using some of the JTS Geometry class methods such as Geometry.within(otherGeom).  See http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html for more details.  Note – you don’t need to use a Repast Geography query for this since it’s directly supported by the JTS Geometry class.
                                               
To restrict the agent points being created close to a line feature, you can further add constraints to the above approach to see if the point lies within a boundary polygon around a line feature.   The BufferZone agent in the Geography demo provides an example of how to do this with GeometryUtils.generateBuffer(), but instead of using the zone agent, you can use an agent with a line feature.  The returned buffer Geometry object will always be a polygon around the provided geometry.
 
eric
 
From: Yared Abayneh [mailto:[hidden email]]
Sent: Thursday, October 01, 2015 4:01 AM
To: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Visualizing 2D and 3D GIS objects
 
Eric,


Thank you for the explanation. As you mentioned, I found the GIS 3D display with style classes a more convenient implementation than the GIS display.



Regarding the GIS 2D display, I have tried to configure the display using the built in editor (in the runtime environment under Displays > Display Configuration). However, after selecting the layer in the "Agent Selection" window, I do not see the selected layers in the "Agent Style" window. In this window, since the default geometry type is POINT, the display apparently shows all kinds of feature types as point. Would you please comment on why the selected layers do not appear in the "Agent Style" window? I also found out that the repast.simphony.action.display_*.xml file stores the configuration of appearances of the shape files. But I agree that it is painful to edit this file manually. 



I have a couple more related questions.
  1. In my work, for some reason, I want to check the topography (elevation) of a point. As you may know, raster files give a better advantage by representing the whole cell by a single value. However, if I convert that into a shape file of point features, that represents just single points at the centroid of raster cells and other parts of the cell will not have a value. Therefore, the ideal way of dealing with topography is using raster files. The question is, is it possible to work with raster (ASCII) files? If so, which libraries to use? Do you have any example on how to load and if possible visualize topography maps in the RS environment?
  2. I will use the Geography model to formulate this question. In that model, there are three agents loaded from a shape file (radio tower agents, water line agents and zone agents) and GIS agents located randomly with in the geography projection. What if I want to create the GIS agents randomly but only inside the zone agents (the polygons), and in cases where water line agents crosses zone agents, GIS agents should not be created with in some distance of the water line agents? Assume that GIS agents are stationary. I really appreciate any kind of implementation help including which geotools or opengis or jts methods to use, or any peace of code developed before.
 

Thanks for the help!
Yared

-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands
 
 
On Friday, September 25, 2015 5:42 AM, "Tatara, Eric R." <[hidden email]> wrote:
 
Yared,

There are two GIS display types - "GIS" which is a 2D projection, and "GIS 3D", which is actually a 2D projection wrapped around a globe, similar to Google Earth.  The GIS 3D display works the same as the other Repast display in that you simply define the style class for each agent class to appear in the display.  The key difference though between the GIS 3D display and the other Repast 2D/3D Cartesian displays, is that the style class for the GIS 3D display needs to reflect the geometry type (point, line, polygon) of the agent layer.  Point layer style classes should implement Repast's MarkStyle or extend Repast's DefaultMarkStyle.  Line or polygon layers should implement Repast's SurfaceShapeStyle interface or extend Repast's DefaultSurfaceShapeStyle.  The SurfaceShapeStyle interface returns a gov.nasa.worldwind.render.SurfaceShape, with common choices for style classes returning either a SurfacePolugon or SurfacePolyline for polygon or line layers.

The GIS 2D display uses Style Layer Descriptor files rather than style classes.  When creating a GIS display, the agent classes can be assigned an SLD file that's created with an SLD editor via the SLD button, or you can use Repast's built in editor using the edit button.  Each agent is assigned a geometry type in the agent style dialog.  The editor will allow basic shapes for points and colors and line thickness for lines and polygons.  The SLD editor also allows you to define Range or Value rules that can change the appearance of the shapes based on the agent properties.  I would advise against using the GIS display with SLD styling (in favor of the GIS 3D with style classes) simply because it can be difficult to setup the proper styling rules compared to the GIS 3D display.

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

From: Yared Abayneh [[hidden email]]
Sent: Wednesday, September 23, 2015 8:50 AM
To: [hidden email]
Subject: [Repast-interest] Visualizing 2D and 3D GIS objects
Hi,


I have a question on how to visualize GIS objects - shape files of points, polylines and polygon features. Using the Geography model as an example, I managed to load point, line and polygon features. However, in the RS runtime environment, I see all the features I loaded as points. I also created style classes (like BufferZoneStyle.java and WaterLineStyle.java in Geography model) and created a GIS Display under the Scenario tree in the RS runtime environment though both did not help.


How does RS identify the feature of a shape file and visualize it accordingly? Should I do something with files in the *.rs folder, for example, editing files such as repast.simphony.action.display.xml and scenario.xml to visualize GIS features as in ArcGIS? Is there any new xml file that I need to create? 


Cheers,
Yared
-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands
 



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

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

Re: Visualizing 2D and 3D GIS objects

Yared Abayneh
Eric,

I found the last solution easy to use (copying this line - Thread.currentThread().setContextClassLoader(getClass().getClassLoader());), and now it is working well.

I would like to ask a related question. I managed to load the raster file (.tiff file of digital elevation model) but in which projection should I add this raster file to use it, grid or geography? I tried both but was not successful. In addition, given a point, what might be the method to extract the elevation from the raster file of that point? I spent the whole day looking for that but again I could not find something working.  
 
Cheers,
Yared
-------------------------------------------------
Yared Abayneh Abebe,
MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands




On Friday, October 9, 2015 3:59 AM, "Tatara, Eric R." <[hidden email]> wrote:


Another solution that I just tried is to insert the following line in your ContextBuilder class on a line before you call loadRaster(...):

Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

With this approach, you don't need to copy the JAI libraries or add them to the classpath as I described in my previous message. 

eric

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


From: Tatara, Eric R.
Sent: Thursday, October 08, 2015 8:51 PM
To: Yared Abayneh; [hidden email]
Subject: RE: [Repast-interest] Visualizing 2D and 3D GIS objects

Yared,

I researched this and discovered that it's caused by strange behavior in the JAI library plugin loader on which the Geotools TIFF reader depends.  Repast does include the JAI libraries as you noticed, however the JAI plugin loader apparently only works using Java's default classloader.  Repast uses it's own plugin loader to load itself and user model libraries and this is conflicting with the JAI plugin process.

To fix this, simply add the JAI libraries to your model /lib folder and ALSO add them to the model runtime classpath.  The JAI libraries (jai_codec.jar, jai_core.jar, jai_imageio.jar) are located in the C:\RepastSimphony-2.3.1\eclipse\plugins\libs.ext_2.3.1\lib folder (as you mentioned).  For TIFF support you also need the following Geotools libraries: gt-geotiff-13.0.jar, imageio-ext-tif-1.1.10.jar, and imageio-ext-utilities-1.1.10.jar and add them to your /lib folder, but DO NOT add them to the runtime classpath as Repast will automatically load these.

Normally, I would advise against mixing libraries that already exist in Repast, however none of the Repast classes use the JAI libraries anymore (they're only included to support Geotools), so I don't think this will cause an issue.

eric

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

From: Yared Abayneh [[hidden email]]
Sent: Thursday, October 08, 2015 7:32 AM
To: [hidden email]; Tatara, Eric R.
Subject: Re: [Repast-interest] Visualizing 2D and 3D GIS objects

Eric,

Thank you for your time!

I tried to use raster data (in tif format) using geotools libraries. This is part of my context builder which creates grid projection and loads the tif file.
   
    public Context build(Context context) {
        GridPointTranslator borderRule = new repast.simphony.space.grid.StrictBorders();
        GridBuilderParameters gridParams = GridBuilderParameters.singleOccupancy2D(new SimpleGridAdder(), borderRule, 1929, 1136);
        Grid grid = GridFactoryFinder.createGridFactory(null).createGrid("Grid", context, gridParams);
        try {
            loadRaster(context, grid);
        } catch (IOException e) {
            System.out.println("test error");
        }
        return context;
    }

    private void loadRaster (Context context, Grid grid) throws IOException {
        File file = new File("data/gis_data/test.tif");
        AbstractGridFormat format = GridFormatFinder.findFormat(file);
        GridCoverage2DReader reader = format.getReader(file);
               
        if (reader != null) {
            GridCoverage2D coverage = reader.read(null);
            GridSampleDimension[] gsd = coverage.getSampleDimensions(); // this is just to check if it works
            int dim = gsd.length;
            System.out.println("dim = " + dim);
        } else {
            throw new IOException("No reader");
        }
        context.add(reader);
    }

The problem is that there is error while initializing the simulation (full stack trace shown below). I think I added all the necessary geotools jar files in my model class path. I googled if I could get help online and it looks like that the problem is related to JAI. I can see that the jai_codec, jai_core and jai_imageio jar files are already under C:\RepastSimphony-2.3.1\eclipse\plugins\libs.ext_2.3.1\lib (and I see them under Repast Simphony Development Libraries). What might be the problem?   
 
ERROR [AWT-EventQueue-0] 14:05:28,314 repast.simphony.ui.RSApplication - Error while initializing simulation
java.lang.IllegalArgumentException: ImageRead: No OperationDescriptor is registered in the current operation registry under this name.
    at javax.media.jai.JAI.createNS(JAI.java:1070)
    at javax.media.jai.JAI.create(JAI.java:973)
    at org.geotools.gce.geotiff.GeoTiffReader.read(GeoTiffReader.java:565)
    at stMaarten.StMaartenBuilder.loadRaster(StMaartenBuilder.java:237)
    at stMaarten.StMaartenBuilder.build(StMaartenBuilder.java:88)
    at repast.simphony.dataLoader.engine.ClassNameContextBuilder.build(ClassNameContextBuilder.java:41)
    at repast.simphony.dataLoader.engine.DataLoaderControllerAction.runInitialize(DataLoaderControllerAction.java:48)
    at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:214)
    at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:1)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:292)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
    at repast.simphony.util.collections.NaryTree.preOrderTraversal(NaryTree.java:288)
    at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:212)
    at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:383)
    at repast.simphony.ui.RSApplication.initSim(RSApplication.java:157)
    at repast.simphony.ui.action.InitRun.actionPerformed(InitRun.java:17)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
    at java.awt.Component.processMouseEvent(Component.java:6535)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6300)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4891)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)






On Tuesday, October 6, 2015 1:20 AM, "Tatara, Eric R." <[hidden email]> wrote:


Yared,
 
It seems like there is some issue with the GIS 2D display editor itself that I will investigate further. 
 
There are a few ways to use raster data in your model.   The GeoTools GIS libraries used by Repast include support for a number of raster formats.  GeoTools GridCoverage interface provides a mechanism to store and evaluate 2D grid data and the GeoTools library also supports loading a number of image formats with embedded geography information.  See http://docs.geotools.org/latest/userguide/library/coverage/grid.html for some example code.   Note that the GridCoverage class is included with the GeoTools bundled with Repast, however the complete GeoTools library contains separate library jar files for different raster file types.   If you would like to use GeoTools GridCoverage reader classes, you will need to download GeoTools and include the relevant jar files in your model classpath.
 
Alternately, you could use a custom class to store the 2D raster data in a double array or hashmap and then simply look up values using the agent’s position.  Since the raster data and agent’s position information may be at different resolutions however, you would need to include some simple interpolation or rounding of the position values.
 
To create points inside of a polygon, the most direct way would be to use the mathematical definition of the polygon and then derive agent locations that fall within it, although this may be needlessly complex.  The simplest way would be to start by getting the polygon envelope by using geography.getGeometry(object).getEnvelope() which will give you the min/max x,y coordinate rectangle.  The envelope is a box around the polygon and you can use its dimensions from which to randomly select a set of x,y values for a new random point.  Since there’s a chance the point may actually lie outside the polygon border, you should last check if the point lies within the polygon by using some of the JTS Geometry class methods such as Geometry.within(otherGeom).  See http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html for more details.  Note – you don’t need to use a Repast Geography query for this since it’s directly supported by the JTS Geometry class.
                                               
To restrict the agent points being created close to a line feature, you can further add constraints to the above approach to see if the point lies within a boundary polygon around a line feature.   The BufferZone agent in the Geography demo provides an example of how to do this with GeometryUtils.generateBuffer(), but instead of using the zone agent, you can use an agent with a line feature.  The returned buffer Geometry object will always be a polygon around the provided geometry.
 
eric
 
From: Yared Abayneh [mailto:[hidden email]]
Sent: Thursday, October 01, 2015 4:01 AM
To: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Visualizing 2D and 3D GIS objects
 
Eric,


Thank you for the explanation. As you mentioned, I found the GIS 3D display with style classes a more convenient implementation than the GIS display.



Regarding the GIS 2D display, I have tried to configure the display using the built in editor (in the runtime environment under Displays > Display Configuration). However, after selecting the layer in the "Agent Selection" window, I do not see the selected layers in the "Agent Style" window. In this window, since the default geometry type is POINT, the display apparently shows all kinds of feature types as point. Would you please comment on why the selected layers do not appear in the "Agent Style" window? I also found out that the repast.simphony.action.display_*.xml file stores the configuration of appearances of the shape files. But I agree that it is painful to edit this file manually. 



I have a couple more related questions.
  1. In my work, for some reason, I want to check the topography (elevation) of a point. As you may know, raster files give a better advantage by representing the whole cell by a single value. However, if I convert that into a shape file of point features, that represents just single points at the centroid of raster cells and other parts of the cell will not have a value. Therefore, the ideal way of dealing with topography is using raster files. The question is, is it possible to work with raster (ASCII) files? If so, which libraries to use? Do you have any example on how to load and if possible visualize topography maps in the RS environment?
  2. I will use the Geography model to formulate this question. In that model, there are three agents loaded from a shape file (radio tower agents, water line agents and zone agents) and GIS agents located randomly with in the geography projection. What if I want to create the GIS agents randomly but only inside the zone agents (the polygons), and in cases where water line agents crosses zone agents, GIS agents should not be created with in some distance of the water line agents? Assume that GIS agents are stationary. I really appreciate any kind of implementation help including which geotools or opengis or jts methods to use, or any peace of code developed before.
 

Thanks for the help!
Yared

-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands
 
 
On Friday, September 25, 2015 5:42 AM, "Tatara, Eric R." <[hidden email]> wrote:
 
Yared,

There are two GIS display types - "GIS" which is a 2D projection, and "GIS 3D", which is actually a 2D projection wrapped around a globe, similar to Google Earth.  The GIS 3D display works the same as the other Repast display in that you simply define the style class for each agent class to appear in the display.  The key difference though between the GIS 3D display and the other Repast 2D/3D Cartesian displays, is that the style class for the GIS 3D display needs to reflect the geometry type (point, line, polygon) of the agent layer.  Point layer style classes should implement Repast's MarkStyle or extend Repast's DefaultMarkStyle.  Line or polygon layers should implement Repast's SurfaceShapeStyle interface or extend Repast's DefaultSurfaceShapeStyle.  The SurfaceShapeStyle interface returns a gov.nasa.worldwind.render.SurfaceShape, with common choices for style classes returning either a SurfacePolugon or SurfacePolyline for polygon or line layers.

The GIS 2D display uses Style Layer Descriptor files rather than style classes.  When creating a GIS display, the agent classes can be assigned an SLD file that's created with an SLD editor via the SLD button, or you can use Repast's built in editor using the edit button.  Each agent is assigned a geometry type in the agent style dialog.  The editor will allow basic shapes for points and colors and line thickness for lines and polygons.  The SLD editor also allows you to define Range or Value rules that can change the appearance of the shapes based on the agent properties.  I would advise against using the GIS display with SLD styling (in favor of the GIS 3D with style classes) simply because it can be difficult to setup the proper styling rules compared to the GIS 3D display.

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

From: Yared Abayneh [[hidden email]]
Sent: Wednesday, September 23, 2015 8:50 AM
To: [hidden email]
Subject: [Repast-interest] Visualizing 2D and 3D GIS objects
Hi,


I have a question on how to visualize GIS objects - shape files of points, polylines and polygon features. Using the Geography model as an example, I managed to load point, line and polygon features. However, in the RS runtime environment, I see all the features I loaded as points. I also created style classes (like BufferZoneStyle.java and WaterLineStyle.java in Geography model) and created a GIS Display under the Scenario tree in the RS runtime environment though both did not help.


How does RS identify the feature of a shape file and visualize it accordingly? Should I do something with files in the *.rs folder, for example, editing files such as repast.simphony.action.display.xml and scenario.xml to visualize GIS features as in ArcGIS? Is there any new xml file that I need to create? 


Cheers,
Yared
-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands
 





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

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

Re: Visualizing 2D and 3D GIS objects

Tatara, Eric R.

Yared,

 

Repast projections and displays do not directly support adding of raster data in that they don’t provide any functionality to read/write from the GridCoverage2D object that holds the raster data.  However, you could add the GridCoverage2D object to an agent or just add it to a context and use the context utils to find it by specifying the class type.  I would probably recommend adding it to a single agent whos job is to only hold the raster data.  To look up the values, simply reference the “raster” agent, get the GridCoverage2D from it, and use GridCoverage2D.evaluate() method as described in the Geotools docs:

 

http://docs.geotools.org/latest/userguide/library/coverage/grid.html

http://docs.geotools.org/latest/javadocs/org/geotools/coverage/grid/GridCoverage2D.html

 

To retrieve the value(s) at a specific lat/lon, you use a DirectPosition instance created from the CRS and the lat/lon (x,y):

 

DirectPosition position = new DirectPosition2D( crs, x, y);   

double[] sample = (double[]) coverage.evaluate( position );

 

The returned array will contain all of the values available in the raster data at that point.  Depending on the format of the raster data, your elevation info might be the only data in the array, or one of several values.  The CRS passed to the DirectPosition2D should be the CRS of the x,y points, eg the lat/lon of your agents.  I think the GridCoverage evaluate will convert the points if the CRS in your geography is different from the CRS of the raster data, but you should check if that’s indeed the case.

 

eric

 

From: Yared Abayneh [mailto:[hidden email]]
Sent: Tuesday, October 13, 2015 10:04 AM
To: Tatara, Eric R. <[hidden email]>; [hidden email]
Subject: Re: [Repast-interest] Visualizing 2D and 3D GIS objects

 

Eric,

 

I found the last solution easy to use (copying this line - Thread.currentThread().setContextClassLoader(getClass().getClassLoader());), and now it is working well.

 

I would like to ask a related question. I managed to load the raster file (.tiff file of digital elevation model) but in which projection should I add this raster file to use it, grid or geography? I tried both but was not successful. In addition, given a point, what might be the method to extract the elevation from the raster file of that point? I spent the whole day looking for that but again I could not find something working.  

 

Cheers,

Yared

-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands

 

 

On Friday, October 9, 2015 3:59 AM, "Tatara, Eric R." <[hidden email]> wrote:

 

Another solution that I just tried is to insert the following line in your ContextBuilder class on a line before you call loadRaster(...):

Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

With this approach, you don't need to copy the JAI libraries or add them to the classpath as I described in my previous message. 

eric

 

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


From: Tatara, Eric R.
Sent: Thursday, October 08, 2015 8:51 PM
To: Yared Abayneh; [hidden email]
Subject: RE: [Repast-interest] Visualizing 2D and 3D GIS objects

Yared,

I researched this and discovered that it's caused by strange behavior in the JAI library plugin loader on which the Geotools TIFF reader depends.  Repast does include the JAI libraries as you noticed, however the JAI plugin loader apparently only works using Java's default classloader.  Repast uses it's own plugin loader to load itself and user model libraries and this is conflicting with the JAI plugin process.

To fix this, simply add the JAI libraries to your model /lib folder and ALSO add them to the model runtime classpath.  The JAI libraries (jai_codec.jar, jai_core.jar, jai_imageio.jar) are located in the C:\RepastSimphony-2.3.1\eclipse\plugins\libs.ext_2.3.1\lib folder (as you mentioned).  For TIFF support you also need the following Geotools libraries: gt-geotiff-13.0.jar, imageio-ext-tif-1.1.10.jar, and imageio-ext-utilities-1.1.10.jar and add them to your /lib folder, but DO NOT add them to the runtime classpath as Repast will automatically load these.

Normally, I would advise against mixing libraries that already exist in Repast, however none of the Repast classes use the JAI libraries anymore (they're only included to support Geotools), so I don't think this will cause an issue.

eric

 

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


From: Yared Abayneh [[hidden email]]
Sent: Thursday, October 08, 2015 7:32 AM
To: [hidden email]; Tatara, Eric R.
Subject: Re: [Repast-interest] Visualizing 2D and 3D GIS objects

Eric,

 

Thank you for your time!

 

I tried to use raster data (in tif format) using geotools libraries. This is part of my context builder which creates grid projection and loads the tif file.

   

    public Context build(Context context) {

        GridPointTranslator borderRule = new repast.simphony.space.grid.StrictBorders();
        GridBuilderParameters gridParams = GridBuilderParameters.singleOccupancy2D(new SimpleGridAdder(), borderRule, 1929, 1136);
        Grid grid = GridFactoryFinder.createGridFactory(null).createGrid("Grid", context, gridParams);

        try {

            loadRaster(context, grid);
        } catch (IOException e) {
            System.out.println("test error");
        }

        return context;

    }

 

    private void loadRaster (Context context, Grid grid) throws IOException {
        File file = new File("data/gis_data/test.tif");
        AbstractGridFormat format = GridFormatFinder.findFormat(file);
        GridCoverage2DReader reader = format.getReader(file);
               
        if (reader != null) {
            GridCoverage2D coverage = reader.read(null);
            GridSampleDimension[] gsd = coverage.getSampleDimensions(); // this is just to check if it works
            int dim = gsd.length;
            System.out.println("dim = " + dim);
        } else {
            throw new IOException("No reader");
        }
        context.add(reader);
    }

 

The problem is that there is error while initializing the simulation (full stack trace shown below). I think I added all the necessary geotools jar files in my model class path. I googled if I could get help online and it looks like that the problem is related to JAI. I can see that the jai_codec, jai_core and jai_imageio jar files are already under C:\RepastSimphony-2.3.1\eclipse\plugins\libs.ext_2.3.1\lib (and I see them under Repast Simphony Development Libraries). What might be the problem?   

 

ERROR [AWT-EventQueue-0] 14:05:28,314 repast.simphony.ui.RSApplication - Error while initializing simulation
java.lang.IllegalArgumentException: ImageRead: No OperationDescriptor is registered in the current operation registry under this name.
    at javax.media.jai.JAI.createNS(JAI.java:1070)
    at javax.media.jai.JAI.create(JAI.java:973)
    at org.geotools.gce.geotiff.GeoTiffReader.read(GeoTiffReader.java:565)
    at stMaarten.StMaartenBuilder.loadRaster(StMaartenBuilder.java:237)
    at stMaarten.StMaartenBuilder.build(StMaartenBuilder.java:88)
    at repast.simphony.dataLoader.engine.ClassNameContextBuilder.build(ClassNameContextBuilder.java:41)
    at repast.simphony.dataLoader.engine.DataLoaderControllerAction.runInitialize(DataLoaderControllerAction.java:48)
    at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:214)
    at repast.simphony.engine.controller.DefaultController$2.visit(DefaultController.java:1)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:292)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
    at repast.simphony.util.collections.NaryTree.preOrderTraverals(NaryTree.java:295)
    at repast.simphony.util.collections.NaryTree.preOrderTraversal(NaryTree.java:288)
    at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:212)
    at repast.simphony.engine.controller.DefaultController.runInitialize(DefaultController.java:383)
    at repast.simphony.ui.RSApplication.initSim(RSApplication.java:157)
    at repast.simphony.ui.action.InitRun.actionPerformed(InitRun.java:17)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
    at java.awt.Component.processMouseEvent(Component.java:6535)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6300)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4891)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

 

 

 

 

On Tuesday, October 6, 2015 1:20 AM, "Tatara, Eric R." <[hidden email]> wrote:

 

Yared,

 

It seems like there is some issue with the GIS 2D display editor itself that I will investigate further. 

 

There are a few ways to use raster data in your model.   The GeoTools GIS libraries used by Repast include support for a number of raster formats.  GeoTools GridCoverage interface provides a mechanism to store and evaluate 2D grid data and the GeoTools library also supports loading a number of image formats with embedded geography information.  See http://docs.geotools.org/latest/userguide/library/coverage/grid.html for some example code.   Note that the GridCoverage class is included with the GeoTools bundled with Repast, however the complete GeoTools library contains separate library jar files for different raster file types.   If you would like to use GeoTools GridCoverage reader classes, you will need to download GeoTools and include the relevant jar files in your model classpath.

 

Alternately, you could use a custom class to store the 2D raster data in a double array or hashmap and then simply look up values using the agent’s position.  Since the raster data and agent’s position information may be at different resolutions however, you would need to include some simple interpolation or rounding of the position values.

 

To create points inside of a polygon, the most direct way would be to use the mathematical definition of the polygon and then derive agent locations that fall within it, although this may be needlessly complex.  The simplest way would be to start by getting the polygon envelope by using geography.getGeometry(object).getEnvelope() which will give you the min/max x,y coordinate rectangle.  The envelope is a box around the polygon and you can use its dimensions from which to randomly select a set of x,y values for a new random point.  Since there’s a chance the point may actually lie outside the polygon border, you should last check if the point lies within the polygon by using some of the JTS Geometry class methods such as Geometry.within(otherGeom).  See http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html for more details.  Note – you don’t need to use a Repast Geography query for this since it’s directly supported by the JTS Geometry class.

                                               

To restrict the agent points being created close to a line feature, you can further add constraints to the above approach to see if the point lies within a boundary polygon around a line feature.   The BufferZone agent in the Geography demo provides an example of how to do this with GeometryUtils.generateBuffer(), but instead of using the zone agent, you can use an agent with a line feature.  The returned buffer Geometry object will always be a polygon around the provided geometry.

 

eric

 

From: Yared Abayneh [[hidden email]]
Sent: Thursday, October 01, 2015 4:01 AM
To: Repast List <[hidden email]>
Subject: Re: [Repast-interest] Visualizing 2D and 3D GIS objects

 

Eric,

 

Thank you for the explanation. As you mentioned, I found the GIS 3D display with style classes a more convenient implementation than the GIS display.

 

Regarding the GIS 2D display, I have tried to configure the display using the built in editor (in the runtime environment under Displays > Display Configuration). However, after selecting the layer in the "Agent Selection" window, I do not see the selected layers in the "Agent Style" window. In this window, since the default geometry type is POINT, the display apparently shows all kinds of feature types as point. Would you please comment on why the selected layers do not appear in the "Agent Style" window? I also found out that the repast.simphony.action.display_*.xml file stores the configuration of appearances of the shape files. But I agree that it is painful to edit this file manually. 

 

I have a couple more related questions.

  1. In my work, for some reason, I want to check the topography (elevation) of a point. As you may know, raster files give a better advantage by representing the whole cell by a single value. However, if I convert that into a shape file of point features, that represents just single points at the centroid of raster cells and other parts of the cell will not have a value. Therefore, the ideal way of dealing with topography is using raster files. The question is, is it possible to work with raster (ASCII) files? If so, which libraries to use? Do you have any example on how to load and if possible visualize topography maps in the RS environment?
  2. I will use the Geography model to formulate this question. In that model, there are three agents loaded from a shape file (radio tower agents, water line agents and zone agents) and GIS agents located randomly with in the geography projection. What if I want to create the GIS agents randomly but only inside the zone agents (the polygons), and in cases where water line agents crosses zone agents, GIS agents should not be created with in some distance of the water line agents? Assume that GIS agents are stationary. I really appreciate any kind of implementation help including which geotools or opengis or jts methods to use, or any peace of code developed before.

 

Thanks for the help!

Yared


-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands

 

 

On Friday, September 25, 2015 5:42 AM, "Tatara, Eric R." <[hidden email]> wrote:

 

Yared,

There are two GIS display types - "GIS" which is a 2D projection, and "GIS 3D", which is actually a 2D projection wrapped around a globe, similar to Google Earth.  The GIS 3D display works the same as the other Repast display in that you simply define the style class for each agent class to appear in the display.  The key difference though between the GIS 3D display and the other Repast 2D/3D Cartesian displays, is that the style class for the GIS 3D display needs to reflect the geometry type (point, line, polygon) of the agent layer.  Point layer style classes should implement Repast's MarkStyle or extend Repast's DefaultMarkStyle.  Line or polygon layers should implement Repast's SurfaceShapeStyle interface or extend Repast's DefaultSurfaceShapeStyle.  The SurfaceShapeStyle interface returns a gov.nasa.worldwind.render.SurfaceShape, with common choices for style classes returning either a SurfacePolugon or SurfacePolyline for polygon or line layers.

The GIS 2D display uses Style Layer Descriptor files rather than style classes.  When creating a GIS display, the agent classes can be assigned an SLD file that's created with an SLD editor via the SLD button, or you can use Repast's built in editor using the edit button.  Each agent is assigned a geometry type in the agent style dialog.  The editor will allow basic shapes for points and colors and line thickness for lines and polygons.  The SLD editor also allows you to define Range or Value rules that can change the appearance of the shapes based on the agent properties.  I would advise against using the GIS display with SLD styling (in favor of the GIS 3D with style classes) simply because it can be difficult to setup the proper styling rules compared to the GIS 3D display.

eric

 

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


From: Yared Abayneh [[hidden email]]
Sent: Wednesday, September 23, 2015 8:50 AM
To: [hidden email]
Subject: [Repast-interest] Visualizing 2D and 3D GIS objects

Hi,

 

I have a question on how to visualize GIS objects - shape files of points, polylines and polygon features. Using the Geography model as an example, I managed to load point, line and polygon features. However, in the RS runtime environment, I see all the features I loaded as points. I also created style classes (like BufferZoneStyle.java and WaterLineStyle.java in Geography model) and created a GIS Display under the Scenario tree in the RS runtime environment though both did not help.

 

How does RS identify the feature of a shape file and visualize it accordingly? Should I do something with files in the *.rs folder, for example, editing files such as repast.simphony.action.display.xml and scenario.xml to visualize GIS features as in ArcGIS? Is there any new xml file that I need to create? 

 

Cheers,

Yared

-------------------------------------------------
Yared Abayneh Abebe, MSc
PhD Research Fellow in Urban Water Systems
Environmental Engineering and Water Technology Department
UNESCO-IHE Institute for Water Education
Westvest 7 - P.O.Box 3015
2601 DA Delft, The Netherlands

 

 

 


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

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