[Geoserver-devel] Adding a new coverage from within a service

I'm sorry if this goes against etiquette, but I'm rather desperate so I need
to re-post this in it's own thread...

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/Adding-a-new-coverage-from-within-a-service-tf4797060.html#a13723559
Sent from the GeoServer - Dev mailing list archive at Nabble.com.

Hi Jon,

Sorry for not responding earlier. Unfortunately as I stated before this
is something that is not really supported, and the code i mapped out was
more just a place for you start, as opposed to being a recipe that is
known to work.

To figure out what is going on i would have to walk through the code in
a debugger. I suggest you do the same. And perhaps walk through the code
that executes when you add a coverage through the user interface, and
compare.

As for getting a HttpServletRequest, you said your class is a Response?
do you mean org.geoserver.ows.Response?

-Justin

Jon Britton wrote:

I'm sorry if this goes against etiquette, but I'm rather desperate so I need
to re-post this in it's own thread...

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

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

My class extends org.vfny.geoserver.Response

Justin Deoliveira-4 wrote:

Hi Jon,

Sorry for not responding earlier. Unfortunately as I stated before this
is something that is not really supported, and the code i mapped out was
more just a place for you start, as opposed to being a recipe that is
known to work.

To figure out what is going on i would have to walk through the code in
a debugger. I suggest you do the same. And perhaps walk through the code
that executes when you add a coverage through the user interface, and
compare.

As for getting a HttpServletRequest, you said your class is a Response?
do you mean org.geoserver.ows.Response?

-Justin

Jon Britton wrote:

I'm sorry if this goes against etiquette, but I'm rather desperate so I
need
to re-post this in it's own thread...

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

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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

--
View this message in context: http://www.nabble.com/Adding-a-new-coverage-from-within-a-service-tf4797060.html#a13766706
Sent from the GeoServer - Dev mailing list archive at Nabble.com.