The shape data source

The IlvShapeDataSource class is a specialized data source that reads ESRI shapefiles.

Reading Shapefiles

The easiest way of reading shapefiles is to use the dedicated data source:
// Create the data source
IlvShapeDataSource source = new IlvShapeDataSource(fileName);
// affect the manager
source.setManager(manager);
// start the data source.
try {
  source.start();
} catch (Exception e) {
  e.printStackTrace();
}
In this example, the data source is simply invoked and started. You have to use the setManager method to specify the manager into which the graphic objects are inserted. Graphic objects are instances of IlvMapPolyline, IlvMapGraphicPath or IlvMapPoint, depending on the feature contained in the shapefile. Additionally, the data source creates an IlvMapLayer. You can specify a IlvMapStyle to change the rendering of the graphic objects in this layer.

Filtering Shapefiles

If the shape file you read has an associated dbf file, you can filter a subset of the file content through the setfilter method. For example, the following code will only load the records which have a "NAME" property with a value "usa".
source.setFilter(new IlvSplitEqualsFilter("NAME", "usa", true);

Modifying graphic object rendering

The following example shows how to modify the rendering of the graphic objects produced by this data source by changing the style of the IlvMapLayer of the data source.
// create the data source
IlvShapeDataSource source = new IlvShapeDataSource(fileName);
source.setManager(manager);
// Assuming that the geometry of the shape file are areas.
IlvGraphicPathStyle style = new IlvGraphicPathStyle();
source.getInsertionLayer().setStyle(style);
style.setPaint(Color.blue);
try {
  source.start();
} catch (Exception e) {
  e.printStackTrace();
}
If you are not sure of the type of objects contained in the shape file, you can use the setAttribute method on the layer style, for example:
    IlvMapLayer layer = source.getInsertionLayer();
    layer.getStyle().setAttribute(IlvPolylineStyle.FOREGROUND,Color.black);
      layer.getStyle().setAttribute(IlvPolylineStyle.BACKGROUND,new
    Color(1,1,0.8f));