AnyLogic
Expand
Font size
All Implemented Interfaces:
Serializable
Enclosing class:
ShapeGISMap

public static class ShapeGISMap.Layer
extends Object
implements Serializable
Class which stores GIS map layer information
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Constructor Summary

ConstructorDescription
Layer(String shapeFileName, Color lineColor, Color fillColor, boolean visible)
Creates new Layer descriptor
Layer(String shapeFileName, String dbfFileName, Color lineColor, Color fillColor, int objectNameColumnIndex, boolean visible)
Deprecated.

Method Summary

Modifier and TypeMethodDescription
voidforAllObjects(BiConsumer<org.locationtech.jts.geom.Geometry,org.geotools.api.feature.simple.SimpleFeature> action)
Reads the shapefile (with optional filtering, e.g.
voidforAllObjects(BiFunction<org.geotools.api.filter.FilterFactory,org.geotools.api.feature.type.FeatureType,org.geotools.api.filter.Filter> filterProvider, BiConsumer<org.locationtech.jts.geom.Geometry,org.geotools.api.feature.simple.SimpleFeature> action)
Same as #forAllObjects(Consumer) but applies the given filtering when reading shapefile.
booleanisVisible() 
voidsetFillColor(List<Integer> shapes, Color color)
Sets the new fill color for the given shapes in the shape file.
voidsetLineColor(List<Integer> shapes, Color color)
Sets the new line color for the given shapes in the shape file.
voidsetVisible(boolean visible) 

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

Layer

@Deprecated
public Layer(String shapeFileName,
 String dbfFileName,
 Color lineColor,
 Color fillColor,
 int objectNameColumnIndex,
 boolean visible)
Deprecated.

Layer

public Layer(String shapeFileName,
 Color lineColor,
 Color fillColor,
 boolean visible)
Creates new Layer descriptor
Parameters:
shapeFileName - GIS Map Shape file name (.shp) with shapes of the layer
lineColor - default line color for objects in this layer
fillColor - default fill color for objects in this layer
visible - initial visibility state

Method Details

forAllObjects

public void forAllObjects(BiConsumer<org.locationtech.jts.geom.Geometry,org.geotools.api.feature.simple.SimpleFeature> action)
Reads the shapefile (with optional filtering, e.g. by clipping or by name) and executes the given action for each element found (which could be a geometry of polyline, polygon, point, or a collection of those)
Parameters:
action - the action to be called on each geometry read from the file, after filtering (if any). If shapefile contains geometry collection with a single element inside, it is handled 'unwrapped' (the surrounding collection isn't returned).
Action example (here 'g' stands for Geometry and 'f' for SimpleFeature which may be used to access data from DBF-file records):
 forAllObjects((g, f) -> {
        // Data from DBF file record:
        traceln("DBF attribute: " + f.getAttribute("CNTRY_NAME") + " : " + f.getAttribute("AREA"));
 
        // Shapefile (geometry) data:
        int n = g.getNumGeometries();
        if (n > 1) {
                traceln("geometry list, n: " + n);
        }
        for (int i = 0; i < n; i++) {
                var element = g.getGeometryN(i); // returns 'g' itself, if n == 1
                if (element instanceof org.locationtech.jts.geom.Polygon geometry) {
                        var exteriorRing = geometry.getExteriorRing();
                        traceln("polygon with number of points of exterior ring: " + exteriorRing.getNumPoints());
                        double[] latLonPoints = java.util.stream.Stream.of(exteriorRing.getCoordinates())
                                                .flatMapToDouble(coord -> java.util.stream.DoubleStream.of( coord.y, coord.x ))
                                                .toArray();
                        // Use the following code to access the 'holes', if needed:
                        //for (int j = 0; j < geometry.getNumInteriorRing(); j++) {
                        //      var interior = geometry.getInteriorRingN(j);
                        //}
                } else if (element instanceof org.locationtech.jts.geom.Point geometry) {
                        traceln("point with lat,lon: " + geometry.getY() + ", " + geometry.getX());
                } else if (element instanceof org.locationtech.jts.geom.LineString geometry) {
                        traceln("line with number of points: " + geometry.getNumPoints());
                } else {
                        traceln("unknown geometry: " + element.getClass());
                }
        }
 });
 

forAllObjects

public void forAllObjects(BiFunction<org.geotools.api.filter.FilterFactory,org.geotools.api.feature.type.FeatureType,org.geotools.api.filter.Filter> filterProvider,
 BiConsumer<org.locationtech.jts.geom.Geometry,org.geotools.api.feature.simple.SimpleFeature> action)
Same as #forAllObjects(Consumer) but applies the given filtering when reading shapefile.
Parameters:
filterProvider - may be null (to disable filtering), or otherwise a code constructing Filter instance. Two arguments are provided here: FilterFactory (ff in the code below) instance (provided for convenience, but may also be obtained using CommonFactoryFinder.getFilterFactory()), and FeatureType (schema in the code below) - the schema that will apply to features retrieved from the shapefile (may be used e.g. to check the CSR used in the file or other common attributes).
Here are some Filter examples:
  • Filter by DBF-contained info:
     forAllObjects(
       (ff, schema) -> ff.equals( ff.property("CNTRY_NAME"), ff.literal("United States") ),
       (g, f) -> { ... });
     
  • Filter by bounds:
     forAllObjects(
       (ff, schema) -> ff.bbox(
         schema.getGeometryDescriptor().getLocalName(),
         -88, 41, -87, 42,
         null),
       (g, f) -> { ... });
     
  • Combine filters:
     var attributeFilter = // ...
     var boundsFilter = // ...
     var combinedFilter = ff.and(attributeFilter, boundsFilter);
     
action - see forAllObjects(BiConsumer)

isVisible

public boolean isVisible()

setVisible

public void setVisible(boolean visible)

setLineColor

public void setLineColor(List<Integer> shapes,
 Color color)
Sets the new line color for the given shapes in the shape file. WARNING: This is a temporary API, it may be replaced in the future versions.
Parameters:
shapes - the list of shape indices, 0-based
color - the new line color

setFillColor

public void setFillColor(List<Integer> shapes,
 Color color)
Sets the new fill color for the given shapes in the shape file. WARNING: This is a temporary API, it may be replaced in the future versions.
Parameters:
shapes - the list of shape indices, 0-based
color - the new fill color