skip to main content
Defense > Programmer's documentation > Programming with JViews Maps > Introducing the main classes > Readers and writers
 
Readers and writers
Introduces you to the predefined reader/writer classes supplied with JViews Maps.
*Overview of readers and writers
*Presents the predefined reader/writer classes supplied with JViews Maps.
*The pivot format reader and writer
*Describes the classes for the pivot format reader and writer.
*Saved files
*Describes the files saved for a map.
*Saving and reloading a map
*Explains how to save and reload a map.
*Map Export API
*Describes the API for exporting map data.
*The shapefile reader and writer
*Describes the shapefile reader and writer classes and data sources.
*The MID/MIF reader and writer
*Describes the MID/MIF reading and rendering classes and data sources.
*The DTED file reader
*Describes the Digital Terrain Elevation Data (DTED®) read format.
*The image file reader
*Describes a generic image file reader.
*The IBM spatial database readers
*Describes the IBM spatial databases (DB2 and Informix) reader classes, how to use them through data sources, and how to use tiling and multithreading.
*The Oracle spatial reader and writer
*Describes the Oracle® reader and writer classes, using data sources, how to use tiling, multithreading and exporting to an SDO database.
*The GeoTIFF reader
*Describes the classes that allow you to read GEO TIFF files.
*The TIGER/Line reader
*Describes the TIGER/Line® reader for maps related to US census data.
*The DXF reader
*Explains how to read DXF files.
*The KML reader and writer
*Describes the KML reader and writer and exporting KML files.
*The DEM/GTOPO30 reader
*Explains how to read GTOPO30 files.
*The Web Map Server reader
*Explains how to read images from a Web Map Server (WMS).
*The SVG reader
*Explains how to read SVG files.
Overview of readers and writers
The predefined reader/writer classes supplied with JViews Maps are defined in subpackages of the ilog.views.maps.format package.
The pivot format reader and writer
The class diagram for the pivot format reader and writer is shown in Pivot Format Reader and Writer UML Diagram.
Pivot Format Reader and Writer UML Diagram
Saved files
Saving a map can produce two files:
*A mandatory .ivl file, containing all information about the map and all map objects (unless only the theme is saved, see Saving and reloading a map).
*An .img file, containing the map raster data in a proprietary format for fast access when reloading. This file is not produced if the map does not contain an image.
The .ivl file
The .ivl format is the standard Rogue Wave® JViews file format used to save an IlvManager object, see Saving and reading in The Essential JViews Framework. The file basically contains:
*The IlvManagerLayers of the manager, which themselves contain all of the graphic objects.
*All additional IlvNamedProperty objects attached to the IlvManagerLayers.
For example, in JViews Maps 8.1, the entire map model, and all related information, is stored in the IlvManager as named properties, see Map-specific manager properties, and saved in the .ivl file.
The .img File
To deliver the map reload performance currently achieved by JViews Maps, raster data for image objects is not saved in the .ivl file because this would slow down the .ivl file read time. Instead, all raster data is saved in a separate .img file. When reloading the map, this file can be mapped directly in memory (if allowed by the operating system) for fast access and virtually no parsing time.
Note that if the map does not contain an image, no .img file is generated with the .ivl file.
Finally, the .ivl and .img file extensions are defined by the Map Builder, but you are free to use the API to give any filename you want to the map you are saving. It is up to you to be consistent between the saving and loading processes.
Saving and reloading a map
In JViews Maps 8.1, maps can be saved in the proprietary .ivl file format. This is basically the regular Rogue Wave® JViews format slightly modified to improve the loading performance of maps containing large amounts of raster data.
To save a map:
1. Create an IlvMapOutputStream object from a filename. This class extends the IlvOutputStream (see Input/output operations in The Essential JViews Framework) and provides the option of not saving the layers (and hence the graphic objects) contained in an IlvManager. You can choose to write the file in binary format, which is more compact, or in ASCII format, which is more readable.
String mapFilename = "myMap.ivl";
boolean binary = false;
IlvMapOutputStream mapOutput = new IlvMapOutputStream(mapFilename, binary);
Note that when using the above IlvMapOutputStream constructor, the name of the image file (see The .img File) is inferred from the specified map filename, by adding the .img extension or by replacing the ivl extension by .img. You can also create the IlvMapOutputStream with a different constructor, specifying a java.io.OutputStream to save the map contents to, and a different filename for the .img file. In this case, you must use the appropriate matching constructor of IlvMapInputStream when loading the map, see the reloading a map procedure below for more information.
2. Optionally:
Save only the map theme. When reloading a theme file only, all IlvMapDataSource instances of the model are started again so that they can read data from their original files and reconstruct the map. This is useful if the original data sources (ESRI Shape, DTED® and so on) are available when reloading the .ivl file (when working on the same machine for example, or on the same network if data formats are stored on a networked resource). The file produced is small, typically only a few tens of KB:
mapOutput.setWritingObjects(false);
Conversely, if you plan on distributing the map without the original data sources, or if you want to achieve higher reload performance, you should consider saving all the data in the file:
mapOutput.setWritingObjects(true);
3. Write the manager to the IlvMapOutputStream and clean up the remaining resources:
try {
  mapOutput.write(manager);
} catch (IOException ex) {
  // handle I/O exception here...…
}
To reload a map:
1. First, it is best is to clear the current manager, see Clearing map data.
2. Create an IlvMapInputStream and use it to read the map file. This takes care of reconnecting read data with the corresponding read map model (data sources, map layers and so on).
String mapFilename = "myMap.ivl";
IlvMapInputStream mapInputStream = new IlvMapInputStream (mapFilename);
try {
   mapInputStream.read(manager);
} catch (Exception ex) {
   // handle reading exceptions here
}
Note that when using the above IlvMapInputStream constructor, the .img file that goes with the .ivl file (passed to IlvMapInputStream ) must be in the same directory as the .ivl file or the stream will not be able to find it, leading to missing images on the map.
If you choose to specify a different name for the .img file when saving the map (see Saving and reloading a map), you must also specify the filename to the IlvMapInputStream using the appropriate constructor as follows:
String ivlFilename = "myMap.ivl";
String imgFilename = "myImgFilename.img";
 
//Create the input stream for the .ivl file.
FileInputStream fis = new FileInputStream(ivlFilename);
 
//Create the IlvMapInputstream and specify the image file name.
IlvMapInputStream mapInputStream = new IlvMapInputStream(fis, imgFilename);
 
//Read the map as described previously.
   try {
     mapInputStream.read(manager);
     } catch (Exception ex) {
// Handle reading exceptions here.
}
Map Export API
The map export API makes it easier for the user to export a part of a map to different output formats.
Class for exporting selected map features
The main class is the IlvMapExportManager. This class is responsible for exporting selected map features of a map through specified export plug-ins known as IlvMapExportManager.IlvMapExporter implementations.
Exporters
IlvMapExportManager.IlvMapExporter is an interface that defines the expected methods of any object capable of writing map features in sequence.
Two kind of exporters can be set on the IlvMapExportManager:
*A vectorial exporter, which handles all vectorial map features when exporting a map.
*A raster exporter, which handles map features containing raster data.
They are set by calling the methods setVectorialExporter and setRasterExporter on an IlvMapExportManager instance.
A region of export can also be set on the IlvMapExportManager so that map features outside this region are not exported.
Once the two exporters of a IlvMapExportManager object are properly set and configured, an array of IlvMapLayer instances of the map may be exported with the method exportMapLayers.
The IlvMapExportDialog class
The IlvMapExportDialog is a user-friendly dialog box class that lets the user choose:
*The exporters to use (from a list of registered exporters)
*A list of map layers to export
*A region of interest for the export
Export Map Dialog Box
Vectorial and raster exporters are registered with this dialog box through the methods registerVectorExporter and registerRasterExporter, and similarly are removed by calling unregisterVectorExporter and unregisterRasterExporter methods.
The shapefile reader and writer
Describes the shapefile reader and writer classes and data sources.
*The shapefile reader and writer classes
*Describes the classes for shapefile reading and writing.
*The shape data source
*Describes the data source for reading shapefiles.
*Classes for reading the shape format
*Describes the classes for reading shapefiles.
*Classes for writing the shape format
*Describes the classes for writing shapefiles.
*Shapefile load-on-demand
*Describes the classes for loading shapefiles on demand.
*The IlvTiledShapeDataSource
*Describes the data source for shapefiles with tiling and load-on-demand.
The shapefile reader and writer classes
The class diagram for the shapefile reader and writer is shown in Shapefile Reader and Writer UML Diagram.
Shapefile Reader and Writer UML Diagram
These classes are based on the Shapefile Specifications listed in the ESRI (Environmental Systems Research Institute) document: ESRI Shapefile Technical Specifications - An ESRI White Paper - July 1998.
The Shapefile format is the exchange format for vector maps of the ESRI. This format supports polygons, arcs, lines, and points. Each Shapefile contains one single theme, meaning that all the objects in the file are of the same type (either line, point, polygon, or another type of object). In the Shapefile format, a theme is essentially described with four different files:
*A shapefile ( .shp ) contains the geometry of the objects.
*A Dbase file ( .dbf ) contains the attributes of the objects.
*An index file ( .shx) contains the index and sizes of the objects of the .shp file.
*A spatial index file ( .idx ) contains tiling information. This file is JViews Maps package specific, and is used to performload-on-demand on Shapefiles.
This format does not contain information concerning the coordinate system used to reference the position of the graphic objects. Objects in Shapefiles are often positioned within a geographic coordinate system ( IlvGeographicCoordinateSystem), but this is far from being the rule.
The Shapefile format comprises the following classes:
*The shape data source
*Classes for reading the shape format
*Classes for writing the shape format
*Shapefile load-on-demand
The complete source code for an ESRI shapefile demonstration can be found at <installdir> /jviews-maps/samples/shape/index.html
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));
Classes for reading the shape format
The ilog.views.maps.format.shapefile package includes the following classes:
*IlvShapeFileReader
This class implements the IlvMapFeatureIterator interface and allows you to read .shp, .dbf and .shx files. Since Shapefiles provide no information on the projection system used, this reader is not georeferenced. This reader uses the two specialized readers described below. Its getNextFeature getNext method merges the information generated by these specialized readers into a single map feature.
*IlvSHPReader
This class implements the IlvMapFeatureIterator interface. This reader only reads .shp files.
*IlvDBFReader: reads .dbf files.
*IlvShapeFileIndex: reads .shx files.
*IlvShapeSpatialIndex: reads maps spatial index .idx files.
The IlvSHPReader class
The geometries stored in Shapefiles are not necessarily 2-D objects. Each point that makes up a shape object can be associated with measurements, or with measurements and an elevation.
Measurements are stored in an attribute of type IlvAttributeArray, which itself is stored in the map feature attribute of index 0.
The following are the shape types that are associated with measurements:
*POINTZ
*POLYLINEZ
*POLYGONZ
*MULTIPOINTZ
*POINTM
*POLYLINEM
*POLYGONM
*MULTIPOINTM
Elevations are stored in an attribute of type IlvAttributeArray, which itself is stored in the map feature attribute of index 1.
The following are the shape types that are associated with measurements and elevations:
*POINTZ
*POLYLINEZ
*POLYGONZ
*MULTIPOINTZ
Since the JViews Maps package does not have a predefined geometry to represent shape objects of type MULTIPATCH, which are essentially used for 3-D rendering, these are ignored. It is possible, however, to modify this behavior by subtyping the class IlvShapeSHPReader. Since shape objects are read in protected methods, modifying the reader to include new geometries requires minimal effort.
The IlvDBFReader class
This reader is used exclusively for reading a file of the .dbf format. It can be used to iterate over a file as follows:
 try {
       IlvDBFReader reader = new IlvDBFReader("myFile.dbf");
       IlvFeatureAttributeProperty attributes = reader.getNextRecord();
       while (attributes != null) {
         // Process attributes.
         ...
        attributes = reader.getNextRecord();
       }
    } catch (Exception e) {
       e.printStackTrace();
    }
