Package com.anylogic.engine.presentation
- java.lang.Object
- com.anylogic.engine.presentation.ShapeGISMap.Layer
- 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 | Description |
---|---|
Layer |
Creates new Layer descriptor
|
Layer |
Deprecated.
|
Modifier and Type | Method | Description |
---|---|---|
void | forAllObjects |
Reads the shapefile (with optional filtering, e.g.
|
void | forAllObjects |
Same as
#forAllObjects(Consumer) but applies the given filtering
when reading shapefile. |
boolean | isVisible() | |
void | setFillColor |
Sets the new fill color for the given shapes in the shape file.
|
void | setLineColor |
Sets the new line color for the given shapes in the shape file.
|
void | setVisible |
@Deprecated public Layer(String shapeFileName, String dbfFileName, Color lineColor, Color fillColor, int objectNameColumnIndex, boolean visible)
Deprecated.
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 layerlineColor
- default line color for objects in this layerfillColor
- default fill color for objects in this layervisible
- initial visibility state
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 forGeometry
and 'f' forSimpleFeature
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()); } } });
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 benull
(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 usingCommonFactoryFinder.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);
- Filter by DBF-contained info:
action
- seeforAllObjects(BiConsumer)
public boolean isVisible()
public void setVisible(boolean visible)
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-basedcolor
- the new line color
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-basedcolor
- the new fill color