[Geoserver-devel] Creating a new coverage from inside a service

Hi,
I've created a basic service for carrying out an operation on two existing
coverages. The service then creates a new coverage showing the result. Is
it possible to add this new coverage to WMS/WCS?

Also, if I can get this working I would need to remove older results
automatically - how can I remove a coverage from inside the service code?
Thanks!
Jon.
--
View this message in context: http://www.nabble.com/Creating-a-new-coverage-from-inside-a-service-tf4730408.html#a13526190
Sent from the GeoServer - Dev mailing list archive at Nabble.com.

Hi Jon,

There is not really a good api (imho) for doing this, however, i suggest
you take the same approach that the user interface does when deleting a
coverage, or feature type, etc...

Grab a reference to the global "DataConfig" instance. It is available
from the servlet context:

DataConfig dataConfig =
(DataConfig)getServlet().getServletContext().getAttribute(DataConfig.CONFIG_KEY);

Or you can grab it directly from spring, from a bean called "dataConfig".

It contains api which allows you to add/remove coverages. However, you
are done at this point. You have to "reload" the catalog so to speak. To
do this you need to grab the global "Data" instance. Again from teh
servlet container or from spring. Once you have it:

Data data = ...;
data.load( dataConfig.toDTO() );

At this point your changes will have been picked up by GeoServer but not
committed to underlying persistence. Do that you can copy code from
"SaveXMLAction".

Hope that helps, fire away with any more questions.

-Justin

Jon Britton wrote:

Hi,
I've created a basic service for carrying out an operation on two existing
coverages. The service then creates a new coverage showing the result. Is
it possible to add this new coverage to WMS/WCS?

Also, if I can get this working I would need to remove older results
automatically - how can I remove a coverage from inside the service code?
Thanks!
Jon.

--
Justin Deoliveira
The Open Planning Project
http://topp.openplans.org

Thanks for the reply!
I assume the method I need in DataConfig is addCoverage(String key,
CoverageConfig cv). How would I actually use this method? The Javadocs are
pretty bare...
Sorry, I'm quite new to the ins and outs of GeoServer!
Thanks,
Jon

Continuum-3 wrote:

Hi Jon,

There is not really a good api (imho) for doing this, however, i suggest
you take the same approach that the user interface does when deleting a
coverage, or feature type, etc...

Grab a reference to the global "DataConfig" instance. It is available
from the servlet context:

DataConfig dataConfig =
(DataConfig)getServlet().getServletContext().getAttribute(DataConfig.CONFIG_KEY);

Or you can grab it directly from spring, from a bean called "dataConfig".

It contains api which allows you to add/remove coverages. However, you
are done at this point. You have to "reload" the catalog so to speak. To
do this you need to grab the global "Data" instance. Again from teh
servlet container or from spring. Once you have it:

Data data = ...;
data.load( dataConfig.toDTO() );

At this point your changes will have been picked up by GeoServer but not
committed to underlying persistence. Do that you can copy code from
"SaveXMLAction".

Hope that helps, fire away with any more questions.

-Justin
en Planning Project
http://topp.openplans.org

--
View this message in context: http://www.nabble.com/Creating-a-new-coverage-from-inside-a-service-tf4730408.html#a13532191
Sent from the GeoServer - Dev mailing list archive at Nabble.com.

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

Jon Britton wrote:

Thanks for the reply!
I assume the method I need in DataConfig is addCoverage(String key,
CoverageConfig cv). How would I actually use this method? The Javadocs are
pretty bare...
Sorry, I'm quite new to the ins and outs of GeoServer!
Thanks,
Jon

Continuum-3 wrote:

Hi Jon,

There is not really a good api (imho) for doing this, however, i suggest
you take the same approach that the user interface does when deleting a
coverage, or feature type, etc...

Grab a reference to the global "DataConfig" instance. It is available
from the servlet context:

DataConfig dataConfig =
(DataConfig)getServlet().getServletContext().getAttribute(DataConfig.CONFIG_KEY);

Or you can grab it directly from spring, from a bean called "dataConfig".

It contains api which allows you to add/remove coverages. However, you
are done at this point. You have to "reload" the catalog so to speak. To
do this you need to grab the global "Data" instance. Again from teh
servlet container or from spring. Once you have it:

Data data = ...;
data.load( dataConfig.toDTO() );

At this point your changes will have been picked up by GeoServer but not
committed to underlying persistence. Do that you can copy code from
"SaveXMLAction".

Hope that helps, fire away with any more questions.

-Justin
en Planning Project
http://topp.openplans.org

--
Justin Deoliveira
The Open Planning Project
http://topp.openplans.org

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

--
View this message in context: http://www.nabble.com/Creating-a-new-coverage-from-inside-a-service-tf4730408.html#a13545749
Sent from the GeoServer - Dev mailing list archive at Nabble.com.

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

Thanks!
I've tried this and I'm having a few problems:

What do I need to replace "newCoverage" and "description" with in this line

CoverateStoreConfig coverageStore = new
CoverateStoreConfig("newCoverage","description");

And, what HttpServletRequest object is needed in the following line:

CoverageConfig coverageConfig = new CoverageConfig(formatID, format, reader,
request);

I'm doing all of this in the execute method of my Response class and don't
have a HttpServletRequest...

Thanks again,
Jon

Justin Deoliveira-4 wrote:

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

--
View this message in context: http://www.nabble.com/Creating-a-new-coverage-from-inside-a-service-tf4730408.html#a13626755
Sent from the GeoServer - Dev mailing list archive at Nabble.com.