Title: GridCoverage CRS differenant than MapContext

Hi again :)

So, using my edited version of ArcGridReader I now have a GridCoverage object with a UTM 10N CoordinateReferenceSystem that I'd like to be able to view from within a MapContext (using a StyledMapPane). Before, when I was using an incorrect CoordinateReferenceSystem I was able to display my GridCoverage object by following the Spearfish demo example, that is, by creating a style and adding the GridCoverage and Style as a layer to a MapContext object. Now, however, with the coordinate system set to UTM_10N when I view the map it is completely blank.

My first guess of what going on is that there's a problem with the fact that the map context is using one CRS (the DefaultGeographicCRS) and my GridCoverage is using another (the DefaultProjectedCRS), but that's just a guess. Also, I've tried setting the MapContext's areaOfInterest to the coordinates of my GridCoverage, but that didn't help.

I'm at a bit of loss on this one, so I'm going to go ahead and paste the relevant code below, as a jumping off point. Any suggestions or thoughts would be much appreciated.

Cheers,
Andrew

public void test(){
     GridCoverage gcDem = createGridCoverage("monterey.asc.gz");
        StyleBuilder sb = new StyleBuilder();
        ColorMap cm = getBathyColorMap(sb);
        RasterSymbolizer rsDem = sb.createRasterSymbolizer(cm, 1);
        Style demStyle = sb.createStyle(rsDem);

        // Build the map
        final MapContext map = new DefaultMapContext();
        map.addLayer(gcDem, demStyle);

        // Show the map
        final StyledMapPane mapPane = new StyledMapPane();
        DirectPosition lowerCorner = gcDem.getEnvelope().getLowerCorner();
        DirectPosition upperCorner = gcDem.getEnvelope().getUpperCorner();
        Coordinate lowerCoord = new Coordinate(lowerCorner.getCoordinates()[0], lowerCorner.getCoordinates()[1]);
        Coordinate upperCoord = new Coordinate(upperCorner.getCoordinates()[0], upperCorner.getCoordinates()[1]);
        Envelope envelope = new Envelope(lowerCoord, upperCoord);
        map.setAreaOfInterest(envelope, gcDem.getCoordinateReferenceSystem());       
        mapPane.setMapContext(map);
        mapPane.getRenderer().addLayer(new RenderedMapScale());
        JFrame frame = new JFrame();
        frame.setTitle("Test map");
        frame.setContentPane(mapPane.createScrollPane());
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setBounds(800, 200, 640, 480);
        frame.setVisible(true);
    }

    private GridCoverage createGridCoverage(String gridName)
        throws IOException {
        URL url = "">"/grids/" + gridName);
        if (url =""> null) {
            throw new FileNotFoundException("Could not find specified grid.");
        }
        GridCoverageExchange gce = new StreamGridCoverageExchange();
        GridCoverageReader reader = gce.getReader(url);
        Format format = reader.getFormat();

        // get the parameters and set them
        ParameterValueGroup paramDescriptor = format.getReadParameters();
        GeneralParameterDescriptor descriptor = paramDescriptor.getDescriptor();
        boolean isCompressed = gridName.endsWith("gz");
        paramDescriptor.parameter("Compressed").setValue(isCompressed);
        paramDescriptor.parameter("GRASS").setValue(false);
        format.getReadParameters().parameter("crs").setValue(getUtm10CRS());
        List paramList = paramDescriptor.values();
        GeneralParameterValue[] params = new GeneralParameterValue[paramList
            .size()];
        int i = 0;
        for (Iterator iter = paramList.iterator(); iter.hasNext(); i++) {
            Parameter param = (Parameter) iter.next();
            params[i] = param;
        }

        // read the grid
        GridCoverage gridCoverage = reader.read(params);
        return gridCoverage;
    }

    private CoordinateReferenceSystem getUtm10CRS() {
        String wkt = "PROJCS[\"UTM_Zone_10N\", " + "GEOGCS[\"WGS84\", "
            + "DATUM[\"WGS84\", "
            + "SPHEROID[\"WGS84\", 6378137.0, 298.257223563]], "
            + "PRIMEM[\"Greenwich\", 0.0], "
            + "UNIT[\"degree\",0.017453292519943295], "
            + "AXIS[\"Longitude\",EAST], " + "AXIS[\"Latitude\",NORTH]], "
            + "PROJECTION[\"Transverse_Mercator\"], "
            + "PARAMETER[\"semi_major\", 6378137.0], "
            + "PARAMETER[\"semi_minor\", 6356752.314245179], "
            + "PARAMETER[\"central_meridian\", -123.0], "
            + "PARAMETER[\"latitude_of_origin\", 0.0], "
            + "PARAMETER[\"scale_factor\", 0.9996], "
            + "PARAMETER[\"false_easting\", 500000.0], "
            // + "PARAMETER[\"false_easting\", 0.0], "
            + "PARAMETER[\"false_northing\", 0.0], " + "UNIT[\"metre\",1.0], "
            + "AXIS[\"x\",EAST], " + "AXIS[\"y\",NORTH]]";

        CRSFactory csFactory = FactoryFinder.getCRSFactory(null);

        CoordinateReferenceSystem utm10 = null;
        try {
            utm10 = csFactory.createFromWKT(wkt);
        } catch (FactoryException e) {
            e.printStackTrace();
            System.exit(-1);
        }
        return utm10;

    }

Reply via email to