NASA World Wind

gov.nasa.worldwindx.examples.util
Class ShapefileLoader

java.lang.Object
  extended by gov.nasa.worldwindx.examples.util.ShapefileLoader

public class ShapefileLoader
extends Object

Converts Shapefile geometry into World Wind renderable objects. Shapefile geometries are mapped to World Wind objects as follows:

Shapefile GeometryWorld Wind Object
PointWWIcon
MultiPointList of WWIcon
PolylineSurfacePolylines
PolygonSurfacePolygons

Shapefiles do not contain a standard definition for color and other visual attributes. Though some Shapefiles contain color information in each record's key-value attributes, ShapefileLoader does not attempt to interpret that information. Instead, the World Wind renderable objects created by ShapefileLoader are assigned a random color. Callers can replace or extend this behavior by defining a subclass of ShapefileLoader and overriding the following methods:

.


Field Summary
protected  int numPolygonsPerLayer
          Indicates the maximum number of polygons to place in a layer before creating an additional layer.
protected static RandomShapeAttributes randomAttrs
           
 
Constructor Summary
ShapefileLoader()
          Constructs a ShapefileLoader, but otherwise does nothing.
 
Method Summary
protected  void addRenderablesForMultiPoints(gov.nasa.worldwind.formats.shapefile.Shapefile shp, RenderableLayer layer)
           
protected  void addRenderablesForPoints(gov.nasa.worldwind.formats.shapefile.Shapefile shp, RenderableLayer layer)
           
protected  void addRenderablesForPolygons(gov.nasa.worldwind.formats.shapefile.Shapefile shp, List<Layer> layers)
          Creates renderables for all the polygons in the shapefile.
protected  void addRenderablesForPolylines(gov.nasa.worldwind.formats.shapefile.Shapefile shp, RenderableLayer layer)
           
 Layer createLayerFromShapefile(gov.nasa.worldwind.formats.shapefile.Shapefile shp)
          Creates a Layer from a general Shapefile.
 Layer createLayerFromSource(Object source)
          Creates a Layer from a general Shapefile source.
 List<Layer> createLayersFromShapefile(gov.nasa.worldwind.formats.shapefile.Shapefile shp)
          Creates a list of Layers containing shapes from a Shapefile.
 List<Layer> createLayersFromSource(Object source)
          Creates a list of Layers containing shapes from a Shapefile.
protected  Renderable createPoint(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record, double latDegrees, double lonDegrees, PointPlacemarkAttributes attrs)
           
protected  PointPlacemarkAttributes createPointAttributes(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record)
           
protected  void createPolygon(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record, ShapeAttributes attrs, RenderableLayer layer)
           
protected  ShapeAttributes createPolygonAttributes(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record)
           
protected  Renderable createPolyline(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record, ShapeAttributes attrs)
           
protected  Renderable createPolyline(gov.nasa.worldwind.formats.shapefile.Shapefile shp, ShapeAttributes attrs)
           
protected  ShapeAttributes createPolylineAttributes(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record)
           
protected  Double getHeight(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record)
          Get the height of a record.
 int getNumPolygonsPerLayer()
          Indicates the maximum number of polygon renderables to place in a single layer.
 void setNumPolygonsPerLayer(int numPolygonsPerLayer)
          Specifies the maximum number of polygon renderables to place in a single layer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numPolygonsPerLayer

protected int numPolygonsPerLayer
Indicates the maximum number of polygons to place in a layer before creating an additional layer.


randomAttrs

protected static final RandomShapeAttributes randomAttrs
Constructor Detail

ShapefileLoader

public ShapefileLoader()
Constructs a ShapefileLoader, but otherwise does nothing.

Method Detail

addRenderablesForMultiPoints

protected void addRenderablesForMultiPoints(gov.nasa.worldwind.formats.shapefile.Shapefile shp,
                                            RenderableLayer layer)

addRenderablesForPoints

protected void addRenderablesForPoints(gov.nasa.worldwind.formats.shapefile.Shapefile shp,
                                       RenderableLayer layer)

addRenderablesForPolygons

protected void addRenderablesForPolygons(gov.nasa.worldwind.formats.shapefile.Shapefile shp,
                                         List<Layer> layers)
Creates renderables for all the polygons in the shapefile. Polygon is the only shape that potentially returns a more than one layer, which it does when the polygons per layer limit is exceeded.

