Population data sometimes comes as mesh-based data:

Cell location Population

POLYGON(0 0, 1 0, 1 1, 0 1)

3245

POLYGON(1 0, 2 0, 2 1, 1 1)

245

For each cell of the mesh, we have:

  • The location

  • The total population for that location

One option to visualize this data is to use extruded shapes for each cell. The height and color of the extruded shape depend on the value of the Population property.

lls vectorpainting population density mesh

To achieve this visualization, you need:

//Create an ALspStyleTargetProvider which converts the 2D rectangle shape to an extruded shape
//The height of the extruded shape depends on the value of the population property
ALspStyleTargetProvider styleTargetProvider = new ALspStyleTargetProvider() {
  @Override
  public void getStyleTargetsSFCT(Object aObject, TLspContext aContext, List<Object> aResultSFCT) {
    ILcdShape shape = ALcdShape.fromDomainObject(aObject);
    int population = (Integer) ((ILcdDataObject) aObject).getValue(populationProperty);
    TLcdExtrudedShape extrudedShape = new TLcdExtrudedShape(shape, 0, population);
    aResultSFCT.add(extrudedShape);
  }
};

//Create an ILspStyler which uses
// - The style target provider to ensure that extruded shapes are painted
// - A TLspParameterizedFillStyle to make the color of the extruded shape depend on the property
ILspStyler bodyStyler = new ALspStyler() {
  private final TLspParameterizedFillStyle fStyle =
      TLspParameterizedFillStyle.newBuilder()
                                .color(mixmap(toFloat(attribute(Integer.class, populationProperty)), densityColorMap))
                                .build();

  @Override
  public void style(Collection<?> aObjects, ALspStyleCollector aStyleCollector, TLspContext aContext) {
    aStyleCollector.objects(aObjects)
                   .style(fStyle)
                   .geometry(styleTargetProvider)
                   .submit();
  }
};

//Install the styler on the layer
TLspLayer layer = TLspShapeLayerBuilder.newBuilder()
                                       .model(aModel)
                                       .bodyStyler(TLspPaintState.REGULAR, bodyStyler)
                                       .selectableSupported(false)
                                       .build();