skip to main content
Programmer's documentation > Programming with JViews Maps > Creating a map application using the API > Creating data source objects
 
Creating data source objects
Describes how to create data source objects for vector and raster data sources.
*Data source
*Explains what a data source is in the context of maps.
*Vector data sources
*Describes how to create data source objects for any of the following files: ESRI Shapefile, MID/MIF, TIGER/Line®, DXF (AutoCAD), KML or KMZ, SVG.
*Raster data sources
*Describes the common API for raster (image data sources.
Data source
A data source is an object that connects a feature iterator, a renderer, and a map layer.
A data source uses the feature iterator to get global data information, such as the coordinate system and bounding box, and the list of map features to parse. Then it uses the renderer to create graphic objects. Finally, it uses the layer to manage the order and style of those objects.
In class terms, a data source is a class that connects an IlvMapReusableFeatureIterator, an IlvFeatureRenderer and an IlvMapLayer. It uses the iterator object to get global data information, such as the coordinate system and bounding box, and the list of IlvMapFeature objects to parse. Then it uses the renderer object to create graphic objects. Finally it uses the layer object to manage the order and style of the graphic objects.
Vector data sources
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
ESRI shapefile
When you create a Shapefile format data source the shapefiles can be loaded with or without the tiling mechanism. When using tiling, the data is loaded in a background thread.
The complete source code for an ESRI shapefile demonstration can be found at <installdir> /jviews-maps/shape/mapbuilder/index.html
Loading a shapefile using tiling
To load a shapefile using tiling, use the following code:
 
IlvTiledShapeDataSource tiledSource = new
IlvTiledShapeDataSource(shpFileName,true);
If the shapefile does not have a tiling index file, you can create the index file as follows:
 
IlvShapeFileTiler tiler = new IlvShapeFileTiler(shpFileName, shxFileName,
indexFileName, tileWidth, tileHeight);
while(tiler.getNextFeature() != null) {
  tiler.addInfo();
}
tiler.close();
The resulting index file, which is used in the reader, can be set with a call to:
 
tiledSource.setIdxFilename(idxFileName);
Loading a shapefile without using tiling
To load a shapefile without using tiling, use the following code:
 
IlvShapeDataSource shpDataSource = new IlvShapeDataSource(shpFileName, true);
MID/MIF
To create a MID/MIF file data source, use the following code:
 
IlvMapDataSource source = new IlvMIDMIFDataSource(fileName);
source.setManager(getView().getManager());
TIGER/Line
To create a TIGER/Line data source, use the following code:
 
IlvTigerDataSource source = new IlvTigerDataSource(fileName);
source.setManager(getView().getManager());
TIGER/Line® data contains many different features. You can select the features to import into your map by choosing the CFCC codes of the features you want:
 
source.setCFCCCodeList(CFCCCodes);
DXF (AutoCAD)
The DXF format (Drawing Interchange Format) is the interchange format for AutoCAD. This format supports vector graphics (polygons, arcs, lines, points...) and layers.
The specifications of the various releases of the DXF format can be found at the following URL: http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=5129239.
For details of the limitations with a DXF data source, refer to Drawing Exchange Format (DXF) in the section on managers in The Essential JViews Framework.
To create a DXF data source, use the following code:
 
IlvDXFDataSource source = new IlvDXFDataSource("C:/maps/DXF/maps.dxf");
source.setManager(getView().getManager());
You must then set up the transformation you want to use to read DXF.
If you want to transform the DXF extent into the latitude/longitude range provided, call:
 
source.setDestinationBounds(lonMinRad,latMinRad,lonMaxRad,latMaxRad);
If you want to use a more complex transformation (such as reprojection), call:
 
IlvMathTransform mathTransform =…/create mathematical transformation
   source.setInternalTransformation(mathTransform);
An example of how to create a complex transformation is given in the Map Builder demonstration, through use of the DXFControlModel class.
KML or KMZ
KML/ KMZ is an XML-based numerical map format containing both vectorial and raster information. KML is published by Google™, for use in their Google Earth© Product.
You can find more information at http://earth.google.com/kml/kml_intro.html.
JViews Maps supports import of the KML elements shown in KML element support:
KML element support
Element
Support
Placemarks
Geometric Shapes, Location.
Geometry
Points, Lines, Polygons.
Image Overlays
Ground Overlays.
Styles
No Support.
Grouping Mechanisms
Documents, Folders, Geometry Collections.
Network Links
Locations.
KML files can refer to other files, either locally or through a network link URL. KMZ is a compressed file containing a single doc.xml entry and a set of auxiliary files, such as images or icons.
To create a KML data source, use the following code:
 
IlvKMLDataSource source = new IlvKMLDataSource("C:/maps/KML/places.kmz");
source.setManager(getView().getManager());
SVG
SVG (Scalable Vector Graphic) is a language for describing two-dimensional graphics and graphical applications in XML. The specifications of the SVG format can be found at http://www.w3.org/Graphics/SVG.
The JViews Maps SVG reader is based on features in Rogue Wave® JViews Framework. These features are described in the section on Scalable Vector Graphics in The Advanced JViews Framework.
The JViews Maps SVG reader ignores the following SVG elements:
*Images defined through the image element.
*Text defined through the text-path element.
All the other elements, including text elements, are transformed into IlvMapGeneralPath instances.
The graphic styles in the resulting map are rendered to look as close as possible to the original version. However, the styles created are limited to the data available for styling such an object.
To create an SVG data source, use the following code:
 
IlvSVGDataSource source = new IlvSVGDataSource("C:/maps/SVG/maps.svg");
source.setManager(getView().getManager());
You then need to set up the transformation you want to use to read SVG. To transform the SVG extent into the latitude/longitude range provided, call:
 
source.setDestinationBounds(lonMinRad,latMinRad,lonMaxRad,latMaxRad);
To use a more complex transformations such as reprojection, call:
 
IlvMathTransform mathTransform = //create mathematical transformation
source.setInternalTransformation(mathTransform);
An example of how to create a complex transformation using of the ControlModel example class can be found at <installdir> /jviews-maps/samples/mapbuilder/index.html
Raster data sources
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
All raster (image) data sources have a common API. To create your data source, you need to create an IlvRasterAbstractReader for the type of data to be read, and then use this reader to build a tiled image data source.
Raster reader classes
The raster reader classes for the different image formats are as follows.
 
GEOTIFF
IlvRasterGeoTiffReader
DTED
IlvRasterDTEDReader
GTOPO30
IlvGTopo30Reader
Non-geo-referenced images(*)
IlvRasterBasicImageReader
Images from OpenGIS compliant Web Map Servers
IlvWMSReader
(*) Non georeferenced images must be geo-referenced, see Georeferencing a nongeoreferenced image.
Creating a raster reader
To create a raster reader and add all image files to be read you can, for example, use the following code:
Creating a tiled data source
To create a data source for the reader:
 
IlvRasterDTEDReader reader = new IlvRasterDTEDReader();
for(int i=0;i<fileName.length;i++) {
  reader.addMap(fileName[i]);
}
IlvMapDataSource DTEDDataSource =
IlvRasterDataSourceFactory.buildTiledImageDataSource(manager,reader,true,true,null);
DTEDDataSource.setName("name in data source panel");
The IlvTiledRasterDataSource returned by the IlvRasterDataSourceFactory executes image reading in a background thread.
Georeferencing a nongeoreferenced image
To georeference a nongeoreferenced image, you can set the longitude and latitude image bounds:
 
reader.setImageBounds(0,-Math.PI,Math.PI/2,Math.PI,-Math.PI/2);
Alternatively, you can compute a more complex mathematical transformation and set it on the reader:
 
reader.setInternalTransformation(trans);
NOTE The non georeferenced image reader does not support multiple calls to addMap.
Images from OpenGIS-compliant Web Map Servers
This section gives information about the OpenGIS® Web Map Server (WMS standard). This International Standard specifies the behavior of a service that produces spatially referenced maps dynamically from geographic information. It specifies operations to retrieve a description of the maps offered by a server and to query a server about features displayed on a map. The standard is not applicable to the retrieval of actual feature data or coverage data values, but is applicable to pictorial renderings of maps in a graphical format. These capabilities are provided by a Web Feature and Web Coverage Service.
In a basic WMS, only a limited number of predefined styles can be applied to features. The mechanism that enables users to define their own styles is defined in the OGC Styled Layer Descriptor Implementation Specification. An SLD-enabled WMS retrieves feature data from a Web Feature Service and applies explicit styling information provided by the user in order to render a map.
The ISO/TC 211 also defines a standard for Web Map Servers, see ISO 19128.
Importing a WMS image
JViews Maps supports the import of images from a WMS server.
To create a WMS data source, use the following code:
 
URL url = new URL("http://geo.compusult.net/scripts/mapman.dll?
   Name=weather&REQUEST=GetCapabilities");
IlvWMSReader reader = new IlvWMSReader(url);
IlvWMSDataSource source = new IlvWMSDataSource(reader);
source.setManager(manager);

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