ilog.views.maps.format.wms
Class IlvWMSReader

java.lang.Object
  extended by ilog.views.maps.format.wms.IlvWMSReader
All Implemented Interfaces:
IlvPersistentObject, IlvMapFeatureIterator, IlvMapReusableFeatureIterator, IlvMapRegionOfInterestIterator

public class IlvWMSReader
extends Object
implements IlvMapRegionOfInterestIterator, IlvPersistentObject

A map reader that can read image layers from a OpenGIS-compliant server. To instantiate such a reader, you can use:

 URL url = new URL("http://www.ilog.com"); // This will not work and is only given as an example. Put a real WMS server URL 
 here!
 IlvWMSReader reader = new IlvWMSReader(url);
 IlvCoordinateSystem cs = IlvCoordinateSystemProperty.GetCoordinateSystem(manager);
 reader.setTransformation(IlvCoordinateTransformation.CreateTransformation(cs,IlvGeographicCoordinateSystem.KERNEL));
 String[] layerNames = reader.getAvailableLayers();
 reader.setLayerNames(layerNames);
 IlvMapFeature feature; 
 while((feature = reader.getNextFeature()) != null) {
     IlvGraphic g = reader.getDefaultFeatureRenderer().makeGraphic(feature, reader.getTransformation());
     manager.addObject(g, false);
 }      
 

Since:
JViews 8.0

Constructor Summary
IlvWMSReader(IlvInputStream stream)
          Constructs an IlvWMSReader from an IlvInputStream.
IlvWMSReader(String surl)
          Constructs an IlvWMSreader from a string representation of a URL.
IlvWMSReader(URL url)
          Constructs an IlvWMSreader from a URL.
 
Method Summary
 void dispose()
          Releases the resources allocated by the feature iterator (files, connections, and so on).
 String[] getAvailableLayers()
          Returns the names of the available layers.
 double[] getBBox()
          Returns the bounding box used for the query to the server.
 URL getCapabilityURL()
          Returns the URL used to retrieve the capabilities of the server.
 IlvCoordinateSystem getCoordinateSystem()
          Returns the spatial reference system that describes the coordinate system of geometric coordinates of the map features.
 IlvFeatureRenderer getDefaultFeatureRenderer()
          Returns the renderer used to translate map features into IlvGraphics.
 InputStream getErrorStream()
          Retrieves the error stream, if an error occurs.
 File getFeaturesFile()
          Returns a file with a content suitable for passing to an IlvFeatureSelectorPanel.
 InputStream getFeaturesStream()
          Returns a stream with a content suitable for passing to an IlvFeatureSelectorPanel.
 String getImageFormat()
          Retrieves the image format used to construct the request.
 float getImageSize()
          Returns the requested image size, which is a floating number between 0 (excluded) and 1.
 Rectangle2D getLatLonBounds()
          Returns the latitude/longitude bounds for the list of all geometries or null if such is not available.
 IlvCoordinate getLowerRightCorner()
          Returns the lower right corner of the rectangle containing all the map feature of the list, or null if the iterator cannot provide this information.
 URL getMapURL()
          Gets the URL to be used to retrieve the image from the server.
 IlvMapFeature getNextFeature()
          Returns the next map feature of the iterator or null, if the iteration is finished.
 String getNextLayerName()
          Returns the layer name to be processed in the next call to getNextFeature.
 IlvWMSLayerNode[] getNodes(String[] layers)
          Returns the array of the layers which the names are specified as arguments.
 String getRS(boolean check)
          Returns the SRS of this reader as specified by setSRS(String).
 IlvWMSServerNode getServer()
          Returns the server node.
 IlvCoordinateTransformation getTransformation()
          Returns the transformation used to read in images from the WMS.
 IlvCoordinate getUpperLeftCorner()
          Returns the upper left corner of the rectangle containing all the map features of the list, or null if the iterator cannot provide this information.
 URL getURL()
          Returns the URL given at construction time.
 String getVersion()
          Returns the version of the supported WMS protocol.
static String getWKT(String tok)
          Returns the Well Known Text corresponding to the SRS whose EPSG number is given as argument.
 boolean isFlatteningLayers()
          Indicates if the reader is rendering all the layers into a single image or not.
 boolean isGeoreferenced()
          Returns true if the map reader can provide the source projection of its map features. This reader is georeferenced, so this method returns true.
 boolean isTransparency()
          Indicates if the requested image contains transparent pixels or not.
 IlvMapFeature makeMapFeature(URL u, IlvWMSLayerNode node)
          Constructs the map feature from this URL.
 URL makeURL(IlvWMSLayerNode node)
          Creates the URL that points to the image to retrieve.
 void restart()
          Rewinds the iterator for a new use.
 void setBBox(double[] box)
          Set the bounding box used for the query to the server.
 void setCoordinateSystem(IlvCoordinateSystem cs)
          Sets the coordinate system for this reader.
 void setFlatteningLayers(boolean flatten)
          Indicates if the reader should render all the layers into a single image.
 void setImageFormat(String f)
          Sets the image format to be used in the request.
 void setImageSize(float sz)
          Sets the image size requested by this reader.
 void setLayerNames(String[] layerNames)
          Sets the names of the layers to be read by this reader.
 void setRegionOfInterest(double lonMin, double latMin, double lonMax, double latMax)
          Sets the region of interest to return features for.
 void setRS(String srs)
          Sets the SRS of this reader.
 void setTransformation(IlvCoordinateTransformation transformation)
          Sets the transformation to use when reading images from the kernel into the manager coordinate system.
 void setTransparency(boolean tr)
          Indicates if the requested image contains transparent pixels or not.
 void setVersion(String version)
          Sets the version number to be used in the request to the server.
 void write(IlvOutputStream stream)
          Writes this reader to an IlvOutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlvWMSReader

public IlvWMSReader(URL url)
Constructs an IlvWMSreader from a URL.

Parameters:
url - The URL of the server.

IlvWMSReader

public IlvWMSReader(String surl)
             throws MalformedURLException
Constructs an IlvWMSreader from a string representation of a URL.

Parameters:
surl - The String representation of the URL.
Throws:
MalformedURLException

IlvWMSReader

public IlvWMSReader(IlvInputStream stream)
             throws IlvReadFileException
Constructs an IlvWMSReader from an IlvInputStream.

Parameters:
stream - The stream to read from.
Throws:
IlvReadFileException - if an error occurs
Method Detail

write

public void write(IlvOutputStream stream)
           throws IOException
Writes this reader to an IlvOutputStream.

Specified by:
write in interface IlvPersistentObject
Parameters:
stream - The stream to write to.
Throws:
IOException - if an error occurs

getVersion

public String getVersion()
Returns the version of the supported WMS protocol.

Returns:
Returns "1.1.0" if no other value has been set.

restart

public void restart()
Rewinds the iterator for a new use.

Specified by:
restart in interface IlvMapReusableFeatureIterator

getCapabilityURL

public URL getCapabilityURL()
                     throws MalformedURLException
Returns the URL used to retrieve the capabilities of the server.

Returns:
the URL used to retrieve the capabilities of the server.
Throws:
MalformedURLException

setLayerNames

public void setLayerNames(String[] layerNames)
Sets the names of the layers to be read by this reader.

Parameters:
layerNames - An array of strings containing the list of layer names to be read.

setFlatteningLayers

public void setFlatteningLayers(boolean flatten)
Indicates if the reader should render all the layers into a single image.

Parameters:
flatten - Set to true to render all the layers into a single image, or false to produce an IlvMapFeature for each layer.

isFlatteningLayers

public boolean isFlatteningLayers()
Indicates if the reader is rendering all the layers into a single image or not.

Returns:
Set to true if the reader is rendering all the layers into a single image, otherwise false.

getNextFeature

public IlvMapFeature getNextFeature()
                             throws IOException
Returns the next map feature of the iterator or null, if the iteration is finished. The features returned are features containing IlvMapRasterGeometry geometries.

Specified by:
getNextFeature in interface IlvMapFeatureIterator
Returns:
The next map feature or null, if the iteration is finished.
Throws:
IOException

getURL

public URL getURL()
Returns the URL given at construction time.

Returns:
The URL used to construct the reader.

getMapURL

public URL getMapURL()
Gets the URL to be used to retrieve the image from the server.

Returns:
The URL to be used to retrieve the image from the server or null, if no feature is available.

makeURL

public URL makeURL(IlvWMSLayerNode node)
Creates the URL that points to the image to retrieve.

Parameters:
node - The IlvWMSLayerNode.
Returns:
The URL.

setImageSize

public void setImageSize(float sz)
Sets the image size requested by this reader. The image size must be greater than zero and less than or equal to 1. An image size of 1 corresponds to an image whose largest dimension is 2048 pixels.

Parameters:
sz - The requested image size, between 0 (excluded) and one (included).

getImageSize

public float getImageSize()
Returns the requested image size, which is a floating number between 0 (excluded) and 1.

Returns:
The image size.
See Also:
setImageSize(float)

getRS

public String getRS(boolean check)
Returns the SRS of this reader as specified by setSRS(String).

Parameters:
check - Specifies if the method should check for SRS validity.
Returns:
The SRS of the current layer.

setRS

public void setRS(String srs)
Sets the SRS of this reader.

Parameters:
srs - The SRS to set.

setVersion

public void setVersion(String version)
Sets the version number to be used in the request to the server.

Parameters:
version - The version number to be used in the request to the server.

setImageFormat

public void setImageFormat(String f)
Sets the image format to be used in the request.

Parameters:
f - The image format to be used in the request.

getImageFormat

public String getImageFormat()
Retrieves the image format used to construct the request. If an image format has been specified by setImageFormat, then this format is returned. Otherwise the first of the image formats specified in the capabilities is returned, if any.

Returns:
The image format to be used to construct the request.

setTransparency

public void setTransparency(boolean tr)
Indicates if the requested image contains transparent pixels or not.

Parameters:
tr - Set to true to retrieve a transparent image, otherwise false.

isTransparency

public boolean isTransparency()
Indicates if the requested image contains transparent pixels or not.