Parameters:
shp - the shapefile to read
layers - a list in which to place the layers created. May not be null.

addRenderablesForPolylines

protected void addRenderablesForPolylines(gov.nasa.worldwind.formats.shapefile.Shapefile shp,
                                          RenderableLayer layer)

createLayerFromShapefile

public Layer createLayerFromShapefile(gov.nasa.worldwind.formats.shapefile.Shapefile shp)
Creates a Layer from a general Shapefile.

Parameters:
shp - the Shapefile to create a layer for.
Returns:
a Layer that renders the Shapefile's contents on the surface of the Globe.
Throws:
IllegalArgumentException - if the Shapefile is null, or if the Shapefile's primitive type is unrecognized.

createLayerFromSource

public Layer createLayerFromSource(Object source)
Creates a Layer from a general Shapefile source. The source type may be one of the following:

Parameters:
source - the source of the Shapefile.
Returns:
a Layer that renders the Shapefile's contents on the surface of the Globe.
Throws:
IllegalArgumentException - if the source is null or an empty string, or if the Shapefile's primitive type is unrecognized.

createLayersFromShapefile

public List<Layer> createLayersFromShapefile(gov.nasa.worldwind.formats.shapefile.Shapefile shp)
Creates a list of Layers containing shapes from a Shapefile.

For polygon shapes, the maximum number of polygons to add to a layer can be specified. By default it's 5000. If there are more polygons in the shapefile than the maximum, new layers are created as needed, with each holding no more than the maximum. All but the first layer is disabled to avoid bogging down the display trying to render an excessive number of shapes. The application can enable the layers selectively to maintain performance.

Parameters:
shp - the source of the Shapefile.
Returns:
a Layer that renders the Shapefile's contents on the surface of the Globe.
Throws:
IllegalArgumentException - if the shapefile is null or an empty string, or if the Shapefile's primitive type is unrecognized.

createLayersFromSource

public List<Layer> createLayersFromSource(Object source)
Creates a list of Layers containing shapes from a Shapefile.

For polygon shapes, the maximum number of polygons to add to a layer can be specified. By default it's 5000. If there are more polygons in the shapefile than the maximum, new layers are created as needed, with each holding no more than the maximum. All but the first layer is disabled to avoid bogging down the display trying to render an excessive number of shapes. The application can enable the layers selectively to maintain performance.

The source type may be one of the following:

Parameters:
source - the source of the Shapefile.
Returns:
a Layer that renders the Shapefile's contents on the surface of the Globe.
Throws:
IllegalArgumentException - if the source is null or an empty string, or if the Shapefile's primitive type is unrecognized.

createPoint

protected Renderable createPoint(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record,
                                 double latDegrees,
                                 double lonDegrees,
                                 PointPlacemarkAttributes attrs)

createPointAttributes

protected PointPlacemarkAttributes createPointAttributes(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record)

createPolygon

protected void createPolygon(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record,
                             ShapeAttributes attrs,
                             RenderableLayer layer)

createPolygonAttributes

protected ShapeAttributes createPolygonAttributes(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record)

createPolyline

protected Renderable createPolyline(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record,
                                    ShapeAttributes attrs)

createPolyline

protected Renderable createPolyline(gov.nasa.worldwind.formats.shapefile.Shapefile shp,
                                    ShapeAttributes attrs)

createPolylineAttributes

protected ShapeAttributes createPolylineAttributes(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record)

getHeight

protected Double getHeight(gov.nasa.worldwind.formats.shapefile.ShapefileRecord record)
Get the height of a record.

Parameters:
record - shape for which to find height
Returns:
the height of the shape, or null if there is no height.

getNumPolygonsPerLayer

public int getNumPolygonsPerLayer()
Indicates the maximum number of polygon renderables to place in a single layer. If this limit is exceeded an additional layer is added.

Returns:
the maximum number of polygons to place in a layer.

setNumPolygonsPerLayer

public void setNumPolygonsPerLayer(int numPolygonsPerLayer)
Specifies the maximum number of polygon renderables to place in a single layer. If this limit is exceeded an additional layer is added.

Parameters:
numPolygonsPerLayer - the maximum number of polygons to place in a layer.
Throws:
IllegalArgumentException - if the number is less than 1.

NASA World Wind