Ok, so based on your original email you say you are doing an operation
on two coverages to create a third. And I assume this is happening in a
servlet? For the coverates you are working on I assume you have a
reference to two CoverageInfo objects?
CoverageInfo c1 = ...;
CoverageInfo c2 = ...;
//get at the data config
ServletContext ctx = getServletConfig().getServletContext();
DataConfig dataConfig = (DataConfig) ctx.getAttribute(
DataConfig.CONFIG_KEY );
//get at the data
Data data = (Data) ctx.getAttribute( Data.WEB_CONTAINER_KEY );
//create a new coverage store config object
CoverateStoreConfig coverageStore = new CoverateStoreConfig(
"newCoverage", "description" );
coverageStoreConfig.setType( "GeoTIFF" );
coverageStoreConfig.setURL( "C:\data\...\something.tif" );
dataConfig.addDataFormat( coverageStoreConfig );
CoverateStoreInfo coverateStoreInfo = new CoverateStoreInfo(
coverageStoreConfig.toDTO(), data);
//create a new coverage config object
Format format = coverageStoreInfo.getFormat();
AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader)
coverageStoreInfo.getReader();
if (reader == null) {
reader = (AbstractGridCoverage2DReader) ((AbstractGridFormat)
format).getReader(GeoserverDataDirectory.findDataFile(coverageStoreInfo.getUrl()));
}
CoverageConfig coverageConfig = new CoverageConfig(formatID, format,
reader, request);
//add the new coverage
dataConfig.addCoverage( "key", coverageConfig );
//save changes
data.load( dataConfig.toDTO() );
XMLConfigWriter.Store( data.toDTO(),
GeoServerDataDirecetory.getGeoserverDataDirectory());
Try that out. I have to admit I have never really tried this before and
the code above is just what would be my first attempt. Try it out, but
you will probably have to play around a bit to get it to work.
-Justin
Jon Britton wrote:
Thanks Justin,
I've had a look at the code and can't really see whats going on. I can see
it setting up a CoverageConfig object but can't really see what's its doing
with this.
How can this code be put to use inside my Response execute method?
Do I need to create a CoverageConfig and pass it to addCoverage in
DataConfig? If so, how do I actually tell the CoverageConfig where my
coverage is? Is this in the HttpServletRequest passed in to the
CoverageConfig?
Sorry about all the questions, I'm in a bit of a rush.
Thanks,
Jon.
Justin Deoliveira-4 wrote:
Hi Jon,
Yeah , the javadocs are useless. Which is why I said originally that
this is not really been setup properly as a formal API.
As for how to use this api. I suggest you look at the class
DataCoveragesNewAction. It is located in the web module in the
"org.vfny.geoserver.action.data" package.
In particular look at the execute method. This is the UI class that
executes when a new coverage is created. You should be able to adapt it
to your needs.
So check that out and let us know if you have any more questions. We
realize that these classes are poorly documented so are happy to answer
any questions about them.
-Justin
--
Justin Deoliveira
The Open Planning Project
http://topp.openplans.org