ucar.unidata.data.gis
Class KmlDataSource

java.lang.Object
  extended by ucar.unidata.collab.SharableImpl
      extended by ucar.unidata.data.DataSourceImpl
          extended by ucar.unidata.data.FilesDataSource
              extended by ucar.unidata.data.gis.KmlDataSource
All Implemented Interfaces:
Sharable, DataSource, DataSourceFactory, XmlPersistable

public class KmlDataSource
extends FilesDataSource

DataSource for Web Map Servers

Version:
$Revision: 1.38 $ $Date: 2007/04/16 20:34:52 $
Author:
IDV development team

Field Summary
static String ATTR_NAME
          xml attribute
static String ATTR_PARENT
          xml attribute
protected  List cachedData
          A local cache
protected  List cachedUrls
          The urls
static String EXT_KML
          For ximg files
static PatternFileFilter FILTER_KML
          For ximg files
static String SUFFIX_KML
          For ximg files
static String TAG_DOCUMENT
          kml tag id
static String TAG_FOLDER
          kml tag id
static String TAG_GROUNDOVERLAY
          kml tag id
static String TAG_HREF
          xml tag
static String TAG_KML
          xml tag
static String TAG_LINESTRING
           
static String TAG_LINK
          xml tag
static String TAG_MULTIGEOMETRY
          kml tag id
static String TAG_NAME
          kml tag id
static String TAG_NETWORKLINK
          kml tag id
static String TAG_PHOTOOVERLAY
          kml tag
static String TAG_PLACEMARK
          kml tag id
static String TAG_SCHEMA
          xml tag
static String TAG_URL
          xml tag
 
Fields inherited from class ucar.unidata.data.FilesDataSource
adapters, oldSourceFromBundles, sources
 
Fields inherited from class ucar.unidata.data.DataSourceImpl
changeDataPathsCbx, dataCacheKey, dataChoices, geoSelectionPanel, haveBeenUnPersisted, okToContinue, PARAM_SHOW_HIDE, PARAM_SHOW_NO, PARAM_SHOW_YES
 
Fields inherited from interface ucar.unidata.data.DataSource
DATAPATH_DATE_FORMAT, DATAPATH_DATE_PATTERN, MOST_RECENT, ordinalNames, PROP_AUTOCREATEDISPLAY, PROP_BASEDIRECTORY, PROP_CACHEABLE, PROP_DATACHOICENAME, PROP_DISPLAYPROPERTIES, PROP_DOCUMENTLINKS, PROP_FILEPATTERN, PROP_GEOLOCATION, PROP_ICON, PROP_NAME, PROP_POLLINFO, PROP_RESOLVERURL, PROP_SERVICE_HTTP, PROP_SUBPROPERTIES, PROP_TIMELABELS, PROP_TITLE
 
Constructor Summary
KmlDataSource()
          Dummy constructor so this object can get unpersisted.
KmlDataSource(DataSourceDescriptor descriptor, String kmlUrl, Hashtable properties)
          Create a KmlDataSource from the specification given.
 
Method Summary
static String createKml(GeoLocationInfo bounds, String imageFileName)
          Create some kml from the given bounds and image file
static void createLatLonBox(GeoLocationInfo bounds, StringBuffer sb)
          Utility to create a latlonbox kml
protected  void doMakeDataChoices()
          Create the data choices associated with this source.
protected  List doMakeDateTimes()
          Create a list of times for this data source.
 void expandIfNeeded(CompositeDataChoice parent)
          Expand the data choice if its a networklink
protected  Data getDataInner(DataChoice dataChoice, DataCategory category, DataSelection dataSelection, Hashtable requestProperties)
          Actually get the data identified by the given DataChoce.
protected  InputStream getInputStream(String path)
          Create the input stream.
 void initAfterUnpersistence()
          Initialize after we have been unpersisted
static boolean isKmlFile(String filename)
          Is this a kml or kmz file
