Package org.geoserver.catalog

Examples of org.geoserver.catalog.CoverageInfo


        // check coverages are legit
        List<String> badCoverageIds = new ArrayList<String>();

        for (String datasetId : (List<String>) dcs.getEoId()) {
            CoverageInfo layer = resourceCodec.getDatasetCoverage(datasetId);
            if (layer == null) {
                badCoverageIds.add(datasetId);
            }
        }
        if (!badCoverageIds.isEmpty()) {
View Full Code Here


            String coverageId = gc.getCoverageId();
            if(coverageId == null) {
                throw new WCS20Exception("Required parameter coverageId is missing",
                        WCS20Exception.WCS20ExceptionCode.MissingParameterValue, "coverageId");
            }
            CoverageInfo coverage = codec.getGranuleCoverage(coverageId);
            if(coverage != null) {
                // set the actual coverage name
                String actualCoverageId = NCNameResourceCodec.encode(coverage);
                gc.setCoverageId(actualCoverageId);
               
View Full Code Here

        LayerInfo layer = NCNameResourceCodec.getCoverage(catalog, coverageName);
        if (layer == null) {
            LOGGER.fine("Invalid dataset id " + datasetId + " does not match any published dataset");
            return null;
        }
        CoverageInfo ci = (CoverageInfo) layer.getResource();
        if (!isValidDataset(ci)) {
            LOGGER.fine("Invalid dataset id " + datasetId + " does not match any published dataset");
            return null;
        }
View Full Code Here

        if(li == null) {
            return null;
        }
       
        // is it a EO dataset?
        CoverageInfo ci = (CoverageInfo) li.getResource();
        if(isValidDataset(ci)) {
            return ci;
        } else {
            return null;
        }
View Full Code Here

                    .append(request).toString());
        }

        WCSInfo wcs = getServiceInfo();

        CoverageInfo meta = null;
        GridCoverage2D coverage = null;
        try {
            CodeType identifier = request.getIdentifier();
            if (identifier == null)
                throw new WcsException("Internal error, the coverage identifier must not be null",
                        InvalidParameterValue, "identifier");
            meta = catalog.getCoverageByName(identifier.getValue());
            if (meta == null) {
                throw new WcsException("No such coverage: " + request.getIdentifier().getValue());
            }

            // first let's run some sanity checks on the inputs
            checkDomainSubset(meta, request.getDomainSubset(), wcs);
            checkRangeSubset(meta, request.getRangeSubset());
            checkOutput(meta, request.getOutput());

            // grab the format, the reader using the default params
            final GridCoverage2DReader reader = (GridCoverage2DReader) meta.getGridCoverageReader(
                    null, WCSUtils.getReaderHints(wcs));

            // handle spatial domain subset, if needed
            final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope();
            final BoundingBoxType bbox = request.getDomainSubset().getBoundingBox();
            final CoordinateReferenceSystem nativeCRS = originalEnvelope
                    .getCoordinateReferenceSystem();
            final GeneralEnvelope requestedEnvelopeInNativeCRS;
            final GeneralEnvelope requestedEnvelope;
            if (bbox != null) {
                // first off, parse the envelope corners
                double[] lowerCorner = new double[bbox.getLowerCorner().size()];
                double[] upperCorner = new double[bbox.getUpperCorner().size()];
                for (int i = 0; i < lowerCorner.length; i++) {
                    lowerCorner[i] = (Double) bbox.getLowerCorner().get(i);
                    upperCorner[i] = (Double) bbox.getUpperCorner().get(i);
                }
                requestedEnvelope = new GeneralEnvelope(lowerCorner, upperCorner);
                // grab the native crs
                // if no crs has beens specified, the native one is assumed
                if (bbox.getCrs() == null) {
                    requestedEnvelope.setCoordinateReferenceSystem(nativeCRS);
                    requestedEnvelopeInNativeCRS = requestedEnvelope;
                } else {
                    // otherwise we need to transform
                    final CoordinateReferenceSystem bboxCRS = CRS.decode(bbox.getCrs());
                    requestedEnvelope.setCoordinateReferenceSystem(bboxCRS);
                    if (!CRS.equalsIgnoreMetadata(bboxCRS, nativeCRS)) {
                        CoordinateOperationFactory of = CRS.getCoordinateOperationFactory(true);
                        CoordinateOperation co = of.createOperation(bboxCRS, nativeCRS);
                        requestedEnvelopeInNativeCRS = CRS.transform(co, requestedEnvelope);
                    } else {
                        requestedEnvelopeInNativeCRS = new GeneralEnvelope(requestedEnvelope);
                    }
                }
            } else {
                requestedEnvelopeInNativeCRS = reader.getOriginalEnvelope();
                requestedEnvelope = requestedEnvelopeInNativeCRS;
            }

            final GridCrsType gridCRS = request.getOutput().getGridCRS();

            // Compute the crs that the final coverage will be served into
            final CoordinateReferenceSystem targetCRS;
            if (gridCRS == null) {
                targetCRS = reader.getOriginalEnvelope().getCoordinateReferenceSystem();
            } else {
                targetCRS = CRS.decode(gridCRS.getGridBaseCRS());
            }

            //
            // Raster destination size
            //
            int elevationLevels = 0;
            double[] elevations = null;

            // grab the grid to world transformation
            MathTransform gridToCRS = reader.getOriginalGridToWorld(PixelInCell.CELL_CENTER);

            //
            // TIME Values
            //
            final List<Date> timeValues = new LinkedList<Date>();

            TimeSequenceType temporalSubset = request.getDomainSubset().getTemporalSubset();

            if (temporalSubset != null && temporalSubset.getTimePosition() != null
                    && temporalSubset.getTimePosition().size() > 0) {
                for (Iterator it = temporalSubset.getTimePosition().iterator(); it.hasNext();) {
                    Date tp = (Date) it.next();
                    timeValues.add(tp);
                }
            } else if (temporalSubset != null && temporalSubset.getTimePeriod() != null
                    && temporalSubset.getTimePeriod().size() > 0) {
                for (Iterator it = temporalSubset.getTimePeriod().iterator(); it.hasNext();) {
                    TimePeriodType tp = (TimePeriodType) it.next();
                    Date beginning = (Date) tp.getBeginPosition();
                    Date ending = (Date) tp.getEndPosition();

                    timeValues.add(beginning);
                    timeValues.add(ending);
                }
            }

            // now we have enough info to read the coverage, grab the parameters
            // and add the grid geometry info
            final GeneralEnvelope intersectionEnvelopeInSourceCRS = new GeneralEnvelope(
                    requestedEnvelopeInNativeCRS);
            intersectionEnvelopeInSourceCRS.intersect(originalEnvelope);

            final GridGeometry2D requestedGridGeometry = new GridGeometry2D(
                    PixelInCell.CELL_CENTER, gridToCRS, intersectionEnvelopeInSourceCRS, null);

            final ParameterValueGroup readParametersDescriptor = reader.getFormat()
                    .getReadParameters();
            GeneralParameterValue[] readParameters = CoverageUtils.getParameters(
                    readParametersDescriptor, meta.getParameters());
            readParameters = (readParameters != null ? readParameters
                    : new GeneralParameterValue[0]);

            //
            // Setting coverage reading params.
            //
            final ParameterValue requestedGridGeometryParam = new DefaultParameterDescriptor(
                    AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
                    GeneralGridGeometry.class, null, requestedGridGeometry).createValue();

            /*
             * Test if the parameter "TIME" is present in the WMS request, and by the way in the reading parameters. If it is the case, one can adds
             * it to the request. If an exception is thrown, we have nothing to do.
             */
            final List<GeneralParameterDescriptor> parameterDescriptors = readParametersDescriptor
                    .getDescriptor().descriptors();
            ParameterValue time = null;
            boolean hasTime = timeValues.size() > 0;
            ParameterValue elevation = null;
            boolean hasElevation = elevations != null && !Double.isNaN(elevations[0]);

            if (hasElevation || hasTime) {
                for (GeneralParameterDescriptor pd : parameterDescriptors) {

                    final String code = pd.getName().getCode();

                    //
                    // TIME
                    //
                    if (code.equalsIgnoreCase("TIME")) {
                        time = (ParameterValue) pd.createValue();
                        time.setValue(timeValues);
                    }

                    //
                    // ELEVATION
                    //
                    if (code.equalsIgnoreCase("ELEVATION")) {
                        elevation = (ParameterValue) pd.createValue();
                        elevation.setValue(elevations[0]);
                    }

                    // leave?
                    if ((hasElevation && elevation != null && hasTime && time != null)
                            || !hasElevation && hasTime && time != null || hasElevation
                            && elevation != null && !hasTime)
                        break;
                }
            }
            //
            // add read parameters
            //
            int addedParams = 1 + (hasTime ? 1 : 0) + (hasElevation ? 1 : 0);
            // add to the list
            GeneralParameterValue[] readParametersClone = new GeneralParameterValue[readParameters.length
                    + addedParams--];
            System.arraycopy(readParameters, 0, readParametersClone, 0, readParameters.length);
            readParametersClone[readParameters.length + addedParams--] = requestedGridGeometryParam;
            if (hasTime)
                readParametersClone[readParameters.length + addedParams--] = time;
            if (hasElevation)
                readParametersClone[readParameters.length + addedParams--] = elevation;
            readParameters = readParametersClone;

            // Check we're not being requested to read too much data from input (first check,
            // guesses the grid size using the information contained in CoverageInfo)
            WCSUtils.checkInputLimits(wcs, meta, reader, requestedGridGeometry);

            //
            // Check if we have a filter among the params
            //
            Filter filter = WCSUtils.getRequestFilter();
            if (filter != null) {
                readParameters = CoverageUtils.mergeParameter(parameterDescriptors, readParameters,
                        filter, "FILTER", "Filter");
            }

            //
            // make sure we work in streaming mode
            //
            // work in streaming fashion when JAI is involved
            readParameters = WCSUtils.replaceParameter(readParameters, Boolean.FALSE,
                    AbstractGridFormat.USE_JAI_IMAGEREAD);

            //
            // perform Read ...
            //
            coverage = (GridCoverage2D) reader.read(readParameters);
            if ((coverage == null) || !(coverage instanceof GridCoverage2D)) {
                throw new IOException("The requested coverage could not be found.");
            }

            // now that we have read the coverage double check the input size
            WCSUtils.checkInputLimits(wcs, coverage);

            // some raster sources do not really read less data (arcgrid for example), we may need to crop
            if (!intersectionEnvelopeInSourceCRS.contains(coverage.getEnvelope2D(), true)) {
                coverage = WCSUtils.crop(coverage, intersectionEnvelopeInSourceCRS);
            }

            /**
             * Band Select (works on just one field)
             */
            GridCoverage2D bandSelectedCoverage = coverage;
            String interpolationType = null;
            if (request.getRangeSubset() != null) {
                if (request.getRangeSubset().getFieldSubset().size() > 1) {
                    throw new WcsException("Multi field coverages are not supported yet");
                }

                FieldSubsetType field = (FieldSubsetType) request.getRangeSubset().getFieldSubset()
                        .get(0);
                interpolationType = field.getInterpolationType();

                // handle axis subset
                if (field.getAxisSubset().size() > 1) {
                    throw new WcsException("Multi axis coverages are not supported yet");
                }
                if (field.getAxisSubset().size() == 1) {
                    // prepare a support structure to quickly get the band index
                    // of a
                    // key
                    List<CoverageDimensionInfo> dimensions = meta.getDimensions();
                    Map<String, Integer> dimensionMap = new HashMap<String, Integer>();
                    for (int i = 0; i < dimensions.size(); i++) {
                        String keyName = dimensions.get(i).getName().replace(' ', '_');
                        dimensionMap.put(keyName, i);
                    }
View Full Code Here

            CoverageStoreInfo store = cb.buildCoverageStore("dummy");
            store.setType(gridFormat().getName());
            cb.setStore(store);

            try {
                CoverageInfo coverage = cb.buildCoverage(reader, null);
                coverage.setStore(null);
                coverage.setNamespace(null);
                cb.setupBounds(coverage, reader);

                LayerInfo layer = cb.buildLayer((ResourceInfo)coverage);

                ImportTask task = new ImportTask(data);
View Full Code Here

                }
            }

            final int indexOf = layerID.indexOf(":");
           
            final CoverageInfo coverageInfo = geoserverCatalog.getCoverageByName(new NameImpl(
                    layerID.substring(0, indexOf), layerID.substring(indexOf + 1)));
            List<CoverageDimensionInfo> dimensions = coverageInfo.getDimensions();
            String unit = "";
            if (dimensions != null && !dimensions.isEmpty()) {
                CoverageDimensionInfo dimensionInfo = dimensions.get(0);
                unit = dimensionInfo.getUnit();
            }

            // Getting coverage to parse statistics
            final CoverageStoreInfo storeInfo = coverageInfo.getStore();
            final GridCoverage2DReader reader = (GridCoverage2DReader) geoserverCatalog
                    .getResourcePool().getGridCoverageReader(storeInfo, null);

            GeneralParameterValue[] parameters = parseReadParameters(coverageInfo, map, reader);
            coverage = (GridCoverage2D) reader.read(parameters);
View Full Code Here

            LegacyCoverageInfoReader cInfoReader = new LegacyCoverageInfoReader();
            try {
                cInfoReader.read(cInfoFile);
   
                CoverageInfo coverage = readCoverage(cInfoReader);
                if ( coverage == null ) {
                    continue;
                }
                catalog.add(coverage);
   
                // create a wms layer for the feature type
                LayerInfo layer = factory.createLayer();
                layer.setResource(coverage);
                layer.setName(coverage.getName());
                layer.setPath(cInfoReader.wmsPath());
                if ( layer.getPath() == null ) {
                    layer.setPath( "/" );
                }
                layer.setType(LayerInfo.Type.RASTER);
               
                String defaultStyleName = cInfoReader.defaultStyle();
                if ( defaultStyleName != null ) {
                    StyleInfo style = catalog.getStyleByName(defaultStyleName);
                    if ( style != null ) {
                        layer.setDefaultStyle(style);
                    }
                }
                List<String> styles = cInfoReader.styles();
                if(styles != null) {
                    for (String styleName : styles) {
                        StyleInfo style = catalog.getStyleByName(styleName);
                        if ( style != null ) {
                            layer.getStyles().add(style);
                        }
                    }
                }
                layer.setEnabled(coverage.isEnabled());
              
                catalog.add(layer);
            } catch(Exception e) {
                LOGGER.warning( "Error loading '" + coverageDirectory.getName() + "/info.xml', ignoring" );
                LOGGER.log( Level.INFO, "", e );
View Full Code Here

            LOGGER.info( "Ignoring coverage: '" + cInfoReader.parentDirectoryName()
                    + "', coverage store is disabled");
            return null;
        }
       
        CoverageInfo coverage = factory.createCoverage();
        coverage.setStore(coverageStore);
       
        coverage.setName(cInfoReader.name());
        coverage.setNativeName(cInfoReader.name());
        coverage.setTitle(cInfoReader.label());
        coverage.setDescription(cInfoReader.description());
        for (String kw : cInfoReader.keywords()) {
            coverage.getKeywords().add(new Keyword(kw));
        }

        Map<String,Object> envelope = cInfoReader.envelope();
        String userDefinedCrsIdentifier = (String)envelope.get( "srsName" );
        String nativeCrsWkt = (String)envelope.get("crs");

        coverage.setSRS(userDefinedCrsIdentifier);
        CoordinateReferenceSystem crs = CRS.parseWKT(nativeCrsWkt);
        coverage.setNativeCRS( crs );
       
        ReferencedEnvelope bounds = new ReferencedEnvelope(
            (Double) envelope.get( "x1" ), (Double) envelope.get( "x2" ),
            (Double) envelope.get( "y1" ), (Double) envelope.get( "y2" ),
            crs
        );
        coverage.setNativeBoundingBox(bounds);
       
        GeneralEnvelope boundsLatLon =
            CoverageStoreUtils.getWGS84LonLatEnvelope(new GeneralEnvelope( bounds ) );
        coverage.setLatLonBoundingBox(new ReferencedEnvelope( boundsLatLon ) );
       
        GeneralEnvelope gridEnvelope = new GeneralEnvelope( bounds );
        Map grid = cInfoReader.grid();
        if ( grid != null ) {
            int[] low = (int[]) grid.get( "low" );
            int[] high = (int[]) grid.get( "high" );
           
            GeneralGridEnvelope range = new GeneralGridEnvelope(low, high);
           
            Map<String,Double> tx = (Map<String, Double>) grid.get( "geoTransform" );
            if ( tx != null ) {
                double[] matrix = new double[3 * 3];
                matrix[0] = tx.get( "scaleX") != null ? tx.get( "scaleX") : matrix[0];
                matrix[1] = tx.get( "shearX") != null ? tx.get( "shearX") : matrix[1];
                matrix[2] = tx.get( "translateX") != null ? tx.get( "translateX") : matrix[2];
                matrix[3] = tx.get( "shearY") != null ? tx.get( "shearY") : matrix[3];
                matrix[4] = tx.get( "scaleY") != null ? tx.get( "scaleY") : matrix[4];
                matrix[5] = tx.get( "translateY") != null ? tx.get( "translateY") : matrix[5];
                matrix[8] = 1.0;
               
                MathTransform gridToCRS = new DefaultMathTransformFactory()
                    .createAffineTransform( new GeneralMatrix(3,3,matrix));
                coverage.setGrid( new GridGeometry2D(range,gridToCRS,crs) );
            }
            else {
                coverage.setGrid( new GridGeometry2D( range, gridEnvelope ) );
            }
        }
        else {
            // new grid range
            GeneralGridEnvelope range = new GeneralGridEnvelope(new int[] { 0,
                    0 }, new int[] { 1, 1 });
            coverage.setGrid( new GridGeometry2D(range, gridEnvelope) );
        }
       
        for ( Iterator x = cInfoReader.coverageDimensions().iterator(); x   .hasNext(); ) {
            Map map = (Map) x.next();
            CoverageDimensionInfo cd = factory.createCoverageDimension();
            cd.setName((String)map.get("name"));
            cd.setDescription((String)map.get("description"));
            cd.setRange(
               NumberRange.create( (Double)map.get("min"),(Double)map.get("max"))
            );
            coverage.getDimensions().add( cd );
        }
       
        coverage.setNativeFormat(cInfoReader.nativeFormat());
        coverage.getSupportedFormats().addAll(cInfoReader.supportedFormats());
       
        coverage.setDefaultInterpolationMethod(cInfoReader.defaultInterpolation());
        coverage.getInterpolationMethods().addAll( cInfoReader.supportedInterpolations());
       
        coverage.getRequestSRS().addAll(cInfoReader.requestCRSs());
        coverage.getResponseSRS().addAll(cInfoReader.responseCRSs());
       
        coverage.getMetadata().put( "dirName", cInfoReader.parentDirectoryName());
        coverage.setEnabled( coverageStore.isEnabled() );
       
        // parameters
        coverage.getParameters().putAll( cInfoReader.parameters() );
       
        // link to namespace
        String prefix = catalog.getCoverageStoreByName(coverageStoreName).getWorkspace().getName();
        coverage.setNamespace(catalog.getNamespaceByPrefix(prefix));
       
        return coverage;
    }
View Full Code Here

    LayerInfo layerInfo = catalog.getLayerByName(layer);
    if (layerInfo != null) {
      ResourceInfo obj = layerInfo.getResource();
      /* Check if it's feature type or coverage */
      if (obj instanceof CoverageInfo) {
        CoverageInfo cvInfo;
        cvInfo = (CoverageInfo) obj;
       
        StyleInfo defaultStyle = layerInfo.getDefaultStyle();
        RasterSymbolizer rasterSymbolizer = getRasterSymbolizer(defaultStyle);
       
View Full Code Here

TOP

Related Classes of org.geoserver.catalog.CoverageInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.