If the reader has been created from a file and not from a URL, you can access map feature attributes directly by specifying their record number:
reader.readRecord(index);
The IlvShapeFileReader class
This reader reads the .shp file storing geometries and the .dbf file storing attributes simultaneously, and merges the information into a single IlvMapFeature object.
It can be instantiated in one of three ways:
*By specifying the name of the .dbf and .shp files.
*By specifying the URL of these two files.
*By specifying an IlvDBFReader and IlvSHPReader object directly.
This is useful, for example, when using a derived IlvSHPReader object.
Classes for writing the shape format
The ilog.views.maps.format.shapefile package contains the following classes for writing Shapefiles.
The class IlvSHPWriter is used to generate the geometry and index parts of a Shapefile ( .shp and .shx files), while the IlvDBFWriter is used to write the attribute file ( .dbf extension).
Like with feature iterator, writing map features to a Shapefile consists of writing repeatedly map features using the methods writeFeature and writeAttributes, then call the close method of writers to flush the data and write the headers.
The IlvSHPWriter class
The IlvSHPWriter class manages the writing of geometries to a Shapefile, with the creation of the Shapefile index that allows direct access to Shapefile records.
The following example shows how to use this class to write the contents of a feature iterator to a file foo.shp, creating the index file at the same time.
try {
   IlvSHPWriter shpwriter = new IlvSHPWriter("foo.shp",
                                            "foo.shx");
  // Loop on features.
  IlvMapFeature feature = iterator.getNextFeature();
  while (feature != null) {
    shpwriter.writeFeature(feature);
    feature = iterator.getNextFeature();
  }
  shpwriter.close();
} catch (IOException e) {
  // Error processing.
  e.printStackTrace();
}
NOTE The Shapefile format defines a header that can be completed only once all data is written. For this reason, it is mandatory to call the close() method of the shape writer once all data is written, so that the header is updated.
The IlvDBFWriter and IlvDBFAttributeInfo classes
The IlvDBFWriter and IlvDBFAttributeInfo classes manage the writing of DBase III+ files ( .dbf files). These files contain records corresponding to attributes of geometries contained within a Shapefile.
As .dbf files need records with fixed-size fields, it is important to choose a field size that is large enough to contain all data of a field, as well as a size small enough not to waste data.
The goal of the class IlvDBFAttributeInfo is to complement IlvAttributeInfoProperty for the definition of record fields.
The following example shows how to write the contents of an iterator to a set of .shp, .shx and .dbf files:
try {
  // Create the SHP writer.
  IlvSHPWriter shpwriter = new IlvSHPWriter("foo.shp", "foo.shx");
 
  // Read the first feature.
  IlvMapFeature feature = iterator.getNextFeature();
 
  // Create the DBF Writer.
  IlvDBFAttributeInfo info =
      new IlvDBFAttributeInfo(feature.getAttributeInfo());
 
  IlvDBFWriter dbfwriter = new IlvDBFWriter(info,
                                            "foo.dbf");
 
  // Loop on features.
  while (feature != null) {
    shpwriter.writeFeature(feature);
    dbfwriter.writeAttributes(feature.getAttributes());
    feature = iterator.getNextFeature();
  }
  shpwriter.close();
  dbfwriter.close();
} catch (IOException e) {
  // Error processing.
  e.printStackTrace();
}
Once again, the writers must be closed to write the headers correctly.
Shapefile load-on-demand
The Maps package provides classes to perform load-on-demand on Shapefiles. This is achieved by the use of specific spatial index files. These files, usually having an .idx extension, store relations between tiles and object identifiers that belong to these tiles. A class and a tool example are provided to generate these spatial index files. A generic tile loader is also provided to minimize the amount of code needed to implement the load-on-demand mechanism using Shapefiles.
The load-on-demand mechanism involves two classes in addition to the shape reader and the dbf reader: the IlvShapeFileIndex class and the IlvShapeSpatialIndex class. A utility class is also provided to generate the spatial index for a given Shapefile: the IlvShapeFileTiler class.
The mechanism used to store and retrieve objects by tiles is illustrated in the following diagram:
The Spatial Index file holds objects identifiers for each tile. Objects identifiers are their ordinal place in the IndexFile. Geometries are retrieved in the Shapefile using the IndexFile. In the following example, the tile [2, 1] (tiles indices begin at 0) contains identifiers 2, 5 and 9 referring to the geometries g2 g5 and g9.
The classes used to perform load-on-demand on the Shapefiles are:
*The IlvShapeFileIndex Class
*The IlvShapeSpatialIndex Class
*The IlvShapeFileTiler Class
*The IlvShapeFileTileLoader Class
The IlvShapeFileIndex Class
This class allows you to directly access geometries in a Shapefile. The spatial index and the Shapefile must correspond to the same theme:
// Open the index file.
IlvShapeFileIndex index = new IlvShapeFileIndex("example.shx");
// Open the corresponding Shapefile.
IlvSHPReader shape = new IlvSHPReader("example.shp");
// Retrieve the feature for each index.
int count = index.getRecordCount();
for(int i = 0; i < count; i++)
    IlvMapFeature f = shape.getFeatureAt(i);
The IlvShapeSpatialIndex Class
This class stores tile information: tile size and count, and identifiers of the objects belonging to each tile. To retrieve objects from a tile specified by its row and column, use the getIdArray method:
// Open the spatial index file.
IlvShapeSpatialIndex spatialIndex =
    new IlvShapeSpatialIndex("example.shx");
// Loop on all columns and rows.
for(int c = 0; c < spatialindex.getColumnCount(); c++) {
    for(int r = 0; r < spatialindex.getRowCount(); r++) {
        // Retrieve the IDs of objects belonging to the tile at row ‘r’ and
        // column ‘c’.
        int[] ids = spatialindex.getIdArray(c, r);
        // Loop on these IDs and get the corresponding map feature.
        for(int i =0; i < ids.length; i++) {
            IlvMapFeature f = shape.getFeatureAt(i);
        }
    }
}
The IlvShapeFileTiler Class
This class is used to generate tiling information from a given Shapefile. To use this class you have to provide the Shapefile to tile, the SpatialIndexFile to write to, and either the tile size or the number of rows and columns.
IlvShapeFileTiler.CreateShapeSpatialIndex("example.shp",
                                          "example.idx",
                                                     5., 10.);
The above code extract produces a SpatialIndexFile named example.idx with a tile size of width 5 and height 10.
IlvShapeFileTiler.CreateShapeSpatialIndex("example.shp",
                                          "example.idx",
                                          20, 30);
The above code extract produces a SpatialIndexFile of 600 tiles, 20 columns and 30 rows.
The IlvTiledShapeDataSource
The IlvTiledShapeDataSource is the tiled version of the IlvShapeDataSource. This means that it takes advantage of the tiling and load-on-demand mechanism. To read a tiled shapefile with such a data source, you can use the following code:
IlvTiledShapeDataSource source = new IlvTiledShapeDataSource(fileName);
source.setManager(getManager());
try {
  source.start();
} catch (Exception e) {
  e.printStackTrace();
}
The IlvShapeFileTileLoader Class
This class implements load-on-demand for tiled Shapefiles. When associated with an IlvTiledLayer, this class automatically handles tile loading if the Shapefile file name, the IndexFile file name, and the SpatialIndexFile file name are provided. An optional Dbase file name can also be provided to load object attributes.
IlvShapeFileTileLoader tileLoader =
    new IlvShapeFileTileLoader("example.shp",
                               "example.dbf", // Or null if attributes loading
                                             // is not wanted.
                               "example.shx",
                               "example.idx");
IlvTiledLayer tiledLayer = new IlvTiledLayer(new IlvRect(), null,
   IlvTileController.FREE);
tiledLayer.setTileLoader(tileLoader);
The MID/MIF reader and writer
Describes the MID/MIF reading and rendering classes and data sources.
*The MID/MIF classes
*Describes the classes for reading MID/MIF files.
*The MIDMIF data source
*Describes the data source for MIDMIF files.
*Classes for reading the MapInfo Interchange File format
*Describes the classes provided for reading MIF format files.
*Classes for rendering the MapInfo Interchange File format
*Describes the classes provided for rendering MIF format files.
The MID/MIF classes
The class diagram for the mid/mif reader is shown in MID/MIF Reader UML Diagram.
MID/MIF Reader UML Diagram
This section describes the ilog.views.maps.format.midmif package, which allows you to read files provided in the MapInfo Interchange File (MIF) format.
A MapInfo Interchange Format consists of a MIF file containing the geometries and rendering attributes, and a MID file containing the attributes attached to each geometry.
The MIF file is an ASCII text file that describes the geometry data associated with rendering attributes such as pen and brush styles, font, and color that should be used to transform geometries into graphic objects. The reader classes provided with the JViews Maps package allow you to use either the information contained in the MIF file or your own rendering attributes.
The MID file contains attributes, which are nongraphical additional information associated with the geometries contained in the MIF file.
The MID/MIF Reader contains the following classes:
*The MIDMIF data source
*Classes for reading the MapInfo Interchange File format
*Classes for rendering the MapInfo Interchange File format
*Coordinate System Support
The MIDMIF data source
The IlvMIDMIFDataSource class is a specialized data source that reads MIDMIF files. It wraps all MIDMIF file rendering processes.
IlvMIDMIFDataSource source = new IlvMIDMIFDataSource(filename);
source.setManager(manager);
source.start();
The IlvMIFDMIFDataSource produces a IlvMapLayer for objects having the same geometries and similar graphic attributes. If, however, a MIDMIF file contains lines whose color attributes are different, for example, red and blue, two layers are created, one for the blue lines and one for the red lines.
Classes for reading the MapInfo Interchange File format
The JViews Maps package provides all the necessary classes to read data provided in the MapInfo Interchange File (MIF) format. In addition to these classes, the JViews Maps package also provides the IlvGraphic classes needed to render specific MIF objects.
The classes used to read MapInfo Interchange files are:
*The IlvMIDMIFReader class
*The IlvMIFReader class
*The IlvMIDReader class
The IlvMIDMIFReader class
This class reads both MIF file and MID file by providing a MIF file name and a MID file name. If the MID file name is set to null, no attribute is loaded. If the MID file name corresponds to a valid MID file, the attributes are read from the file and attached to the IlvMapFeature returned by the reader.
IlvMIDMIFReader reader = new IlvMIDMIFReader("example.mif", "example.mid");
IlvMapFeature feature = reader.getNextFeature();
while(feature != null)
     feature = reader.getNextFeature();
