/** * Static method to create an object from a factory, a configuration source, and an optional configuration parameter * list. * * @param factoryKey the key identifying the factory in {@link Configuration}. * @param configSource the configuration source. May be any of the types listed for {@link * #createFromConfigSource(object, SharpEarth.avlist.AVList)} * @param parameters key-value parameters to override or supplement the information provided in the specified * configuration source. May be null. * * @return a new instance of the requested object. * * @throws ArgumentException if the factory key is null, or if the configuration source is null or an empty * string. */ public static object create(string factoryKey, object configSource, AVList parameters) { if (factoryKey == null) { string message = Logging.getMessage("generic.FactoryKeyIsNull"); throw new ArgumentException(message); } if (WWUtil.isEmpty(configSource)) { string message = Logging.getMessage("generic.ConfigurationSourceIsInvalid", configSource); throw new ArgumentException(message); } Factory factory = (Factory)WorldWind.createConfigurationComponent(factoryKey); return(factory.createFromConfigSource(configSource, parameters)); }
protected void determineActiveAttributes() { super.determineActiveAttributes(); if (this.mustRefreshIcon()) { String path = this.getActiveAttributes().getImageAddress(); if (!WWUtil.isEmpty(path)) { // Evict the resource from the file store if there is a cached resource older than the icon update // time. This prevents fetching a stale resource out of the cache when the Icon is updated. bool highlighted = this.isHighlighted(); this.parent.getRoot().evictIfExpired(path, highlighted ? this.highlightIconRetrievalTime : this.iconRetrievalTime); this.textures.remove(path); } } }
protected bool doCanRead(Object source, AVList parameters) { if (WWUtil.isEmpty(source)) { return(false); } if (null == parameters) { File file = WWIO.getFileForLocalAddress(source); if (null == file) { return(false); } return(GDALUtils.canOpen(file)); } bool canOpen = false; GDALDataRaster raster = null; try { raster = new GDALDataRaster(source, true); // read data raster quietly parameters.setValues(raster.getMetadata()); canOpen = true; } catch (Throwable t) { // we purposely ignore any exception here, this should be a very quiet mode canOpen = false; } finally { if (null != raster) { raster.dispose(); raster = null; } } return(canOpen); }
/** * Creates an object from a general configuration source. The source can be one of the following: <ul> <li>{@link * java.net.URL}</li> <li>{@link java.io.File}</li> <li>{@link java.io.InputStream}</li> <li>{@link Element}</li> * <li>{@link SharpEarth.ogc.OGCCapabilities}</li> * <li>{@link SharpEarth.ogc.wcs.wcs100.WCS100Capabilities}</li> * <li>{@link string} holding a file name, a name of a resource on the classpath, or a string representation of a * URL</li></ul> * <p/> * * @param configSource the configuration source. See above for supported types. * @param parameters key-value parameters to override or supplement the information provided in the specified * configuration source. May be null. * * @return the new object. * * @throws ArgumentException if the configuration source is null or an empty string. * @throws WWUnrecognizedException if the source type is unrecognized. * @throws WWRuntimeException if object creation fails. The exception indicating the source of the failure is * included as the {@link Exception#initCause(Throwable)}. */ public object createFromConfigSource(object configSource, AVList parameters) { if (WWUtil.isEmpty(configSource)) { string message = Logging.getMessage("generic.ConfigurationSourceIsInvalid", configSource); Logging.logger().severe(message); throw new ArgumentException(message); } object o = null; try { if (configSource is Element) { o = this.doCreateFromElement((Element)configSource, parameters); } else if (configSource is OGCCapabilities) { o = this.doCreateFromCapabilities((OGCCapabilities)configSource, parameters); } else if (configSource is WCS100Capabilities) { o = this.doCreateFromCapabilities((WCS100Capabilities)configSource, parameters); } else { Document doc = WWXML.openDocument(configSource); if (doc != null) { o = this.doCreateFromElement(doc.getDocumentElement(), parameters); } } } catch (Exception e) { string msg = Logging.getMessage("generic.CreationFromConfigurationFileFailed", configSource); throw new WWRuntimeException(msg, e); } return(o); }
/** * Build the resource map from the KML Model's <i>ResourceMap</i> element. * * @param model Model from which to create the resource map. * * @return Map that relates relative paths in the COLLADA document to paths relative to the KML document. */ protected Map <String, String> createResourceMap(KMLModel model) { Map <String, String> map = new HashMap <String, String>(); KMLResourceMap resourceMap = model.getResourceMap(); if (resourceMap == null) { return(Collections.emptyMap()); } foreach (KMLAlias alias in resourceMap.getAliases()) { if (alias != null && !WWUtil.isEmpty(alias.getSourceRef()) && !WWUtil.isEmpty(alias.getTargetHref())) { map.put(alias.getSourceRef(), alias.getTargetHref()); } } return(map.size() > 0 ? map : Collections.< String, String > emptyMap()); }
/** * Create shapes for a geometry. * * @param geomInstance Geometry for which to create shapes. * @param shapes List to collect the new shapes. */ protected void createShapesForGeometry(ColladaInstanceGeometry geomInstance, List <ColladaMeshShape> shapes) { ColladaGeometry geometry = geomInstance.get(); if (geometry == null) { return; } ColladaMesh mesh = geometry.getMesh(); if (mesh == null) { return; } ColladaBindMaterial bindMaterial = geomInstance.getBindMaterial(); ColladaRoot root = this.getRoot(); List <ColladaTriangles> triangles = mesh.getTriangles(); if (!WWUtil.isEmpty(triangles)) { ColladaMeshShape newShape = ColladaMeshShape.createTriangleMesh(triangles, bindMaterial); newShape.setDelegateOwner(root); shapes.add(newShape); } List <ColladaLines> lines = mesh.getLines(); if (!WWUtil.isEmpty(lines)) { ColladaMeshShape newShape = ColladaMeshShape.createLineMesh(lines, bindMaterial); newShape.setDelegateOwner(root); shapes.add(newShape); } }
/** * Create an object such as a layer or elevation model given a local OGC capabilities document containing named * layer descriptions. * * @param capsFileName the path to the capabilities file. The file must be either an absolute path or a relative * path available on the classpath. The file contents must be a valid OGC capabilities * document. * @param parameters a list of configuration properties. These properties override any specified in the * capabilities document. The list should contain the {@link AVKey#LAYER_NAMES} property for * services that define layer, indicating which named layers described in the capabilities * document to create. If this argumet is null or contains no layers, the first named layer is * used. * * @return the requested object. * * @throws ArgumentException if the file name is null or empty. * @throws IllegalStateException if the capabilites document contains no named layer definitions. * @throws WWRuntimeException if an error occurs while opening, reading or parsing the capabilities document. * The exception indicating the source of the failure is included as the {@link * Exception#initCause(Throwable)}. */ public object createFromCapabilities(string capsFileName, AVList parameters) { if (WWUtil.isEmpty(capsFileName)) { string message = Logging.getMessage("nullValue.FilePathIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } WMSCapabilities caps = new WMSCapabilities(capsFileName); try { caps.parse(); } catch (javax.xml.stream.XMLStreamException e) { string message = Logging.getMessage("generic.CannotParseCapabilities", capsFileName); Logging.logger().log(Level.SEVERE, message, e); throw new WWRuntimeException(message, e); } return(this.doCreateFromCapabilities(caps, parameters)); }
/** * Constructs a VPF Coverage from a specified VPF Library and coverage name. This initializes the Coverage's Feature * Class Schema table, the Feature Class Attribute table, the Character Value Description table, the Integer Value * Descrption table, and the Symbol Related Attribute table. * * @param library the Library which the Coverage resides in. * @param name the Coverage's name. * * @return a new Coverage from the specified Library with the specified name. * * @throws ArgumentException if the library is null, or if the name is null or empty. */ public static VPFCoverage fromFile(VPFLibrary library, String name) { if (library == null) { String message = Logging.getMessage("nullValue.LibraryIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (WWUtil.isEmpty(name)) { String message = Logging.getMessage("nullValue.NameIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } File file = new File(library.getFilePath(), name); if (!file.exists()) { String message = Logging.getMessage("generic.FileNotFound", file.getPath()); Logging.logger().severe(message); throw new WWRuntimeException(message); } // Coverage tables. VPFBufferedRecordData fcs = VPFUtils.readTable(new File(file, VPFConstants.FEATURE_CLASS_SCHEMA_TABLE)); if (fcs == null) { String message = Logging.getMessage("VPF.FeatureClassSchemaTableMissing"); throw new WWRuntimeException(message); } VPFBufferedRecordData fca = VPFUtils.readTable( new File(file, VPFConstants.FEATURE_CLASS_ATTRIBUTE_TABLE)); VPFBufferedRecordData char_vdt = VPFUtils.readTable( new File(file, VPFConstants.CHARACTER_VALUE_DESCRIPTION_TABLE)); VPFBufferedRecordData int_vdt = VPFUtils.readTable( new File(file, VPFConstants.INTEGER_VALUE_DESCRIPTION_TABLE)); VPFBufferedRecordData symbol_rat = VPFUtils.readTable( new File(file, "symbol" + VPFConstants.RELATED_ATTRIBUTE_TABLE)); VPFCoverage coverage = new VPFCoverage(library); coverage.setFeatureClassSchemaTable(fcs); coverage.setFeatureClassAttributeTable(fca); coverage.setCharacterValueDescriptionTable(char_vdt); coverage.setIntegerValueDescriptionTable(int_vdt); coverage.setSymbolRelatedAttributeTable(symbol_rat); // Coverage metadata attributes. VPFRecord record = library.getCoverageAttributeTable().getRecord("coverage_name", name); if (record != null) { VPFUtils.checkAndSetValue(record, "coverage_name", AVKey.DISPLAY_NAME, coverage); VPFUtils.checkAndSetValue(record, "description", AVKey.DESCRIPTION, coverage); } return(coverage); }
/** * Create an instance. * * @param tc the current {@link KMLTraversalContext}. * @param placemark the <i>Placemark</i> element containing the <i>Point</i>. * @param geom the {@link KMLPoint} geometry. * * @throws NullPointerException if the geometry is null. * @throws ArgumentException if the parent placemark or the traversal context is null. */ public KMLPointPlacemarkImpl(KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom) { super(((KMLPoint)geom).getCoordinates()); if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (placemark == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } this.parent = placemark; KMLPoint point = (KMLPoint)geom; this.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); // KML default if (point.isExtrude()) { this.setLineEnabled(true); } String altMode = point.getAltitudeMode(); if (!WWUtil.isEmpty(altMode)) { if ("clampToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); } else if ("relativeToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); } else if ("absolute".Equals(altMode)) { this.setAltitudeMode(WorldWind.ABSOLUTE); } } if (this.parent.getVisibility() != null) { this.setVisible(this.parent.getVisibility()); } if (placemark.getName() != null) { this.setLabelText(placemark.getName()); this.setValue(AVKey.DISPLAY_NAME, placemark.getName()); } String description = placemark.getDescription(); if (description != null) { this.setValue(AVKey.DESCRIPTION, description); } if (placemark.getSnippetText() != null) { this.setValue(AVKey.SHORT_DESCRIPTION, placemark.getSnippetText()); } this.setValue(AVKey.CONTEXT, this.parent); }
/** * Create an instance. * * @param tc the current {@link KMLTraversalContext}. * @param overlay the {@link SharpEarth.ogc.kml.KMLGroundOverlay} to render as a polygon. * * @throws NullPointerException if the geomtry is null. * @throws ArgumentException if the parent placemark or the traversal context is null. */ public KMLGroundOverlayPolygonImpl(KMLTraversalContext tc, KMLGroundOverlay overlay) { if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (overlay == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } this.parent = overlay; String altMode = overlay.getAltitudeMode(); if (!WWUtil.isEmpty(altMode)) { if ("relativeToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); } else if ("absolute".Equals(altMode)) { this.setAltitudeMode(WorldWind.ABSOLUTE); } } // Positions are specified either as a kml:LatLonBox or a gx:LatLonQuad Position.PositionList corners = overlay.getPositions(); this.setOuterBoundary(corners.list); // Apply rotation if the overlay includes a LatLonBox KMLLatLonBox box = overlay.getLatLonBox(); if (box != null) { this.setRotation(box.getRotation()); } if (overlay.getName() != null) { this.setValue(AVKey.DISPLAY_NAME, overlay.getName()); } if (overlay.getDescription() != null) { this.setValue(AVKey.BALLOON_TEXT, overlay.getDescription()); } if (overlay.getSnippetText() != null) { this.setValue(AVKey.SHORT_DESCRIPTION, overlay.getSnippetText()); } // If no image is specified, draw a filled rectangle if (this.parent.getIcon() == null || this.parent.getIcon().getHref() == null) { String colorStr = overlay.getColor(); if (!WWUtil.isEmpty(colorStr)) { Color color = WWUtil.decodeColorABGR(colorStr); ShapeAttributes attributes = new BasicShapeAttributes(); attributes.setDrawInterior(true); attributes.setInteriorMaterial(new Material(color)); this.setAttributes(attributes); } } }
/** * Create an instance. * * @param tc the current {@link KMLTraversalContext}. * @param placemark the <i>Placemark</i> element containing the <i>LineString</i>. * @param geom the {@link KMLLineString} geometry. * * @throws NullPointerException if the geometry is null. * @throws ArgumentException if the parent placemark or the traversal context is null. */ public KMLLineStringPlacemarkImpl(KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom) { super(((KMLLineString)geom).getCoordinates()); if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (placemark == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } this.parent = placemark; KMLLineString lineString = (KMLLineString)geom; if (lineString.isExtrude()) { this.setExtrude(true); } if (lineString.getTessellate() != null && lineString.getTessellate()) { this.setFollowTerrain(true); } this.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); // KML default String altMode = lineString.getAltitudeMode(); if (!WWUtil.isEmpty(altMode)) { if ("clampToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); } else if ("relativeToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); } else if ("absolute".Equals(altMode)) { this.setAltitudeMode(WorldWind.ABSOLUTE); } } // If the path is clamped to the ground and terrain conforming, draw as a great circle. Otherwise draw // as linear segments. if (this.getAltitudeMode() == WorldWind.CLAMP_TO_GROUND && this.isFollowTerrain()) { this.setPathType(AVKey.GREAT_CIRCLE); } else { this.setPathType(AVKey.LINEAR); } if (placemark.getName() != null) { this.setValue(AVKey.DISPLAY_NAME, placemark.getName()); } if (placemark.getDescription() != null) { this.setValue(AVKey.DESCRIPTION, placemark.getDescription()); } if (placemark.getSnippetText() != null) { this.setValue(AVKey.SHORT_DESCRIPTION, placemark.getSnippetText()); } this.setValue(AVKey.CONTEXT, this.parent); }
protected PointPlacemarkAttributes assemblePointAttributes(PointPlacemarkAttributes attrs, KMLIconStyle style) { KMLIcon icon = style.getIcon(); if (icon != null && icon.getHref() != null) { // The icon reference may be to a support file within a KMZ file, so check for that. If it's not, then just // let the normal PointPlacemark code resolve the reference. String href = icon.getHref(); String localAddress = null; try { localAddress = this.parent.getRoot().getSupportFilePath(href); } catch (IOException e) { String message = Logging.getMessage("generic.UnableToResolveReference", href); Logging.logger().warning(message); } attrs.setImageAddress((localAddress != null ? localAddress : href)); } // If the Icon element is present, but there is no href, draw a point instead of the default icon. else if (icon != null && WWUtil.isEmpty(icon.getHref())) { attrs.setUsePointAsDefaultImage(true); } // Assign the other attributes defined in the KML Feature element. if (style.getColor() != null) { attrs.setImageColor(WWUtil.decodeColorABGR(style.getColor())); } if (style.getColorMode() != null && "random".Equals(style.getColorMode())) { attrs.setImageColor(WWUtil.makeRandomColor(attrs.getImageColor())); } if (style.getScale() != null) { attrs.setScale(style.getScale()); } if (style.getHeading() != null) { attrs.setHeading(style.getHeading()); attrs.setHeadingReference(AVKey.RELATIVE_TO_GLOBE); // KML spec is not clear about this } if (style.getHotSpot() != null) { KMLVec2 hs = style.getHotSpot(); attrs.setImageOffset(new Offset(hs.getX(), hs.getY(), KMLUtil.kmlUnitsToWWUnits(hs.getXunits()), KMLUtil.kmlUnitsToWWUnits(hs.getYunits()))); } else { // By default, use the center of the image as the offset. attrs.setImageOffset(new Offset(0.5, 0.5, AVKey.FRACTION, AVKey.FRACTION)); } return(attrs); }
public String getContentType() { Object o = this.getValue(AVKey.IMAGE_FORMAT); return((WWUtil.isEmpty(o)) ? null : (String)o); }
/** * Create a layer described by an XML layer description. * * @param domElement the XML element describing the layer to create. * @param parameters any parameters to apply when creating the layer. * * @return a new layer * * @throws WWUnrecognizedException if the layer type or service type given in the describing element is * unrecognized. * @see #createTiledImageLayer(org.w3c.dom.Element, SharpEarth.avlist.AVList). */ protected Layer createFromLayerDocument(Element domElement, AVList parameters) { String className = WWXML.getText(domElement, "@className"); if (className != null && className.length() > 0) { Layer layer = (Layer)WorldWind.createComponent(className); String actuate = WWXML.getText(domElement, "@actuate"); layer.setEnabled(WWUtil.isEmpty(actuate) || actuate.Equals("onLoad")); WWXML.invokePropertySetters(layer, domElement); return(layer); } AVList props = WWXML.copyProperties(domElement, null); if (props != null) { // Copy parameters and add any properties for this layer to the copy if (params != null) { props.setValues(params); } parameters = props; } Layer layer; String href = WWXML.getText(domElement, "@href"); if (href != null && href.length() > 0) { Object o = this.createFromConfigSource(href, parameters); if (o == null) { return(null); } if (!(o is Layer)) { String msg = Logging.getMessage("LayerFactory.UnexpectedTypeForLayer", o.GetType().Name); throw new WWRuntimeException(msg); } layer = (Layer)o; } else { String layerType = WWXML.getText(domElement, "@layerType"); if (layerType != null && layerType.Equals("TiledImageLayer")) { layer = this.createTiledImageLayer(domElement, parameters); } else if (layerType != null && layerType.Equals("ShapefileLayer")) { layer = this.createShapefileLayer(domElement, parameters); } else { String msg = Logging.getMessage("generic.UnrecognizedLayerType", layerType); throw new WWUnrecognizedException(msg); } } if (layer != null) { String actuate = WWXML.getText(domElement, "@actuate"); layer.setEnabled(actuate != null && actuate.Equals("onLoad")); WWXML.invokePropertySetters(layer, domElement); } return(layer); }
public String getName() { Object o = this.getStringValue(AVKey.DISPLAY_NAME); return((WWUtil.isEmpty(o)) ? null : (String)o); }
/** * Reads XML document and extracts raster sources * * @param config Parsed configuration document. * * @return TRUE, if all raster sources are available, FALSE otherwise * */ protected bool readRasterSources(RasterServerConfiguration config) { long startTime = System.currentTimeMillis(); bool hasUnavailableRasterSources = false; int numSources = 0; Sector extent = null; try { List <RasterServerConfiguration.Source> sources = config.getSources(); if (sources == null || sources.size() == 0) { return(false); } numSources = sources.size(); foreach (RasterServerConfiguration.Source source in sources) { Thread.yield(); try { String rasterSourcePath = source.getPath(); if (WWUtil.isEmpty(rasterSourcePath)) { continue; } AVList rasterMetadata = new AVListImpl(); File rasterSourceFile = new File(rasterSourcePath); // normalize rasterSourcePath = rasterSourceFile.getAbsolutePath(); if (!rasterSourceFile.exists()) { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.FileDoesNotExists", rasterSourcePath); Logging.logger().warning(reason); continue; } if (!rasterSourceFile.canRead()) { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.FileNoReadPermission", rasterSourcePath); Logging.logger().warning(reason); continue; } DataRasterReader rasterReader = this.findDataRasterReader(rasterSourceFile, rasterMetadata); if (null == rasterReader) { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.UnknownFileFormatOrMatchingReaderNotFound", rasterSourcePath); Logging.logger().warning(reason); continue; } Sector sector = source.getSector(); if (null == sector) { rasterReader.readMetadata(rasterSourceFile, rasterMetadata); Object o = rasterMetadata.getValue(AVKey.SECTOR); sector = (o is Sector) ? (Sector)o : null; } else { rasterMetadata.setValue(AVKey.SECTOR, sector); } Object rasterPixelFormat = rasterMetadata.getValue(AVKey.PIXEL_FORMAT); String datasetPixelFormat = this.getDataSetPixelFormat(); if (!WWUtil.isEmpty(datasetPixelFormat)) { // verify all data rasters are the same type - we do not allow to mix elevations and imagery if (!datasetPixelFormat.Equals(rasterPixelFormat)) { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.UnexpectedRasterType", rasterSourcePath); Logging.logger().warning(reason); continue; } } else { if (AVKey.IMAGE.Equals(rasterPixelFormat) || AVKey.ELEVATION.Equals(rasterPixelFormat)) { this.setDataSetPixelFormat((String)rasterPixelFormat); } else { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.UnknownFileFormat", rasterSourcePath); Logging.logger().warning(reason); continue; } } if (null != sector) { extent = Sector.union(extent, sector); this.dataRasterList.add( new CachedDataRaster(rasterSourceFile, rasterMetadata, rasterReader, this.getCache()) ); } else { hasUnavailableRasterSources = true; String reason = Logging.getMessage("generic.NoSectorSpecified", rasterSourcePath); Logging.logger().warning(reason); } } catch (Throwable t) { String message = t.getMessage(); message = (WWUtil.isEmpty(message)) ? t.getCause().getMessage() : message; Logging.logger().log(java.util.logging.Level.WARNING, message, t); } } if (null != extent && extent.getDeltaLatDegrees() > 0d && extent.getDeltaLonDegrees() > 0d) { this.setValue(AVKey.SECTOR, extent); } } catch (Throwable t) { String message = t.getMessage(); message = (WWUtil.isEmpty(message)) ? t.getCause().getMessage() : message; Logging.logger().log(java.util.logging.Level.SEVERE, message, t); } finally { Logging.logger().finest(this.getStringValue(AVKey.DISPLAY_NAME) + ": " + numSources + " files in " + (System.currentTimeMillis() - startTime) + " milli-seconds"); } return(!hasUnavailableRasterSources); }
/** * Constructs a VPF Library from the specified VPF Database and library name. This initializes the Library Header * Table, the Coverage Attribute Table, and the Geographic Reference Table. * * @param database the Database which the Library resides in. * @param name the Library's name. * * @return a new Library from the specified Database with the specified name. * * @throws ArgumentException if the database is null, or if the name is null or empty. */ public static VPFLibrary fromFile(VPFDatabase database, String name) { if (database == null) { String message = Logging.getMessage("nullValue.DatabaseIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (WWUtil.isEmpty(name)) { String message = Logging.getMessage("nullValue.NameIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } File file = new File(database.getFilePath(), name); if (!file.exists()) { String message = Logging.getMessage("generic.FileNotFound", file.getPath()); Logging.logger().severe(message); throw new WWRuntimeException(message); } // Library tables. VPFBufferedRecordData lht = VPFUtils.readTable(new File(file, VPFConstants.LIBRARY_HEADER_TABLE)); if (lht == null) { String message = Logging.getMessage("VPF.LibraryHeaderTableMissing"); throw new WWRuntimeException(message); } VPFBufferedRecordData cat = VPFUtils.readTable(new File(file, VPFConstants.COVERAGE_ATTRIBUTE_TABLE)); if (cat == null) { String message = Logging.getMessage("VPF.CoverageAttributeTableMissing"); throw new WWRuntimeException(message); } VPFBufferedRecordData grt = VPFUtils.readTable(new File(file, VPFConstants.GEOGRAPHIC_REFERENCE_TABLE)); if (grt == null) { String message = Logging.getMessage("VPF.GeographicReferenceTableMissing"); throw new WWRuntimeException(message); } VPFLibrary library = new VPFLibrary(database); library.setLibraryHeaderTable(lht); library.setCoverageAttributeTable(cat); library.setGeographicReferenceTable(grt); // Library metadata attributes. VPFRecord record = database.getLibraryAttributeTable().getRecord("library_name", name); if (record != null) { library.bounds = VPFUtils.getExtent(record); } record = lht.getRecord(1); if (record != null) { VPFUtils.checkAndSetValue(record, "library_name", AVKey.DISPLAY_NAME, library); VPFUtils.checkAndSetValue(record, "description", AVKey.DESCRIPTION, library); } // Library Coverages. Collection <VPFCoverage> col = createCoverages(library, cat); if (col != null) { library.setCoverages(col); } // Library tiles. VPFCoverage cov = library.getCoverage(VPFConstants.TILE_REFERENCE_COVERAGE); if (cov != null) { VPFTile[] tiles = createTiles(cov); if (tiles != null) { library.setTiles(tiles); } else { String message = Logging.getMessage("VPF.NoTilesInTileReferenceCoverage"); Logging.logger().warning(message); } } // Coverage tiled attributes. foreach (VPFCoverage coverage in library.getCoverages()) { bool tiled = isCoverageTiled(library, coverage); coverage.setTiled(tiled); } return(library); }
/** * Copies this accessor's content to a buffer. This method begins writing data at the buffer's current position, and * continues until the accessor is out of data. * * @return Array of floats. May return null if the data source is not available. */ public float[] getFloats() { String source = this.getSource(); if (source == null) { return(null); } Object o = this.getRoot().resolveReference(source); if (o == null) { return(null); // Source not available } // TODO: COLLADA spec says source can be a non-COLLADA document (pg 5-5) if (!(o is ColladaFloatArray)) { return(null); } float[] floats = ((ColladaFloatArray)o).getFloats(); if (floats == null) { return(null); } // Skip values before the start offset int index = this.getOffset(); int strideSkip = 0; int stride = this.getStride(); if (stride > this.params.size()) { strideSkip = stride - this.params.size(); } float[] result = new float[this.size()]; int ri = 0; for (int i = 0; i < this.getCount() && index < floats.length; i++) { foreach (ColladaParam param in this.params) { if (index >= floats.length) { break; } // Parse the next value and add to the buffer. Skip unnamed parameters. // See COLLADA spec pg 5-5. if (!WWUtil.isEmpty(param.getName())) { result[ri++] = floats[index]; } index += 1; } // Skip elements up to the stride. index += strideSkip; } return(result); }
/** * Create an instance. * * @param tc the current {@link KMLTraversalContext}. * @param placemark the <i>Placemark</i> element containing the <i>LineString</i>. * @param geom the {@link SharpEarth.ogc.kml.KMLPolygon} geometry. * * @throws NullPointerException if the geometry is null. * @throws ArgumentException if the parent placemark or the traversal context is null. */ public KMLPolygonImpl(KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom) { if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (placemark == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } this.parent = placemark; KMLPolygon polygon = (KMLPolygon)geom; this.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); // KML default String altMode = polygon.getAltitudeMode(); if (!WWUtil.isEmpty(altMode)) { if ("relativeToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); } else if ("absolute".Equals(altMode)) { this.setAltitudeMode(WorldWind.ABSOLUTE); } } KMLLinearRing outerBoundary = polygon.getOuterBoundary(); if (outerBoundary != null) { Position.PositionList coords = outerBoundary.getCoordinates(); if (coords != null && coords.list != null) { this.setOuterBoundary(outerBoundary.getCoordinates().list); } } Iterable <? extends KMLLinearRing> innerBoundaries = polygon.getInnerBoundaries(); if (innerBoundaries != null) { foreach (KMLLinearRing ring in innerBoundaries) { Position.PositionList coords = ring.getCoordinates(); if (coords != null && coords.list != null) { this.addInnerBoundary(ring.getCoordinates().list); } } } if (placemark.getName() != null) { this.setValue(AVKey.DISPLAY_NAME, placemark.getName()); } if (placemark.getDescription() != null) { this.setValue(AVKey.DESCRIPTION, placemark.getDescription()); } if (placemark.getSnippetText() != null) { this.setValue(AVKey.SHORT_DESCRIPTION, placemark.getSnippetText()); } this.setValue(AVKey.CONTEXT, this.parent); }