Returns:
Returns true if the requested image contains transparent pixels, otherwise false.

getWKT

public static String getWKT(String tok)
Returns the Well Known Text corresponding to the SRS whose EPSG number is given as argument.

Parameters:
tok - The EPSG SRS number
Returns:
the WKT describing the SRS.

makeMapFeature

public IlvMapFeature makeMapFeature(URL u,
                                    IlvWMSLayerNode node)
                             throws IOException
Constructs the map feature from this URL.

Parameters:
u - The URL, pointing to the image to be retrieved.
node - The IlvWMSLayerNode
Returns:
The IlvMapFeature with an IlvMapRasterGeometry.
Throws:
IOException

getErrorStream

public InputStream getErrorStream()
Retrieves the error stream, if an error occurs. This stream is valid after the call to getNextFeature().

Returns:
The error stream or null, if no error occurred.

isGeoreferenced

public boolean isGeoreferenced()
Returns true if the map reader can provide the source projection of its map features. This reader is georeferenced, so this method returns true.

Specified by:
isGeoreferenced in interface IlvMapFeatureIterator

setCoordinateSystem

public void setCoordinateSystem(IlvCoordinateSystem cs)
Sets the coordinate system for this reader.

Parameters:
cs - The coordinate system to be set.

getCoordinateSystem

public IlvCoordinateSystem getCoordinateSystem()
Returns the spatial reference system that describes the coordinate system of geometric coordinates of the map features.

Specified by:
getCoordinateSystem in interface IlvMapFeatureIterator
Returns:
The coordinate system, or null if the coordinate system is unknown.

getUpperLeftCorner

public IlvCoordinate getUpperLeftCorner()
Returns the upper left corner of the rectangle containing all the map features of the list, or null if the iterator cannot provide this information.

Specified by:
getUpperLeftCorner in interface IlvMapFeatureIterator

getLowerRightCorner

public IlvCoordinate getLowerRightCorner()
Returns the lower right corner of the rectangle containing all the map feature of the list, or null if the iterator cannot provide this information.

Specified by:
getLowerRightCorner in interface IlvMapFeatureIterator

getDefaultFeatureRenderer

public IlvFeatureRenderer getDefaultFeatureRenderer()
Returns the renderer used to translate map features into IlvGraphics. This implementation returns an IlvRasterImageRenderer.

Specified by:
getDefaultFeatureRenderer in interface IlvMapFeatureIterator
Returns:
The renderer used to translate map features into IlvGraphics.

dispose

public void dispose()
Releases the resources allocated by the feature iterator (files, connections, and so on).

Specified by:
dispose in interface IlvMapFeatureIterator

getServer

public IlvWMSServerNode getServer()
Returns the server node.

Returns:
The server node.

setRegionOfInterest

public void setRegionOfInterest(double lonMin,
                                double latMin,
                                double lonMax,
                                double latMax)
Sets the region of interest to return features for. After this method is called, the IlvMapFeatureIterator.getNextFeature() method should not return any feature which geometry is outside this area.

Specified by:
setRegionOfInterest in interface IlvMapRegionOfInterestIterator
Parameters:
lonMin - longitude min in radians.
latMin - latitude min in radians.
lonMax - longitude max in radians.
latMax - latitude max in radians.

getLatLonBounds

public Rectangle2D getLatLonBounds()
Returns the latitude/longitude bounds for the list of all geometries or null if such is not available.

Specified by:
getLatLonBounds in interface IlvMapRegionOfInterestIterator
Returns:
a rectangle enclosing all features.

setTransformation

public void setTransformation(IlvCoordinateTransformation transformation)
Sets the transformation to use when reading images from the kernel into the manager coordinate system.

Parameters:
transformation - The transformation used to read images.

getTransformation

public IlvCoordinateTransformation getTransformation()
Returns the transformation used to read in images from the WMS.

Returns:
Returns the transformation used to read in images from the WMS.

getFeaturesFile

public File getFeaturesFile()
                     throws IOException
Returns a file with a content suitable for passing to an IlvFeatureSelectorPanel. It is the responsibility of the caller to delete this file.

Returns:
A File containing the available features.
Throws:
IOException

getFeaturesStream

public InputStream getFeaturesStream()
                              throws IOException
Returns a stream with a content suitable for passing to an IlvFeatureSelectorPanel.

Returns:
An InputStream containing the available features.
Throws:
IOException

getAvailableLayers

public String[] getAvailableLayers()
Returns the names of the available layers.

Returns:
The names of the available layers.

getNodes

public IlvWMSLayerNode[] getNodes(String[] layers)
Returns the array of the layers which the names are specified as arguments.

Parameters:
layers - The name of the layers to retrieve.
Returns:
The array of corresponding nodes.

getNextLayerName

public String getNextLayerName()
Returns the layer name to be processed in the next call to getNextFeature.

Returns:
The layer name to be processed in the next call to getNextFeature.

getBBox

public double[] getBBox()
Returns the bounding box used for the query to the server.

Returns:
the bounding box used for the query to the server.

setBBox

public void setBBox(double[] box)
Set the bounding box used for the query to the server.

Parameters:
box - the bounding box to use.


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.