The IlvMIFReader class
This is the class that reads a single MIF file, providing a MIF file name or a reader to the constructor. You can then iterate to obtain the IlvMapFeatures of the file, but you can also obtain information about the MIF file you are reading, such as:
*The IlvAttributeInfoProperty, which defines the name and the classes of the attributes that can be found in the associated MID file.
*The default feature renderer suitable to render the geometries contained in this file.
*The character encoding used in this file.
*The coordinate system in which the geometries of the file are expressed.
Note that the coordinate system returned by the reader can be null even if the MapInfo specifications consider the geometries to be in the Geographic coordinate system if none is specified in the MIF file.
IlvMIFReader reader =
    new IlvMIFReader("example.mif");
IlvAttributeInfoProperty info = reader.getAttributeInfo();
if(info != null) {
    System.out.println("Attributes info : ");
    for(int i = 0; i < info.getAttributesCount(); i++) {
        System.out.println("Name " + info.getAttributeName(i));
        System.out.println("Class " + info.getAttributeClass(i));
    }
}
IlvCoordinateSystem cs = reader.getCoordinateSystem();
if(cs != null)
    System.out.println("The coordinate system is " + cs.getName());
else
    System.out.println("Assuming a geographic coordinate system");
String encoding = reader.getCharset();
System.out.println("Char set is " + encoding);
The IlvMIDReader class
This class reads a MID file. You must have previously opened the corresponding MIF file, in order to build the second argument of the MID reader ( IlvAttributeInfoProperty) that is provided in the MIF file.
IlvMIFReader reader =
    new IlvMIFReader("example.mif");
IlvAttributeInfoProperty info = reader.getAttributeInfo();
IlvMIDReader mid = new IlvMIDReader("example.mid", info);
IlvFeatureAttributeProperty prop = mid.getNextRecord();
while(prop != null)
    prop = mid.getNextRecord();
Classes for rendering the MapInfo Interchange File format
Since the MIF file can contain rendering information, the JViews Maps package provides classes to use this rendering information directly. This includes a ready-to-use IlvFeatureRenderer suitable to render geometries found in the MIF file and a factory to create IlvMapLineRenderingStyle.
In addition to these rendering classes, the JViews Maps package also provides a set of specific IlvGraphic objects to display the MID/MIF geometries. These IlvGraphic objects are needed by the MID/MIF specifications but can also be used outside a MID/MIF context.
The IlvMIFFeatureRenderer Class
This class is a subclass of the IlvDefaultFeatureRenderer that dispatches on the appropriate renderer with the rendering styles found in the MIF file. This is the IlvFeatureRenderer returned by the getDefaultFeatureRenderer method of the IlvMIFReader class. The rendering styles found in the MIF file are attached to the IlvMapFeature as properties by the reader and interpreted in the renderer.
The IlvMIFPenFactory Class
This class is a factory to create an IlvMapLineRenderingStyle by specifying a MID/MIF pattern identifier.
The IlvMIFCoordinateSystemFactory Class
This class is a factory to translate a MID/MIF coordinate system into a Maps coordinate system.
Specialized Graphics
The IlvGraphic objects needed to render MID/MIF geometries include the following classes:
*IlvDecoratedPath: A general path supporting decorations. A decoration is a drawing that follows the path of the graphic. These decorations can be clipped against the clip region of the java.awt.Graphics to provide high performance drawing.
*IlvMapLabel: A label able to display multiline text. This label supports interline spacing.
*IlvFontMarkerA graphic object able to display a character of a given font as the marker point. This object is usually used with a symbol font that provides cartographic symbology.
Coordinate System Support
Along with objects and attribute information, MIF files also contain information on the coordinate system used to store the graphic objects of a defined file.
The possible coordinate systems in MID/MIF are:
*Earth: a coordinate system where coordinates are expressed within a projected coordinate system. See List of Supported MID/MIF Projections for the list of supported projections.
*NonEarth: a coordinate system where coordinates are expressed in a specified unit. When such a file is encountered, the coordinate system is set to null, and the getUnit method returns the unit defined in the file.
*Layout: a coordinate system corresponding to coordinates on a sheet of paper. When such a file is encountered, the coordinate system is set to null, and the getUnit method returns the unit defined in the file.
*Table: a coordinate system corresponding to an open table in MapInfo. This coordinate system is not supported in the JViews Maps package.
*Window: a coordinate system corresponding to an open window in MapInfo. This coordinate system is not supported in the JViews Maps package.
The JViews Maps package fully supports projected coordinates defined in a MID/MIF file. The supported projections are listed in List of Supported MID/MIF Projections:
List of Supported MID/MIF Projections
MID/MIF Projection Number
Name
Corresponding Projection
9
Albers Equal-Area Conic
IlvAlbersEqualAreaProjection
5
Azimuthal Equidistant
IlvAzimuthalEquidistantProjection
2
Cylindrical Equal Area
IlvCylindricalEqualAreaProjection
14
Eckert IV
IlvEckert4Projection
15
Eckert VI
IlvEckert6Projection
17
Gall
IlvMercatorProjection
7
Hotine Oblique Mercator
IlvObliqueMercatorProjection
4
Lambert Azimuthal Equal Area
IlvLambertAzimuthalEqualAreaProjection
3
Lambert Conformal Conic
IlvLambertConformalConicProjection
19
Lambert Conformal Conic
(modified for Belgium 1972)
IlvLambertConformalConicProjection
1
Longitude/Latitude
Not a projection. An IlvGeographicCoordinateSystem is used.
10
Mercator
IlvMercatorProjection
11
Miller Cylindrical
IlvMillerCylindrical Projection
13
Mollweide
IlvMollweideProjection
27
Polyconic
IlvPolyconicProjection
12
Robinson
IlvRobinsonProjection
16
Sinusoidal
IlvSinusoidalProjection
20
Stereographic
IlvStereographicProjection
8
Transverse Mercator
IlvTransverseMercatorProjection
JViews Maps supports all ellipsoids and nearly all datums from MapInfo (see the MID/MIF file format specification for the full list of ellipsoids and datums).
NOTE The MIF format specification allows user datum definition, with either 3 or 7 parameters. As the JViews Maps package does not support 7-parameter datum yet, definitions of 7- parameter datum is decoded as 3-parameter datum, skipping the rotations and scale part of datum definitions.
The DTED file reader
You can use the DTED® file reader to read Digital Terrain Elevation Data (DTED format) files. The DTED read format is a map format for representing terrain elevations published by the U.S. National Imagery and Mapping Agency (NIMA). The DTED files contain digital terrain models as rasters. A raster is a georeferenced grid containing a value in each of its cells. In the case of DTED, and a digital terrain model in general, the value indicates the average elevation in the cell. However, this value can indicate any other attribute: surface temperature, surface pressure, nitrogen rating of the soil, and so on.
The DTED reader provided in this package is based on the specification document MIL-PRF-89020A of 19 April 1996. DTED files are available with various precision levels, called DTED0, DTED1, and DTED2. A DTED file contains a digital terrain model raster that covers a zone of one degree by one degree. The cell size of the raster depends on the DTED level:
*DTED0 provides raw data (approximately 30 to 40 KB for a file).
*DTED1 provides data that is more detailed.
*DTED2 is the most precise level. It has surface cells that are nine times smaller than those of DTED1. At this degree of precision, a DTED file is enormous (several megabytes).
The complete source code for a DTED demonstration can be found at
<installdir> /jviews-maps/samples/dted/index.html.
The DTED raster reader
The following code shows how to use an IlvRasterDTEDReader to load a single DTED file using the IlvMapDataSource:
IlvRasterDTEDReader r = new IlvRasterDTEDReader();
try {
  r.addMap(filename);
} catch (IOException e1) {
  e1.printStackTrace();
}
IlvMapDataSource source =
IlvRasterDataSourceFactory.buildImageDataSource(manager, r, null);
try {
  source.start();
} catch (Exception e) {
  e.printStackTrace();
}
The following code shows how to read a set of DTED files using an IlvTiledRasterDataSource. This produces an IlvMapLayer containing an IlvTiledLayer holding the tiles.
IlvRasterDTEDReader r = new IlvRasterDTEDReader();
try {
  r.addMap(filename);
} catch (IOException e) {
  e.printStackTrace();
}
IlvMapDataSource source =
IlvRasterDataSourceFactory.buildTiledImageDataSource(manager, r, true, true, null);
try {
  source.start();
} catch (Exception e) {
  e.printStackTrace();
}
Classes for reading the DTED format
The main class for reading DTED formats is IlvDTEDReader. This class implements the IlvMapFeatureIterator interface and returns only one IlvMapFeature object, which is the raster corresponding to the digital terrain model (DTM) stored in the file. The geometry of this map feature is of type IlvMapRaster. The map feature has no attribute. The projection of the reader is the source projection of the DTED data, that is, the geographic projection.
The IlvDTEDLayer class defines load-on-demand for the DTED format. Load-on-demand is implemented on a DTED-level basis from the corresponding file name or URL. In other words, the size of a tile in a JViews Maps tiled layer corresponds to the size of a DTED tile. This specific implementation of load-on-demand works exclusively with maps drawn with the geographic projection. Specifying a URL allows you to access one of the NIMA CDs directly from their website. For an example, see the DTED demonstration at the following location:
<installdir> /jviews-maps/samples/dted/index.html.
The image file reader
The formats handled by the generic image file reader, which are GIF, PNG and JPEG, are supported by the Java™ Platform, Standard Edition. An image coded in one of these formats does not contain any geo-referencing information, so this information has to be known before loading this kind of image. This is also true for TIFF images that do not contain GeoTIFF tags. Below you can find a description of the IlvRasterBasicImageReader, the IlvImageReader class and IlvImageTileLoader class.
The IlvRasterBasicImageReader class
The IlvRasterBasicImageReader class is a GIF, JPG, PNG or TIFF reader that creates reprojectable, stylable, and pixel-on-demand images.
Creating an image reader
You need first to create an image reader, and add the image file to be read:
IlvRasterBasicImageReader imageReader = new IlvRasterBasicImageReader();
imageReader.addMap(gifFile);
As these images have no longitude or latitude information, you need to geo-reference this image. The easiest way to do this is to set the image bounds in longitude and latitude. This obviously works only for images that have a spatial coverage along lines of longitude and latitude. For advanced management of more complex images, the Map Builder provides an image transformation model that manages reprojection and image interpolation ( ImageControlModel class).
In the example below, you set the image to cover the entire earth:
imageReader.setImageBounds(0,-Math.PI,Math.PI/2,Math.PI,-Math.PI/2);
Creating a data source
Once you have created the reader, you need to create a data source, which should be integrated into the manager properties:
IlvMapDataSource imageDataSource =
IlvRasterDataSourceFactory.buildTiledImageDataSource(manager,imageReader,true,t
rue,null);
IlvMapDataSourceModel dataSourceModel =
IlvMapDataSourceProperty.GetMapDataSourceModel(manager);
dataSourceModel.insert(imageDataSource);
Reading the data
You can then start reading your data:
dataSourceModel.start();
Starting the data source creates the necessary tiled layers, tile managers and IlvRasterIcon instances to manage the pixel-on-demand feature and the progressive display of the new geo-referenced image.
You can also create a subsampled preview of an image, using code such as:
int iconWidth=imageReader.getRasterProperties(0).getNumColumns();
int iconHeight=imageReader.getRasterProperties(0).getNumLines();
Image image =
Toolkit.getDefaultToolkit().createImage(iReader.getTileLoader(0).getScaledImage
Producer(subsampling, new IlvRect(0, 0, iconWidth, iconHeight)));
The IlvImageReader class
If you do not need image the reprojection, styling or pixel-on-demand features, but simply want to insert and geo-reference a single GIF, JPG or PNG image, you can use the IlvImageReader class.
NOTE If you use this class, the images created are not compatible with the data source and map layer management.
This class implements the IlvMapFeatureIterator interface. It returns only one IlvMapFeature object, which is the image stored in the file.
The geometry of this map feature is of type IlvMapImage. The map feature has no attributes. To use this reader you have to provide a file name and the coordinates of this image.
// The image is known to be at 77 degrees 30 seconds east
// and 10 degrees north for the upper left corner.
// Lower right corner is at 82 degrees 30 seconds east
// and 5 degrees north.
IlvCoordinate ul = new IlvCoordinate(77.5, 10);
IlvCoordinate lr = new IlvCoordinate(82.5, 5);
IlvImageReader reader = new IlvImageReader("image.jpg", ul, lr);
IlvMapFeature feature = reader.getNextFeature();
IlvFeatureRenderer renderer = reader.getDefaultFeatureRenderer();
// Image is known to be in the geographic coordinate system.
IlvCoordinateTransformation tr
        = new IlvCoordinateTransformation(IlvGeographicCoordinateSystem.WGS84,
                                         IlvGeographicCoordinateSystem.WGS84,
                                         new IlvMapAffineTransform());