static void main(String[] args)
          test main
protected  byte[] readBytes(String path)
          Utility to read the bytes from the file or url
protected  Image readImage(String url, String baseUrl)
          Read the image
 void reloadData()
          reload
 void setKmlUrl(String value)
          Set the KmlUrl property.
protected  boolean shouldCache(Data data)
          See if this DataSource should cache or not
static void writeToFile(String kmlFilename, GeoLocationInfo bounds, String imageFileName)
          write image as a kml to file
 
Methods inherited from class ucar.unidata.data.FilesDataSource
doRemove, equals, getDataFileExtension, getDataPaths, getFilePath, getFullDescription, getInputStreams, getLocationsForPolling, getPartialDescription, getSource, getSources, haveSources, initAfterCreation, initWithPollingInfo, isFileBased, newFilesFromPolling, processDataFilename, propertiesChanged, reloadData, saveDataToLocalDisk, setNewFiles, setSource, setSources, sourcesChanged, updateState
 
Methods inherited from class ucar.unidata.data.DataSourceImpl
addActions, addDataChangeListener, addDataChoice, addPropertiesTabs, addReloadTab, applyFieldMask, applyProperties, beginWritingDataToLocalDisk, canAddCurrentName, canCacheDataToDisk, canChangeData, canDoFieldMask, canDoGeoSelection, canDoGeoSelectionMap, canDoGeoSelectionStride, canPoll, canSaveDataToLocalDisk, canShowParameter, checkForInitAfterUnPersistence, clearCachedData, clearFileCache, clearTimes, convertSourceFile, convertToFilesIfDirectory, createAutoDisplay, createCacheKey, createElement, decrOutstandingGetDataCalls, doDirectory, doMakeGeoSelectionPanel, doMakeGeoSelectionPanel, doMakeGeoSelectionPanel, doMakeGeoSubsetPropertiesComponent, endWritingDataToLocalDisk, findDataChoice, findDataChoices, flushCache, getAbsoluteDateTimes, getActions, getAlias, getAllDateTimes, getAllDateTimes, getAllLevels, getAllLevels, getAllTimesForTimeDriver, getCache, getCache, getCacheClearDelay, getCacheDataToDisk, getCompositeDataChoices, getData, getData, getDataCachePath, getDataChangeListeners, getDataChoices, getDataContext, getDataInner, getDataIsEditable, getDataPrefix, getDataSelection, getDataSelectionComponents, getDataSource, getDateTimes, getDateTimeSelection, getDescription, getDescriptor, getErrorMessage, getEverChangedName, getExtraGeoSelectionComponent, getExtraTimesComponent, getFileFilterForPolling, getid, getIdv, getInError, getLocalDirectory, getLocationForPolling, getMostRecentFiles, getName, getNameForDataSource, getNeedToShowErrorToUser, getNextId, getOutstandingGetDataCalls, getPassword, getPathsThatCanBeRelative, getPollingInfo, getProperties, getPropertiesComponents, getPropertiesHeader, getProperty, getProperty, getProperty, getProperty, getProperty, getProperty, getProperty, getRelativePaths, getSampleDataProjection, getSaveDataFileLabel, getSelectedDateTimes, getSelectedDateTimes, getTimesFromDataSelection, getTmpPaths, getTypeName, getUserName, handlePropertiesAction, hasPollingInfo, holdsDateTimes, holdsIndices, identifiedBy, identifiedByName, incrOutstandingGetDataCalls, initAfter, initDataChoice, initDataSelectionComponents, initFromXml, isPolling, loadFieldMask, loadFieldMask, loadLatestFile, logException, logException, makeDerivedDataChoices, makeSaveLocalActions, newFileFromPolling, notifyDataChange, putCache, putCache, reloadProperties, removeCache, removeDataChangeListener, removeDataChoice, removeProperty, replaceDataChoice, resetTmpState, saveDataToLocalDisk, saveDataToLocalDisk, selectTimesFromList, setAlias, setAskToUpdate, setCacheClearDelay, setCacheDataToDisk, setDataEditableStrings, setDataIsEditable, setDataIsRelative, setDataRelativeStrings, setDataSelection, setDateTimeSelection, setDescription, setDescriptor, setDirectory, setEverChangedName, setInError, setInError, setInError, setName, setObjectProperties, setObjectProperty, setPassword, setPollingInfo, setPollLocation, setProperties, setProperty, setProperty, setRelativePaths, setTemplateName, setTmpPaths, setUserName, shouldCache, showPasswordDialog, showPropertiesDialog, showPropertiesDialog, showPropertiesDialog, showWaitDialog, tick, toString, toStringTruncated, updateDetailsText, writeFieldMaskFile, writeFieldMaskFile
 