IlvGraphic g = renderer.makeGraphic(feature, tr);
manager.addObject(g, false);
The IlvImageTileLoader class
If you do not need image reprojection, styling or pixel-on-demand features, but have access to a set of images, you can use the IlvImageTileLoader class.
NOTE If you use this class, the images created are not compatible with the data source and map layer management. This information is provided for compatibility with older versions of JViews.
This class is used to read a set of images that are part of a larger image. This tile loader allows an application to load only the images that are visible at a given time, each image corresponding to a tile. Each file must be named so that it is possible to construct its file name knowing the row index and column index of the corresponding tile. To use this tile loader, you must provide the information needed to reconstruct the file name for a given tile: a pattern that matches the file naming scheme and two formatting strings.
IlvImageTileLoader loader = new IlvImageTileLoader(String pattern,
                                                   String rowFormatString,
                                                   String colFormatString);
The pattern argument must contain one ‘%r’ and one ‘%c’ conversion specifier. The %r conversion specifier is used to convert the row index of the tile, and the %c conversion specifier is used to convert the column index of the tile. These conversion parameters are replaced accordingly with the rowFormatString and the colFormatString parameters. This format string is used to construct two java.text.DecimalFormat strings.
The IBM spatial database readers
Describes the IBM spatial databases (DB2 and Informix) reader classes, how to use them through data sources, and how to use tiling and multithreading.
*The IBM spatial database reader classes
*Describes the IBM spatial databases reader classes, how to use them through data sources, and how to use tiling and multithreading.
*Using the DB2 spatial data source
*Explains how to read a map stored in a DB2 spatial database
*Using the Informix spatial data source
*Explains how to read a map stored in an Informix spatial database.
*Getting a list of layers
*Explains what is needed to obtain a list of layers in an IBM spatial database.
The IBM spatial database reader classes
The class diagram for the IBM® spatial database reader is shown in the following IBM spatial database readers UML diagram.
The IBM database spatial readers allow you to retrieve information from IBM® DB2® Spatial Extender and IBM® Informix® Spatial DataBlade™ georeferenced databases, and the use of such map data in a Rogue Wave® JViews application.
*The package ilog.views.maps.datasource.ibm contains the common classes to both databases. Most of those are abstract and have a different implementation for DB2 and Informix.
*The package ilog.views.maps.datasource.ibm.db2 contains the classes that implement the specific SQL queries and reflect the internal structure of the relational database.
*The package ilog.views.maps.datasource.ibm.informix contains the classes that implement the specific SQL queries and reflect the internal structure of the relational database.
Using the DB2 spatial data source
The IlvDB2DataSource class is an IlvMapDataSource for reading georeferenced objects from a DB2® spatial database. It wraps up all operations (connecting to database, reading features, rendering them to graphic objects) in a convenient way.
To read a map stored in an DB2 spatial database:
1. Create a connection to the DB2 Spatial database:
IlvDB2ConnectionInfo theDB2Connection=new IlvDB2ConnectionInfo();
theDB2Connection.setHostName("server_hostname");
theDB2Connection.setHostPort("50001");
theDB2Connection.setUser("a_db2_user");
theDB2Connection.setPassword("password");
theDB2Connection.setDatabaseName("database_name")
2. Create a data source with this connection as a parameter:
// we want to fetch layer "A_DB2_USER.FLOODZONES.LOCATION.SRID=100002"
String layerName="A_DB2_USER.FLOODZONES.LOCATION.SRID=100002";
IlvDB2DataSource dataSource=new IlvDB2DataSource(DB2Connection, layerName);
To obtain a list of layers, see Getting a list of layers
3. Set parameters on this data source to use load-on-demand, if needed:
boolean useTiling = true;
int rowCount = 5;
int columnCount = 5;
dataSource.setTilingParameters(useTiling, rowCount, columnCount);
4. Connect this data source to the manager of the view:
dataSource.setManager(getView().getManager());
5. Insert the data source map layer into the layer tree (You first need to retrieve the layer model from the property of the manager):
IlvMapLayerTreeModel mltm = IlvMapLayerTreeProperty.GetMapLayerTreeModel(v.getManager());
mltm.addChild(null, dataSource.getInsertionLayer());
6. Insert the data source into the data source tree. You first need to retrieve the data source model from the property of the manager:
IlvMapDataSourceModel dataSourceModel =
IlvMapDataSourceProperty.GetMapDataSourceModel(manager);
dataSourceModel.insert(dataSource);
7. Finally, start the data source (or the whole model, if you have more than one data source):
dataSource.start();
Using the Informix spatial data source
The IlvInformixDataSource class is an IlvMapDataSource for reading georeferenced objects from an Informix® spatial datablade. It wraps up all operations (connecting to database, reading features, rendering them to graphic objects) in a convenient way.
To read a map stored in an Informix spatial datablade:
1. Create a connection to the Informix Spatial datablade:
IlvInformixConnectionInfo cx = new IlvInformixConnectionInfo();
cx.setHostName("server_hostname");
cx.setHostPort("9088");
cx.setUser("an_informix_user");
cx.setServer("informix_server_name");
cx.setPassword("password");
cx.setDatabaseName("database_name");
2. Create a data source with this connection as a parameter:
// we want to fetch layer "AN_INFORMIX_USER.WORLD.GEOM.SRID=0"
String layerName="AN_INFORMIX_USER.WORLD.GEOM.SRID=0";
IlvInformixDataSource dataSource=new IlvInformixDataSource(cx, layerName);
To obtain a list of layers, see Getting a list of layers
3. Set parameters on this data source to use load-on-demand, if needed:
boolean useTiling = true;
int rowCount = 5;
int columnCount = 5;
dataSource.setTilingParameters(useTiling, rowCount, columnCount);
4. Connect this data source to the manager of the view:
dataSource.setManager(getView().getManager());
5. Insert the data source map layer into the layer tree: You first need to retrieve the layer model from the property of the manager:
IlvMapLayerTreeModel mltm = IlvMapLayerTreeProperty.GetMapLayerTreeModel(v.getManager());
mltm.addChild(null, dataSource.getInsertionLayer());
6. Insert the data source into the data source tree. You first need to retrieve the data source model from the property of the manager:
IlvMapDataSourceModel dataSourceModel =
IlvMapDataSourceProperty.GetMapDataSourceModel(manager);
dataSourceModel.insert(dataSource);
7. Finally, start the data source (or the whole model, if you have more than one data source):
IlvDBConnectionInfo cx=…;
String[] layersList = cx.getSpatiallyEnabledTableNames();
Getting a list of layers
To get a list of layers available in an IBM®spatial database, you need first to set up your connection, and then:
IlvDBConnectionInfo cx=…;
String[] layersList = cx.getSpatiallyEnabledTableNames();
The Oracle spatial reader and writer
Describes the Oracle® reader and writer classes, using data sources, how to use tiling, multithreading and exporting to an SDO database.
*The Oracle spatial reader and writer classes
*Describes the Oracle® spatial reader and writer classes.
*Using the Oracle SDO data source
*Explains how to use the Oracle® SDO data source to read a map.
*Using tiling and multithreading
*Explains how to use tiling and multithreading.
*Getting a list of layers
*Describes how to get a list of layers.
*Relational model classes
*Describes the classes for reading and writing data stored in an Oracle® spatial relational model database.
*Object relational model classes
*Describes the classes for reading and writing data stored in an Oracle® spatial object relational database.
*Oracle SDO export
*Describes how to use the Map Export API to export part of a map to an SDO database.
The Oracle spatial reader and writer classes
The class diagram for the Oracle® spatial reader and writer is shown in Oracle Spatial Reader and Writer UML Diagram.
Oracle Spatial Reader and Writer UML Diagram
Oracle SDO, or Oracle Spatial, is the spatial extension of Oracle in its version 7.3. This extension has been renamed to Spatial Cartridge in the version 8.0 and has been renamed again to Oracle Spatial in the version 8i.
The classes are based on the relational implementation of Oracle Spatial available since Oracle 7.3. It contains classes that facilitate the use of map data (stored in an Oracle database) in a Rogue Wave® JViews application. Oracle Spatial allows you to store georeferenced objects in an Oracle database and to perform spatial queries, such as getting the list of objects that intersect a specific polygon.
Oracle has written two implementations of Oracle Spatial:
*An implementation based on relational tables, available since Oracle 7.3.
*An implementation based on the Object Relational model, available since Oracle 8i, which also contains the relational implementation of Oracle Spatial.
The Oracle reader of JViews Maps supports reading and writing data in the relational and the object relational model of Oracle Spatial through two different packages:
*The package ilog.views.maps.format.oracle contains classes to read and write Oracle Spatial Relational model.
*The package ilog.views.maps.format.oracle.objectmodel contains classes to read and write Oracle Spatial Object Relational model.
The Oracle Spatial Reader and Writer comprises the following classes:
*Using the Oracle SDO data source
*Relational model classes
*Object relational model classes
*Oracle SDO export
The complete source code for an Oracle Reader demonstration can be found at <installdir> /jviews-maps/samples/oracle/index.html.
Using the Oracle SDO data source
The IlvSDODataSource class is an IlvMapDataSource for reading georeferenced objects from an Oracle® SDO (formerly Oracle Spatial) database. It relies on the Oracle SDO API that was introduced in former versions of the JViews Maps product, but wraps up all operations (connecting to database, reading features, rendering them to graphic objects) in a more convenient way.
To read a map stored in an Oracle SDO database:
1. Create a connection to the Oracle database:
String url = "jdbc:oracle:thin:@hostMachine:1529:mySID";
String userName="login";
String password="pass";
IlvSDOConnection connection = new IlvSDOConnection(url,userName,password);
connection.createConnection();
2. Create a data source with this connection as a parameter:
// Assume we want to read from an object model Oracle database (not
relational)
boolean isObjectModel = true;
 
// we want to fetch layer "MY_LAYER_GEOMETRY"
IlvSDODataSource SDODataSource =
new IlvSDODataSource(connection, isObjectModel, "MY_LAYER_GEOMETRY");
To get a list of layers, see Getting a list of layers.
3. Set parameters on this data source to use load-on-demand:
boolean useTiling = true;
int rowCount = 5;
int columnCount = 5;
SDODataSource.setTilingParameters(useTiling, rowCount, columnCount);
4. Connect this data source to the manager of the view:
SDODataSource.setManager(getView().getManager());
5. Insert the data source into the data source tree. You first need to retrieve the data source model from the property of the manager:
IlvMapDataSourceModel dataSourceModel =
IlvMapDataSourceProperty.GetMapDataSourceModel(manager);
dataSourceModel.insert(SDODataSource);
6. Finally, start the Oracle SDO data source:
SDODataSource.start();
Using tiling and multithreading
To benefit from Rogue Wave® JViews Maps advanced image tiling capabilities and multithreading, use IlvTiledRasterDataSource in the place of IlvSDODataSource
NOTE This assumes that you want to load an SDO layer containing raster objects, SDO_GEORASTER.
To use a tiled data source:
1. Instantiate a IlvRasterSDOReaderIlvRasterSDOReader object.
This class extends IlvRasterAbstractReaderIlvRasterAbstractReader and holds a list of raster elements. It fetches the following elements from the Oracle® DB
IlvSDOConnection SDOConnection; // the connection to your Oracle DB
String layerName; // the name of the oracle layer containing SDO_GEORASTER
... // Initialize your connection.
IlvRasterSDOReader sdoReader = new
IlvRasterSDOReader(SDOConnection,layerName);
2. Create an IlvTiledRasterDataSourceIlvTiledRasterDataSource backed by the reader.
IlvTiledRasterDataSource tiledSource =
IlvRasterDataSourceFactory.buildTiledImageDataSource(
view.getManager(), sdoReader, true,true, null);
3. Configure the raster data source, and call the start() method to start data production.
tiledSource.setManager(view.getManager());
tiledSource.start();
Getting a list of layers
To get a list of layers available in the Oracle® database, you can do as follows:
*For a relational model:
*For an object model:
String[] layersList =
IlvSDOUtil.GetAllLayers(connection.getConnection(),connection.getUser());
layersList = IlvObjectSDOUtil.GetAllLayers(connection.getConnection(),
connection.getUser(), true);
Relational model classes
Classes for reading data from an Oracle spatial relational model database
The reader classes for Oracle® SDO relational model (package ilog.views.maps.format.oracle) are:
*IlvSDOFeatureIterator for converting Oracle Spatial layer data into IlvMapFeature objects.
*IlvSDOLayer for implementing load-on-demand for Oracle Spatial data.
*IlvSDOTileLoader abstract class for defining Oracle queries for the IlvSDOLayer. An optimized subclass, IlvDefaultSDOTileLoader is used by IlvSDOLayer.
The IlvSDOFeatureIterator class
The IlvSDOFeatureIterator class reads data from the result of an SQL query to a relational Oracle Spatial layer and converts them into IlvMapFeature objects. JViews Maps applications can handle Oracle Spatial data using this class in a transparent manner.
The following example of Java™ code performs a query, loading data from an Oracle Spatial layer named ROADS_SDOGEOM. It includes classes from the java.sql package:
String query = "SELECT * FROM ROADS_SDOGEOM ORDER BY 1, 2, 4 ";
Statement statement = getConnection().createStatement();
ResultSet resultSet = statement.executeQuery(query);
IlvSDOFeatureIterator iterator = new IlvSDOFeatureIterator(resultSet);
The connection variable is a java.sql.Connection object.
The query orders the result using the following three criteria, which must be given in the order indicated:
1. GID (Geometric ID)
2. ESEQ (Element Sequence)
3. SEQ (Row Sequence)
NOTE This ordering is necessary for the IlvSDOFeatureIterator to work correctly.
The ResultSet of any query to an Oracle Spatial layer can be used to initialize an IlvSDOFeatureIterator, but all the SDO columns must be in the resultSet (columns defining the GID, ESEQ, ETYPE, SEQ, and the coordinates).
The features returned by this iterator have no attributes. However, the GID of the Oracle Spatial geometry is used as the identifier of each feature and this identifier can be used to retrieve additional attributes from the database. See the method getId.
The IlvSDOLayer class
This class implements load-on-demand for a relational Oracle Spatial data source. The default implementation takes an Oracle Spatial layer for which a spatial indexation has been performed and reads its content with a tiling equivalent to the Oracle Spatial tiling.
The following example creates an IlvSDOLayer on an Oracle Spatial layer named ROADS :
IlvSDOConnection connection = new IlvSDOConnection(url, userName, password);
IlvSDOLayer layer = new IlvSDOLayer(connection, "ROADS");
manager.addLayer(layer,-1);
The IlvSDOTileLoader class
This class offers additional possibilities when retrieving data from an Oracle Spatial database. These possibilities are meant as a supplement to the default behavior of IlvSDOLayer. For example, you may want to add filters to a layer or to have a tiling definition that is different than the Oracle tiling.
The example in the file <installdir> /jviews-maps/samples/oracle/index.htmlshows how to implement a subclass IlvSDOTileLoader that uses spatial queries to retrieve data for a JViews Maps tile.
The IlvDefaultSDOTileLoader class
This class is a subclass of IlvSDOTileLoader and is used by the IlvSDOLayer. It has some optimizations. For example, the setTileGroupingCount method allows you to set the number of tiles that are grouped in one unique query to the database. In fact, each tile corresponds to a Spatial Query. If you have an average of n tiles to load each time you want to load on demand, you should use setTileGroupingCount(n), where all the n queries are grouped into one unique query that is sent to the database.
NOTE If you want to handle special operations on each IlvMapFeature retrieved in Load-On-Demand with the IlvSDOLayer layer, you have to subclass the IlvDefaultSDOTileLoader in order to override the getFeatureIterator() method. In this method, you have to return an instance of a subclass of IlvSDOFeatureIterator where you have overridden the getNextFeature() method (inside which you can perform your specific operations on each IlvMapFeature returned by the layer). Finally, you have to set your subclass of IlvDefaultSDOTileLoader as the tile loader of the layer.
Class for writing data to an Oracle spatial relational model database
The IlvSDOWriter class allows you to write map features into a relational Oracle Spatial database.
The IlvSDOWriter class
The IlvSDOWriter class can write any IlvMapFeatureIterator whose features have a geometry supported by the relational model of Oracle Spatial and write them to the database as in the following example:
IlvSDOWriter writer =
   new IlvSDOWriter(connection.getConnection()
                   "MyLayer",
                   16,
                   new IlvCoordinate(-360d, 90d),
                   new IlvCoordinate(360d, -90d));
 // Creating a source feature iterator.
 IlvShapeFileReader reader = new IlvShapeFileReader(...);
 // Dumping its content to the Oracle layer.
 writer.writeFeatureIterator(reader);
The write() method of the IlvSDOWriter does not write the attributes of the features. If you want to write the attributes of the features, you can subtype the writeFeature() method of the IlvSDOWriter, after calling super.writeFeature(feature).
The geometries supported by the Oracle Spatial writer are:
*IlvMapPoint
*IlvMapLineString
*IlvMapPolygon
*IlvMapMultiPoint
*IlvMapMultiCurve for geometries composed of multiple line strings.
*IlvMapMultiArea for geometries composed of multiple polygons.
Object relational model classes
Since version 8.1.7, Oracle® Spatial allows spatial data to be georeferenced. Geometries can be georeferenced by associating a spatial reference ID (SRID) to each geometry. Coordinate systems associated to these SRIDs are defined in the table MDSYS.CS_SRS.
JViews Maps can import these reference systems using their OpenGIS WKT (Well Known Text) specifications, found in the MDSYS.CS_SRS table. If your data is not georeferenced, there is no need to change anything. The JViews Maps classes in the objectmodel package handle both georeferenced and nongeoreferenced data.
For more information, see the Oracle Spatial documentation (Coordinate Systems section) and Handling spatial reference systems.
Classes for reading data from an Oracle Spatial object relational model database
The reader classes for Oracle Spatial object relational model included in the package ilog.views.maps.format.oracle.objectmodel are:
*IlvObjectSDOFeatureIterator for converting Oracle Spatial layer data into IlvMapFeature Objects.
*IlvObjectSDOLayerMetaData and IlvObjectSDODimElement for representing metadata information for a given Spatial Layer.
*IlvObjectSDOKeyExtractor and IlvDefaultObjectSDOKeyExtractor for an optimized use of the load-on-demand.
*IlvObjectSDOLayer for implementing the load-on-demand for object Oracle Spatial data.
*IlvDefaultObjectSDOTileLoader, an optimized subclass of IlvSDOTileLoader is used by IlvObjectSDOLayer.
The IlvObjectSDOFeatureIterator class
This class reads data from the result of an SQL query to a relational Oracle Spatial layer and converts the data into IlvMapFeature objects. The JViews Maps package applications can handle Oracle Spatial data using this class in a transparent way. The following example performs a query, loading data from an Oracle Spatial layer named ROADS:
IlvSDOConnection connection = new IlvSDOConnection(url,
                                                   userName,
                                                   password);
connection.createConnection();
IlvObjectSDOFeatureIterator iterator =
   new IlvObjectSDOFeatureIterator(connection.getConnection(),
                                   "select * from ROADS",
                                    // The name of the geometry column.
                                    "GEOMETRY",
                            // No key ID.
                                    null,
                                    // Name of the x-ordinates column.
                                    "X",
                                    // Name of the y-ordinates column.
                                    "Y");
The result set of any query to an Oracle Spatial layer can be used to initialize an IlvObjectSDOFeatureIterator, but the column containing the geometry must be in the result set.
The features returned by the iterator can have attributes and coordinate systems attached.
*Attributes: they can be retrieved by means of the method getAttributes.
Any column of the layer that can be interpreted as a String, a float number, or an integer number is translated into attributes and set in the returned map feature. Moreover, if you instantiate the feature iterator with an ID name, the value of these features can be used to retrieve additional attributes (if any) from the database. See the getId method.
This ID is used in the library essentially for load-on-demand optimization. If you give an ID name when instantiating the iterator, a large geometry that covers more than one tile is loaded just once.
If you ignore the ID name, the load() method of each covered tile fully loads the large geometry.
*Coordinate Systems: they can be retrieved by means of the getCoordinateSystem method. This coordinate system is the interpretation of the Well Known Text contained in the MDSYS.CS_SRS table corresponding to the SDO_SRID attached to the geometry read by the iterator. The interpretation is performed by the ilog.views.maps.srs.wkt package.
This behavior can be bypassed by using setCoordinateSystem. For example, if you call this method, the coordinate system passed as a parameter is assigned to all the map features returned by the iterator.
The Oracle SRID of the geometry that has been currently read by the iterator can be obtained by the getCurrentSRID.
The IlvObjectSDOLayerMetaData and IlvObjectSDODimElement classes
These two classes correspond to two data structures defined in Oracle Spatial.
The IlvObjectSDOLayerMetaData class corresponds to the data contained in each row of the (XXX_)SDO_GEOM_METADATA view. This view contains information, called metadata, about Spatial layers. Each Spatial user has the following views available in the schema associated with that user (in Oracle 8.1.6+):
*USER_SDO_GEOM_METADATA
Contains metadata information for all spatial tables owned by the user (schema). This is the only view that the user must keep up-to-date. For instance, the close() method of IlvObjectSDOWriter updates this view.
*ALL_SDO_GEOM_METADATA
Contains metadata information for all spatial tables on which the user has SELECT permission.
*DBA_SDO_GEOM_METADATA
Contains metadata information for all spatial tables on which the user has SELECT permission (if the user has the DBA role).
Each metadata view has the following definition:
 TABLE_NAME VARCHAR2(32),
 COLUMN_NAME VARCHAR2(32),
 DIMINFO MDSYS.SDO_DIM_ARRAY,
 SRID NUMBER