Methods inherited from class ucar.unidata.collab.SharableImpl
applySharableProperties, doShare, doShare, doShareExternal, doShareInternal, getReceiveShareTime, getSharablePropertiesComponent, getShareGroup, getSharing, getUniqueId, initSharable, receiveShareData, removeSharable, setReceiveShareTime, setShareGroup, setSharing, setUniqueId, showSharableDialog
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ucar.unidata.data.DataSource
getUniqueId
 

Field Detail

FILTER_KML

public static final PatternFileFilter FILTER_KML
For ximg files


EXT_KML

public static final String EXT_KML
For ximg files

See Also:
Constant Field Values

SUFFIX_KML

public static final String SUFFIX_KML
For ximg files

See Also:
Constant Field Values

ATTR_PARENT

public static final String ATTR_PARENT
xml attribute

See Also:
Constant Field Values

ATTR_NAME

public static final String ATTR_NAME
xml attribute

See Also:
Constant Field Values

TAG_GROUNDOVERLAY

public static final String TAG_GROUNDOVERLAY
kml tag id

See Also:
Constant Field Values

TAG_PHOTOOVERLAY

public static final String TAG_PHOTOOVERLAY
kml tag

See Also:
Constant Field Values

TAG_URL

public static final String TAG_URL
xml tag

See Also:
Constant Field Values

TAG_HREF

public static final String TAG_HREF
xml tag

See Also:
Constant Field Values

TAG_LINK

public static final String TAG_LINK
xml tag

See Also:
Constant Field Values

TAG_LINESTRING

public static final String TAG_LINESTRING
See Also:
Constant Field Values

TAG_SCHEMA

public static final String TAG_SCHEMA
xml tag

See Also:
Constant Field Values

TAG_NETWORKLINK

public static final String TAG_NETWORKLINK
kml tag id

See Also:
Constant Field Values

TAG_MULTIGEOMETRY

public static final String TAG_MULTIGEOMETRY
kml tag id

See Also:
Constant Field Values

TAG_DOCUMENT

public static final String TAG_DOCUMENT
kml tag id

See Also:
Constant Field Values

TAG_FOLDER

public static final String TAG_FOLDER
kml tag id

See Also:
Constant Field Values

TAG_KML

public static final String TAG_KML
xml tag

See Also:
Constant Field Values

TAG_PLACEMARK

public static final String TAG_PLACEMARK
kml tag id

See Also:
Constant Field Values

TAG_NAME

public static final String TAG_NAME
kml tag id

See Also:
Constant Field Values

cachedData

protected List cachedData
A local cache


cachedUrls

protected List cachedUrls
The urls

Constructor Detail

KmlDataSource

public KmlDataSource()
Dummy constructor so this object can get unpersisted.


KmlDataSource

public KmlDataSource(DataSourceDescriptor descriptor,
                     String kmlUrl,
                     Hashtable properties)
              throws VisADException
Create a KmlDataSource from the specification given.

Parameters:
descriptor - descriptor for the data source
kmlUrl - Where the kml came from
properties - extra properties
Throws:
VisADException - some problem occurred creating data
Method Detail