In addition, the ALL_SDO_GEOM_METADATA and DBA_SDO_GEOM_METADATA views have an OWNER column identifying the schema that owns the table specified in TABLE_NAME.
You do not need to build metadata by hand: the IlvObjectSDOUtil method can help you retrieve the metadata directly from the database. For instance, if a Spatial layer is called ROADS, then you can retrieve its metadata as follows:
IlvObjectSDOLayerMetaData metadata =
 IlvObjectSDOUtil.GetLayerMetaData(connection.getConnection()
                                   "ROADS",
// You can pass the geometry column name as null: the first
// metadata row that matches the layer name “ROADS” is then
// returned.
                                   null,
// You can pass the metadata view name as null: the default
// is "(USER_)SDO_GEOM_METADATA".
                                   null,
// You can pass the owner name as null: the name of the
// current user is then taken as the owner name.
                                   null);
The IlvObjectSDOLayerMetaData class is then composed of the following elements that match the (XXX_)SDO_GEOM_METADATA view: the table name (the name of the Spatial layer), the geometry column name (called COLUMN_NAME in the view, the name of the column of type MDSYS.SDO_GEOMETRY ), the owner name, the optional SRID if the Spatial layer is georeferenced, and an array of IlvObjectSDODimElement (called DIMINFO in the view).
The IlvObjectSDODimElement corresponds to the MDSYS.SDO_DIM_ELEMENT data type. The MDSYS.SDO_DIM_ELEMENT data type is defined in Oracle as:
Create Type SDO_DIM_ELEMENT as OBJECT (
   SDO_DIMNAME VARCHAR2(64),
   SDO_LB NUMBER,
   SDO_UB NUMBER,
   SDO_TOLERANCE NUMBER);
The DIM element data type describes, for each Spatial Layer, its extent for each dimension. For instance, for typical two-dimensional geometries, the DIM element array of the metadata table has two entries. The first entry describes the first dimension (x, longitude), the second one describes the second dimension (y, latitude).
NOTE In the DIM element array of the metadata table, the elements are supposed to be ordered. For example, the first element of the array is considered as the first dimension of the layer, and so on.
The IlvObjectSDOKeyExtractor and IlvDefaultObjectSDOKeyExtractor classes
The IlvObjectSDOKeyExtractor class is an interface associated with feature iterators and tile loaders. Its main purpose is to associate an object with the map feature read by the iterator or the tile loader.
This object is supposed to be unique, so that the next time the feature iterator meets the object, it is not process the geometry in the corresponding row, considering that this geometry has already been loaded.
The goal is to avoid multiple loading of the same geometry. This interface extracts a key from a ResultSet using the extractKey(java.sql.ResultSet) method. The object returned can be extracted from one Table column or multiple columns as soon as it constitutes a unique object.
Example of Multiple Loading in Load-On-demand
The red rectangle belongs to the tile (2, 2) and (2, 3). When the load method of the tile (2, 2) is called, it loads the rectangle. When the load method of the tile (2, 3) is called, the rectangle is loaded again as soon as it intersects with this tile too, and the tile loader has no way to know that this geometry has already been loaded. You can avoid this by using the IlvObjectSDOKeyExtractor class.
The IlvDefaultObjectSDOKeyExtractor is a default class that implements the key extraction behavior from one Table column. For example, given the previous schema let us suppose that the Spatial Layer is:
GEOMETRY MDSYS.SDO_GEOMETRY,
ID NUMBER
NOTE The ID column does not need to be described in Oracle as a key, when it contains unique values.
The IlvDefaultObjectSDOKeyExtractor used with this layer can be easily obtained in the following way:
IlvDefaultObjectSDOKeyExtractor extractor =
                  new IlvDefaultObjectSDOKeyExtractor("ID");
Then, this extractor can be associated with an IlvObjectSDOLayer, or an IlvDefaultObjectSDOTileLoader.
IlvObjectSDOLayer layer =
   new IlvObjectSDOLayer(connection,
                         IlvObjectSDOUtil.GetLayerMetaData(...),
                         1000,
                         1000,
                         "X",
                         "Y",
                         extractor, // used here
                         null);
The IlvObjectSDOLayer class
This class implements load-on-demand for an object Oracle Spatial data source. The default implementation takes an Oracle Spatial layer for which a spatial indexation has been performed and reads its content.
The following example creates an IlvObjectSDOLayer on an Oracle Spatial layer named ROADS:
IlvSDOConnection connection = new IlvSDOConnection(url,
                                                   userName,
                                                   password);
connection.createConnection();
IlvObjectSDOLayer layer =
     new IlvObjectSDOLayer(connection,
                           // The name of the SDO layer.
                           "ROADS",
                           // Width of a tile in the database
                           // coordinate system.
                           1500,
                           // Height of a tile in the database
                           // coordinate system.
                           1500,
                                  // Special handling of ID.
                           null //Is not required.
                           );
manager.addLayer(layer,-1);
The IlvDefaultObjectSDOTileLoader class
This class is a subclass of IlvSDOTileLoader and is used by the IlvObjectSDOLayer. It has some optimizations.
For example, the method setTileGroupingCount allows you to set the number of tiles that are grouped in one unique query to the database. In fact, each tile corresponds to a Spatial Query, and if you have an average of n tiles to load each time you want to load on demand, you should use setTileGroupingCount(n), where all the n queries are grouped into one unique query that is sent to the database once.
NOTE If you want to handle some special operations on each IlvMapFeature retrieved in load-on-demand with the IlvObjectSDOLayer layer, you have to subclass the IlvDefaultObjectSDOTileLoader in order to override the getFeatureIterator method. In this method, you have to return an instance of a subclass of IlvObjectSDOFeatureIterator where you have overridden the getNextFeature method (inside which you can perform your specific operations on each IlvMapFeature returned by the layer). Finally, you have to set your subclass of IlvDefaultObjectSDOTileLoader as the tile loader of the layer.
Another interesting method of this class is the setRequestParameters method.
This method allows you, for instance, to set the spatial operator used to query the layer. The default operator is SDO_FILTER.
Tiles shows a Spatial layer using a fixed tiling of level 2. The red rectangle is the area queried by the tile loader. If the SDO_FILTER operator is used (default case), all the geometries belonging to the Oracle Spatial Tiles intersecting with the red rectangle fit the request. In the case of Tiles, all the geometries belonging to the tiles (2,2), (2,3), (3,2), and (3,3), for example the line, the point, the triangle, the circle, and the rectangle are retrieved.
You may not want to retrieve the geometries that do not explicitly intersect with the red rectangle (for example, the circle and the rectangle geometries here). In this case, you have two choices.
*The first choice is to keep the SDO_FILTER operator and to use the setClippingRequest method in order to let the tile loader perform a bounding box clipping check.
*The second choice is to use another spatial operator in Oracle which is SDO_RELATE. This operator is to be used with the following parameters: " querytype=window mask=anyinteract ". This way, the setClippingRequest() is not needed anymore so that all the retrieved geometries are the ones that intersect with the red rectangle, for example the point, the triangle, and the line in Tiles.
Finally, note that the SDO_RELATE Spatial operator is slower than the SDO_FILTER operator.
Tiles
Class for writing data to an Oracle Spatial object relational model database
This section presents the IlvObjectSDOWriter class, which allows you to write map features into an Object Oracle Spatial database.
The class IlvObjectSDOWriter can write any IlvMapFeature or any IlvMapFeatureIterator whose features have a geometry supported by Oracle Spatial 8i (vectorial geometries) and write them to the database as in the following example:
IlvSDOConnection connection = new IlvSDOConnection(url,
                                                   userName,
                                                   password);
connection.createConnection();
IlvObjectSDOWriter writer =
    new IlvObjectSDOWriter(connection.getConnection(),
                           "MyLayer", // Layer name.
                           "GEOMETRY", // Geometry column.
                           "X", // X ordinate name.
                           "Y", // Y ordinate name.
                           true // Create table.
);
IlvShapeFileReader reader = new IlvShapeFileReader("foo.shp",null);
int saved_objects_count = writer.writeFeatureIterator(reader,
                                                false, // No attributes
                                                null );// No SRID
writer.close(0.0, // Tolerance
             null );// No SRID
NOTE In the case of the Oracle Spatial Object Model, some auxiliary tables, like the (USER_)SDO_GEOM_METADATA view, need to be updated. It is very important to call the method IlvObjectSDOWriter.close() once the data has been written through the write() method, so that the database is kept up-to-date.
The writeFeature method of the IlvObjectSDOWriter can also write the attributes of the feature.
The method writeFeature has a second argument that can be set to true to save the attributes of the specified map feature. This requires that the map feature has an IlvAttributeInfoProperty correctly set, describing the attributes that match the Oracle Spatial layer column names. This also requires that map feature has an IlvFeatureAttributeProperty IlvFeatureAttributeProperty that fits its IlvAttributeInfoProperty and has correct values.
For instance, if you have an Oracle Spatial layer called ROADS that has the following description in the database:
 
Name
Null?
Type
 
 
 
GEOMETRY
 
MDSYS.SDO_GEOMETRY
TYPE_DESC
 
VARCHAR2(512)
The third argument of the writeFeature() method allows you to set the SDO_SRID value of the written SDO_GEOMETRY. The value of the SDO_SRID is exactly one of the SRID values of the MDSYS.CS_SRS table, and it represents the corresponding coordinate system for the written geometry.
The following code extract shows how to write features with a unique attribute into the database:
IlvSDOConnection connection = new IlvSDOConnection(url,
                                                   userName,
                                                   password);
connection.createConnection();
IlvObjectSDOWriter writer =
   new IlvObjectSDOWriter(connection.getConnection(),
                          "myLayer",
                          "GEOMETRY", "X", "Y", false);
java.lang.String[] names = new String[1];
names[0] = "ATTRIBUTE_NAME";
java.lang.Class[] classes = new Class[1];
classes[0] = java.lang.String.class;
boolean[] nullable = new boolean[1];
nullable[0] = true;
// Creates the attribute info.
IlvAttributeInfoProperty info =
   new IlvAttributeInfoProperty(names, classes, nullable);
 
// Sets the attribute to feature.
IlvFeatureAttribute[] attributes = new IlvFeatureAttribute[1];
attributes[0] = new IlvStringAttribute("MY FOO TYPE");
IlvFeatureAttributeProperty prop =
    new IlvFeatureAttributeProperty(info,attributes);
feature.setAttributeInfo(info);
feature.setAttributes(prop);
 
// Writes the feature.
try {
   writer.writeFeature(feature,true, null); // no SRID
} catch (java.sql.SQLException e) {
   // Error.
   e.printStackTrace();
}
writer.close(0.0, null); // no SRID
The writer can update rows in the SDO layer. This is based on a key mechanism, where the row(s) having the value of the given key are updated. The update is done through the following methods from the IlvObjectSDOWriter class:
*updateFeatureAttributes based on an attribute property where you have to give the position of the key in the attribute list and you can update more than one column at the same time.
*updateFeatureAttribute where you update just one column (the new value is the attributeToUpdate passed as argument) given a key attribute.
NOTE All the subclasses of IlvMapGeometry except IlvMapText, IlvMapImage, and IlvMapRaster are supported by the object model writer.
Oracle SDO export
In addition to the IlvSDOWriter and IlvObjectSDOWriter classes used to store georeferenced objects to an Oracle® database (see The Oracle spatial reader and writer classes), you can export part of a map to a SDO database using the map export API (see Map Export API). To do so, you just need to set an IlvSDOExporter as the vectorial exporter on the IlvMapExportManager.
IlvMapExportManager exportManager = new IlvMapExportManager();
IlvSDOExporter SDOExporter = new IlvSDOExporter();
exportManager.setVectorialExporter(SDOExporter);
 
// configure SDO export (connection parameters)
SDOExporter.showConfigurationDialog(null);
 
// Set the region of the map to export (here we assume that the map is
// in IlvGeographicCoordinateSystem.KERNEL system, i.e. in radians)
exportManager.setExportRegion(-Math.PI,-Math.PI/2, Math.PI,Math.PI/2);
 
 
// Export selected map layers of the map (assuming that mapLayersToExport is
an array of
// IlvMapLayer instances)
exportManager.exportMapLayers(mapLayersToExport);
The GeoTIFF reader
The GeoTIFF reader (see GeoTIFF format) is based on some extension packages such as Batik Apache™ TIFF Reader, an open source API included in the JViews Maps jar files.
The GeoTIFF format is an extension of the TIFF (Tagged Image File Format) format. The TIFF format is an image file format that allows tags to be inserted in the file. These tags give information about the image contained in the file, such as the resolution, the number of samples per pixel, and so on. The GeoTIFF extension adds specific cartographic tags that give geographic information about the image contained in the file, such as the coordinate system in which the image is represented, and the location of the image in this coordinate system.
The official TIFF specification can be found on http://partners.adobe.com/public/developer/tiff/index.html.
More information about the GeoTIFF format can be found at:
http://www.remotesensing.org/geotiff/geotiff.html
The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir> /jviews-maps/samples/mapbuilder/index.html
The IlvRasterGeoTiffReader class
The IlvRasterGeoTiffReader class is a GeoTIFF file reader that creates reprojectable, stylable, and pixel-on-demand images.
Creating an image reader
You need first to create an image reader, and then add the image file to be read:
IlvRasterGeoTiffReader imageReader = new IlvRasterGeoTiffReader();
imageReader.addMap(tiffFile);
The geo-reference information is decoded from the GeoTIFF file, by means of an IlvGeotiffReader.
Creating a data source
Once you have created the reader, you need to create a data source, which should be linked with the manager properties by inserting it into the data source tree:
IlvMapDataSource imageDataSource =
IlvRasterDataSourceFactory.buildTiledImageDataSource(manager,imageReader,true,t
rue,null);
IlvMapDataSourceModel dataSourceModel =
IlvMapDataSourceProperty.GetMapDataSourceModel(manager);
dataSourceModel.insert(imageDataSource);
Reading the data
You can then start reading your data:
dataSourceModel.start();
Starting the data source creates the necessary tiled layers, tile managers, and IlvRasterIcon instances to manage the pixel-on-demand feature and the progressive display of the geo-referenced image.
The IlvGeotiffReader class
The IlvGeotiffReader class implements the IlvMapFeatureIterator interface. The getNextFeature method returns an IlvMapImage geometry which contains a TIFFImage object. The TIFF image can then be rendered by the IlvDefaultImageRenderer to produce an IlvIcon, or be transformed by data sources into a tiled IlvRasterIcon.
The TIFF reader can take two parameters as arguments: the TIFF file name and a file that contains a connection between the tag describing the coordinate system used by the image and the corresponding WKT string. The reader retrieves the coordinate system of the image in a WKT format if the image contains the appropriate tag, and then retrieves the IlvCoordinateSystem through the IlvWKTCoordinateSystemDictionary class. This coordinate system is then available through the getCoordinateSystem method.
The default constructor, however, only takes the TIFF file name parameter and uses an internal WKT file (wktdictionary.txt) found in Rogue Wave® JViews jar files.
The reader can be used in the same way as any reader that conforms to the Maps reader framework:
IlvGeotiffReader reader = new IlvGeotiffReader(tiffFile);
IlvFeatureRenderer renderer = reader.getDefaultFeatureRenderer();
IlvCoordinateSystem coordSys = reader.getCoordinateSystem();
if (coordSys != null)
    manager.setNamedProperty(new IlvCoordinateSystemProperty(coordSys));
else
    manager.removeNamedProperty(IlvCoordinateSystemProperty.NAME);
IlvCoordinateTransformation tr =
    IlvCoordinateTransformation.CreateTransformation(coordSys, coordSys);
IlvGraphic g = renderer.makeGraphic(f, tr);
manager.addObject(g, false);
The TIGER/Line reader
The acronym TIGER® comes from Topologically Integrated Geographic Encoding and Referencing, which is the name for the system and digital database developed at the U.S. Census Bureau to support its mapping needs for the Decennial Census and other Bureau programs.
The TIGER/Line files are a digital database of geographic features, such as roads, railroads, rivers, lakes, legal boundaries, census statistical boundaries, and so on, covering the entire United States. The database contains information about these features, such as, their location in latitude and longitude, the name of the feature, the type of feature, address ranges for most streets, the geographic relationship to other features, and other related information. TIGER/Line® files are a public product created from the TIGER database of the Census Bureau.
The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir> /jviews-maps/samples/mapbuilder/index.html.
The IlvTigerDataSource class
The IlvTigerDataSource class is a data source that reads TIGER/Line files. This data source is filtered so that only selected features can be read from the file, the others being ignored. These features can be supplied in code as an array of strings or can be retrieved from a IlvFeatureSelectorPanel configured with the TigerFeaturesEN.txt file. This file contains the list of the Census Feature Class Codes (CFCCs) and a description of the corresponding features. Use the following lines to supply the CFCCs in the code:
try {
  IlvTigerDataSource source = new IlvTigerDataSource(filename);
  source.setManager(manager);
  source.setCFCCCodeList(new String[]{"A41"});
  source.start();
} catch (Exception e) {
  e.printStackTrace();
}
To retrieve the CFCC codes from an IlvFeatureSelectiorPanel, you can use the following code, which creates, instantiates and starts a TIGER/Line data source with the selected features:
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
final IlvFeatureSelectorPanel spanel = new IlvFeatureSelectorPanel(manager, "TigerFeaturesEN.txt");
JButton button = new JButton("OK");
button.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
  Vector src = new Vector();
  IlvFeatureSelectorPanel.Feature[] features = spanel.getSelectedFeatures();
  ArrayList cfccCodes = new ArrayList();
  if (features != null) {
    for (int j = 0; j < features.length; j++) {
      IlvFeatureSelectorPanel.Feature currentFeature = features[j];
     IlvFeatureSelectorPanel.Feature currentChild;
     int nChildren = currentFeature.getChildCount();
     if (nChildren != 0) {// major
        for (int i = 0; i < currentFeature.getChildCount(); i++) {
        currentChild = (IlvFeatureSelectorPanel.Feature) currentFeature.getChildAt(i);
        cfccCodes.add(currentChild.getMajorCode() + currentChild.getMinorCode());
       }
      } else {
       cfccCodes.add(currentFeature.getMajorCode() + currentFeature.getMinorCode());
       }
      }
     }
     String[] s = (String[])cfccCodes.toArray(new String[0]);
     try {
       source = new IlvTigerDataSource(filename);
       source.setManager(manager);
       source.setCFCCCodeList(s);
       source.start();
     } catch (Exception e1) {
        e1.printStackTrace(); }
}});
panel.add(button, BorderLayout.SOUTH);
JScrollPane pane = new JScrollPane(spanel);
panel.add(pane, BorderLayout.CENTER);
JFrame f = new JFrame();
f.getContentPane().add(panel);
f.pack();
f.setVisible(true);
The IlvTigerReader class
The IlvTigerReader class reads TIGER/Line files. It can be used independently, but it is usually created through the use of a IlvTigerDataSource. The method recordMatches can be overridden to select features to be read or discarded by the TIGER/Line reader.
File file = new File(filename);
IlvTigerReader reader =
  new IlvTigerReader(file.toURL().toExternalForm()) {
    public boolean recordMatches(IlvFeatureAttributeProperty properties) {
     if(properties == null)
       return false;
       return properties.getAttribute("CFCC").toString().equals("A41") ;
    }
  };
IlvMapFeature f = null;
IlvCoordinateSystem source = IlvGeographicCoordinateSystem.WGS84;
IlvCoordinateSystem dst = IlvGeographicCoordinateSystem.WGS84;
IlvCoordinateTransformation tr = IlvCoordinateTransformation.CreateTransformation(source, dst);
while ((f = reader.getNextFeature()) != null) {
  IlvGraphic g = reader.getDefaultFeatureRenderer().makeGraphic(f, tr);
  manager.addObject(g, false);
}
List of CFCC codes
See http://www.census.gov/geo/www/tiger.
The DXF reader
There are two ways of reading DXF format files:
*Using an IlvMapDXFReader instance directly. In this case, you must write all of the code required to render the DXF features into graphic objects, and then add them to the manager.
The IlvMapDXFReader class reads DXF features from a specified DXF file or catalog. It implements the IlvMapFeatureIterator interface to iterate over the read features.
*Using an IlvDXFDataSource. This is a convenient way of performing all the above operations at once and is more integrated with the data model of the map.
The IlvDXFDataSource class provides a convenient way of creating a set of layers containing DXF data in a manager. You can also georeference the geographic objects to create, as DXF data sets are usually nongeoreferenced.
The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir> /jviews-maps/samples/mapbuilder/index.html.
To read the DXF features and create vector data using the DXF readerobject:
1. Create an I lvMapDXFReader instance from the path of the DXF file:
String DXFpath = " C:/maps/DXF/map.dxf";
IlvMapDXFReader reader = new IlvMapDXFReader(DXFpath);
2. Set the transformation to use to render DXF, for example:
reader.setDestinationBounds(new Rectangle2D.Double
   (lonMinRad,latMinRad,lonMaxRad,latMaxRad));