reloadData

public void reloadData()
reload

Specified by:
reloadData in interface DataSource
Overrides:
reloadData in class FilesDataSource

initAfterUnpersistence

public void initAfterUnpersistence()
Initialize after we have been unpersisted

Specified by:
initAfterUnpersistence in interface DataSource
Overrides:
initAfterUnpersistence in class FilesDataSource

readImage

protected Image readImage(String url,
                          String baseUrl)
Read the image

Parameters:
url - image url
baseUrl - Where the kml came from_
Returns:
The image

readBytes

protected byte[] readBytes(String path)
                    throws Exception
Utility to read the bytes from the file or url

Parameters:
path - file or url
Returns:
bytes
Throws:
Exception - On badness

getInputStream

protected InputStream getInputStream(String path)
                              throws Exception
Create the input stream. Handle the case when it is a zip file

Parameters:
path - file or url
Returns:
input stream to kml file
Throws:
Exception - On badness

doMakeDataChoices

protected void doMakeDataChoices()
Create the data choices associated with this source.

Overrides:
doMakeDataChoices in class DataSourceImpl

expandIfNeeded

public void expandIfNeeded(CompositeDataChoice parent)
Expand the data choice if its a networklink

Specified by:
expandIfNeeded in interface DataSource
Overrides:
expandIfNeeded in class DataSourceImpl
Parameters:
parent - data choice

getDataInner

protected Data getDataInner(DataChoice dataChoice,
                            DataCategory category,
                            DataSelection dataSelection,
                            Hashtable requestProperties)
                     throws VisADException,
                            RemoteException
Actually get the data identified by the given DataChoce. The default is to call the getDataInner that does not take the requestProperties. This allows other, non unidata.data DataSource-s (that follow the old API) to work.

Overrides:
getDataInner in class DataSourceImpl
Parameters:
dataChoice - The data choice that identifies the requested data.
category - The data category of the request.
dataSelection - Identifies any subsetting of the data.
requestProperties - Hashtable that holds any detailed request properties.
Returns:
The visad.Data object
Throws:
RemoteException - Java RMI problem
VisADException - VisAD problem

shouldCache

protected boolean shouldCache(Data data)
See if this DataSource should cache or not

Overrides:
shouldCache in class DataSourceImpl
Parameters:
data - Data to cache
Returns:
false

doMakeDateTimes

protected List doMakeDateTimes()
Create a list of times for this data source. Since shapefiles don't have any times, return an empty List.

Overrides:
doMakeDateTimes in class DataSourceImpl
Returns:
an empty List

setKmlUrl

public void setKmlUrl(String value)
Set the KmlUrl property.

Parameters:
value - The new value for KmlUrl

isKmlFile

public static boolean isKmlFile(String filename)
Is this a kml or kmz file

Parameters:
filename - file
Returns:
Is this a kml or kmz file

writeToFile

public static void writeToFile(String kmlFilename,
                               GeoLocationInfo bounds,
                               String imageFileName)
                        throws FileNotFoundException,
                               IOException
write image as a kml to file

Parameters:
kmlFilename - kml filename
bounds - _image bounds
imageFileName - image filename
Throws:
FileNotFoundException - On badness
IOException - On badness

createKml

public static String createKml(GeoLocationInfo bounds,
                               String imageFileName)
                        throws FileNotFoundException,
                               IOException
Create some kml from the given bounds and image file

Parameters:
bounds - bounds
imageFileName - image
Returns:
kml
Throws:
FileNotFoundException - On badness
IOException - On badness

createLatLonBox

public static void createLatLonBox(GeoLocationInfo bounds,
                                   StringBuffer sb)
Utility to create a latlonbox kml

Parameters:
bounds - bounds
sb - buffer to add to

main

public static void main(String[] args)
test main

Parameters:
args - cmd line args