3. Get the default DXF renderer:
IlvFeatureRenderer renderer = reader. getDefaultFeatureRenderer ();
4. Iterate over the features, render them, and assign them to a manager:
IlvMapFeature feature = reader.getNextFeature();
while(feature != null) {
  // Render map feature into graphic object
  IlvGraphic graphic = renderer.makeGraphic(feature,null);
  // Add this object on the first layer of the manager
  manager.addObject(graphic, 0, false);
  feature = reader.getNextFeature();
}
To read DXF features and create vector data using the DXF data source:
1. Create an IlvDXFDataSource :
String DXFpath = " C:/maps/DXF_0606_ed8/DXFT";
IlvDXFDataSource source = new IlvDXFDataSource(DXFpath);
2. Connect this data source with the manager of the view:
source.setManager(manager);
3. Set the transformation to use to render DXF into geo-referenced objects, for example:
source.setDestinationBounds(lonMinRad,latMinRad,lonMaxRad,latMaxRad);
Alternatively you can use a tailored transformation through the use of: setInternalTransformation.
4. Start the DXF data source:
source.start();
The KML reader and writer
Describes the KML reader and writer and exporting KML files.
*The KML reader and writer
*Describes the reader and writer for KML and KMZ files.
*Exporting KML files
*Describes how to export map data to a KML or KMZ file.
The KML reader and writer
There are two ways of reading KML/ KMZ files:
*Using an IlvKMLReader instance directly. In this case, you must write all the code required to render the KML features into graphic objects, and then add them to the manager.
This class reads KML features from a specified KML file or catalog. It implements the IlvMapFeatureIterator interface to iterate over the read features.
*Using an IlvKMLDataSource. This is a convenient way of performing all the above operations at once and is more integrated with the data model of the map.
The IlvKMLDataSource class provides a convenient way of creating a set of layers containing KML data in a manager.
The source code for the Map Builder demonstration, which contains all the code described in this section, can be found at <installdir> /jviews-maps/samples/mapbuilder/index.html.
To read KML features and create vector data using the IlvKMLReader object:
1. Create an IlvKMLReader instance from the path of the KML catalog:
String KMLpath = " C:/maps/KML/places.kmz";
IlvKMLReader reader = new IlvKMLReader(KMLpath);
2. Create a default renderer:
IlvFeatureRenderer renderer = new IlvDefaultFeatureRenderer();
3. Iterate over the features, render them with an appropriate IlvFeatureRenderer, and assign them to a manager:
IlvMapFeature feature = reader.getNextFeature();
while(feature != null) {
  // Render map feature into the graphic object.
  IlvGraphic graphic = renderer.makeGraphic(feature,null);
  // Add this object on the first layer of the manager.
  manager.addObject(graphic, 0, false);
  feature = reader.getNextFeature();
}
To read KML features and create vector data using the IlvKMLDataSource:
1. Create an IlvKMLDataSource :
String KMLpath = "C:/maps/KML_0606_ed8/KMLT";
IlvKMLDataSource source = new IlvKMLDataSource(KMLpath);
2. Connect this data source to the manager of the view:
source.setManager(getView().getManager());
3. Start the KML data source:
source.start();
NOTE JViews Maps does not support KML styles. This is because JViews Maps styles are made for layers whereas KML styles are made for individual objects and are therefore not compatible.
Exporting KML files
You can export part of a map to a KML (or KMZ) file using the Map Export API (see Map Export API). To do so, set an IlvKMLExporter as the vectorial exporter on the IlvMapExportManager. You can also use the raster exporter, if you want to export an overlaid image.
*If you set a KML file name, all images used inside that file are saved at the same location, with names such as image0.png.
*If you set a file name that ends with .kmz, all the files are compressed into a single kmz file:
IlvMapExportManager exportManager = new IlvMapExportManager();
IlvKMLExporter KMLExporter = new IlvKMLExporter();
exportManager.setVectorialExporter(KMLExporter);
exportManager.setRasterExporter(KMLExporter);
 
// Configure KML export (file name).
KMLExporter.setFileName("export.kml");
 
// Set the region of the map to export.
exportManager.setExportRegion(-Math.PI,-Math.PI/2, Math.PI,Math.PI/2);
 
// Export selected map layers of the map.
IlvMapLayer mapLayersToExport[]={/* table of map layers to export*/...};
exportManager.exportMapLayers(mapLayersToExport);
The DEM/GTOPO30 reader
GTOPO30 is a global digital elevation model (DEM) with a horizontal grid spacing of 30 arc seconds (approximately 1 kilometer). It covers the full extent of latitude from 90 degrees south to 90 degrees north, and the full extent of longitude from 180 degrees west to 180 degrees east. The vertical units represent elevation in meters above mean sea level. In the DEM, ocean areas have been masked as "no data" and have been assigned a value of -9999.
A full sample of a GTOPO30 database can be downloaded from: http://edcdaac.usgs.gov/gtopo30/gtopo30.asp.
The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir> /jviews-maps/samples/mapbuilder/index.html.
The IlvGTopo30Reader class is a file reader that creates reprojectable, stylable and pixel-on-demand images that can provide altitude data.
To create images:
1. First create an image reader and add the image file you want to be read:
IlvGTopo30Reader imageReader = new IlvGTopo30Reader();
imageReader.addMap(gtopoFile);
2. Create a data source and link it with the manager properties by inserting it into the data source tree:
IlvMapDataSource imageDataSource = IlvRasterDataSourceFactory.
   buildTiledImageDataSource(manager,imageReader,true,true,null);
IlvMapDataSourceModel dataSourceModel =
   IlvMapDataSourceProperty.GetMapDataSourceModel(manager);
dataSourceModel.insert(imageDataSource);
3. Start reading your data:
dataSourceModel.start();
Starting the data source creates the necessary tiled layers, tile managers and IlvRasterIcon instances to manage the pixel-on-demand feature and the progressive display of the geo-referenced image.
This icon associates altitude properties that can be used as altitude data sources, see Using the altitude provider property.
The Web Map Server reader
The OpenGIS® Web Map Service (WMS standard) Implementation Specification produces maps of spatially referenced data dynamically from geographic information. This international standard defines a map to be a portrayal of geographic information as a digital image file suitable for display on a computer screen. The OpenGIS standard provides three operations ( GetCapabilities, GetMap, and GetFeatureInfo ) in support of the creation and display of registered and superimposed map-like views of information that come simultaneously from multiple remote and heterogeneous sources. For more information about the OpenGIS standard, see http://www.opengeospatial.org/.
There are two ways of reading images from a Web Map Server (WMS):
*Using an IlvWMSReader instance directly. In this case, you must write all the code required to render the WMS features into graphic objects and add them to the manager.
*Using an IlvWMSDataSource. This is a convenient way of performing all the above operations at once and is more integrated with the data model of the map.
The source code for the Map Builder demonstration, which contains all the code described in this section, can be found at <installdir> /jviews-maps/samples/mapbuilder/index.html.
The IlvWMSReader class reads image features from a specified Web Map Server URL. It implements the IlvMapFeatureIterator interface to iterate over the read features.
The IlvWMSDataSource class provides a convenient way of creating a set of layers containing images retrieved from a Web Map Server in a manager.
To read WMS features from a Web Map Server using the IlvWMSReader class and create raster data:
1. Create an IlvWMSReader instance from a server URL. A WMS server URL can be the full http WMS request for capabilities, or at least the WMS request URL for this server. This information is dependent on the server itself and is usually available in the server's documentation. For instance :
URL url = new URL("http://wms.jpl.nasa.gov/wms.cgi?request=GetCapabilities"); // "http://wms.jpl.nasa.gov/wms.cgi" will work as well
IlvWMSReader reader = new IlvWMSReader(url);
2. Set the name of the layers to be rendered. The layer names can be retrieved from the server capabilities:
String[] layers = reader.getAvailableLayers();
reader.setLayerNames(new String[]{layers[0]});
3. Set the transformation to use to render WMS images, for example:
IlvCoordinateSystem cs = IlvCoordinateSystemProperty.
   GetCoordinateSystem(manager);
reader.setTransformation(IlvCoordinateTransformation.CreateTransformation
   (cs, IlvGeographicCoordinateSystem.KERNEL));
4. Iterate over the features, render them with an appropriate IlvFeatureRenderer, and assign them to a manager:
IlvMapFeature feature = reader.getNextFeature();
IlvFeatureRenderer renderer = reader.getDefaultFeatureRenderer();
while(feature != null) {
  // Render the map feature into a graphic object.
  IlvGraphic graphic = renderer.makeGraphic(feature,null);
  // Add this object to the first layer of the manager.
  manager.addObject(graphic, 0, false);
  feature = reader.getNextFeature();
}
To read WMS features using the IlvWMSDataSource class :
1. Create an IlvWMSDataSource instance from a server URL. A WMS server URL can be the full http WMS request for capabilities, or at least the WMS request URL for this server. This information is dependent on the server itself and is usually available in the server's documentation. For instance:
URL url = new URL("http://wms.jpl.nasa.gov/wms.cgi?request=GetCapabilities"); // "http://wms.jpl.nasa.gov/wms.cgi" will work as well
IlvWMSDataSource source = new IlvWMSDataSource(url);
2. Set the layers to be retrieved:
IlvWMSReader reader = source.getReader();
String[] layers = reader.getAvailableLayers();
source.setLayers(new String[]{layers[0]});
3. Optionally set tiling parameters, to enable load-on-demand and better image resolution when zooming in:
source.setTilingParameters(true,5,5);
4. Connect this data source with the manager of the view:
source.setManager(manager);
5. Finally, start the WMS data source:
source.start();
The SVG reader
There are two ways of reading SVG files:
*Use an IlvMapSVGReader instance directly. When you use IlvMapSVGReader, you must write all of the code required to render the SVG features into graphic objects, and to add them to the manager.
This class reads SVG features from a specified SVG file or catalog. It implements the IlvMapFeatureIterator interface to iterate over the features to be read.
*Use an IlvSVGDataSource. This is a convenient way of performing all of the above operations at once. Using IlvSVGDataSource is better integrated with the data model of the map.
The IlvSVGDataSource class provides a convenient way to create a set of layers containing SVG data in a manager.
The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir> /jviews-maps/samples/mapbuilder/index.html.
To read SVG features and create vector data:
1. Create a new IlvMapSVGReader instance using the path to the SVG catalog.
2. Set the transformation to use to render the SVG data. The following code example shows an specimen transformation:
3. retrieve the default SVG renderer.
4. Iterate over the features, render them, and assign them to a manager:
String SVGpath = " C:/maps/SVG/map.svg";
IlvMapSVGReader reader = new IlvMapSVGReader(SVGpath);
reader.setDestinationBounds(lonMinRad,latMinRad,lonMaxRad,latMaxRad);
IlvFeatureRenderer renderer = reader.getDefaultFeatureRenderer();
IlvMapFeature feature = reader.getNextFeature();
while(feature != null) {
  // Render map feature into a graphic object
  IlvGraphic graphic = renderer.makeGraphic(feature,null);
  // Add this object to the first layer of the manager
  manager.addObject(graphic, 0, false);
  feature = reader.getNextFeature();
}
To read SVG features and create vector data:
1. Create a new IlvSVGDataSource instance.
2. Connect this data source with the manager of the view.
3. Set the transformation to render the SVG data into geo-referenced objects.
4. Start the SVG data source.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.