Skip to content

Commit

Permalink
[GEOS-6992] Add gdalwarp/gdal_translate/gdaladdo transformation suppo…
Browse files Browse the repository at this point in the history
…rt in importer
  • Loading branch information
aaime committed May 8, 2015
1 parent 05b3295 commit ee1b5ab
Show file tree
Hide file tree
Showing 28 changed files with 1,250 additions and 113 deletions.
67 changes: 66 additions & 1 deletion doc/en/user/source/extensions/importer/rest_examples.rst
Expand Up @@ -401,4 +401,69 @@ If all goes well the new layer is created in PostGIS and registered in GeoServer

In case the features in the CSV need to be appended to an existing layer a PUT request against the task might be performed, changing its
updateMode from "CREATE" to "APPEND". Changing it to "REPLACE" instead will preserve the layer, but remove the old conents and replace
them with the newly uploaded ones.
them with the newly uploaded ones.

Uploading and optimizing a GeoTiff with ground control points
-------------------------------------------------------------

A data supplier is periodically providing GeoTiffs that we need to configure in GeoServer.
The GeoTIFF is referenced via Ground Control Points, is organized by stripes, and has no overviews.
The objective is to rectify, optimize and publish it via the importer.

First, we are going to create a empty import with no store as the target::

curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @import.json "http://localhost:8080/geoserver/rest/imports"

Where import.json is::

{
"import": {
"targetWorkspace": {
"workspace": {
"name": "sf"
}
}
}
}

Then, we are going to POST the GeoTiff file to the tasks list, in order to create an import task for it::

curl -u admin:geoserver -F name=test -F filedata=@box_gcp_fixed.tif "http://localhost:8080/geoserver/rest/imports/0/tasks"
We are then going to append the transformations to rectify (gdalwarp), retile (gdal_translate) and add overviews (gdaladdo) to it:

curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @warp.json "http://localhost:8080/geoserver/rest/imports/0/tasks/0/transforms"
curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @gtx.json "http://localhost:8080/geoserver/rest/imports/0/tasks/0/transforms"
curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @gad.json "http://localhost:8080/geoserver/rest/imports/0/tasks/0/transforms"


``warp.json`` is::

{
"type": "GdalWarpTransform",
"options": [ "-t_srs", "EPSG:4326"]
}


``gtx.json`` is:

{
"type": "GdalTranslateTransform",
"options": [ "-co", "TILED=YES", "-co", "BLOCKXSIZE=512", "-co", "BLOCKYSIZE=512"]
}

``gad.json`` is::

{
"type": "GdalAddoTransform",
"options": [ "-r", "average"],
"levels" : [2, 4, 8, 16]
}

Now the import is ready to run, and we'll execute it using::

curl -u admin:geoserver -XPOST "http://localhost:8080/geoserver/rest/imports/0"

A new layer ``box_gcp_fixed`` layer will appear in GeoServer, with an underlying GeoTiff file ready
for web serving.
51 changes: 51 additions & 0 deletions doc/en/user/source/extensions/importer/rest_reference.rst
Expand Up @@ -910,3 +910,54 @@ Reprojects a vector layer from a source CRS to a target CRS
- N
- Identifier of the target coordinate reference system

GdalTranslateTransform
""""""""""""""""""""""

Applies ``gdal_translate`` to a single file raster input. Requires ``gdal_translate`` to be inside the PATH used by the web container running GeoServer.


.. list-table::
:header-rows: 1

* - Parameter
- Optional
- Description
* - options
- N
- Array of options that will be passed to ``gdal_translate`` (beside the input and output names, which are internally managed)

GdalWarpTransform
"""""""""""""""""

Applies ``gdalwarp`` to a single file raster input. Requires ``gdalwarp`` to be inside the PATH used by the web container running GeoServer.


.. list-table::
:header-rows: 1

* - Parameter
- Optional
- Description
* - options
- N
- Array of options that will be passed to ``gdalwarp`` (beside the input and output names, which are internally managed)

GdalAddoTransform
"""""""""""""""""

Applies ``gdaladdo`` to a single file raster input. Requires ``gdaladdo`` to be inside the PATH used by the web container running GeoServer.


.. list-table::
:header-rows: 1

* - Parameter
- Optional
- Description
* - options
- N
- Array of options that will be passed to ``gdaladdo`` (beside the input file name, which is internally managed)
* - levels
- N
- Array of integers with the overview levels that will be passed to ``gdaladdo``

4 changes: 4 additions & 0 deletions src/extension/importer/core/pom.xml
Expand Up @@ -51,6 +51,10 @@
<artifactId>javacsv</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-wkt</artifactId>
Expand Down
Expand Up @@ -26,8 +26,8 @@
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.FilenameUtils;
import org.geoserver.data.util.IOUtils;
import org.geotools.util.logging.Logging;
import org.geoserver.importer.job.ProgressMonitor;
import org.geotools.util.logging.Logging;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -135,17 +135,23 @@ public void prepare(ProgressMonitor m) throws IOException {
while(!q.isEmpty()) {
File dir = q.poll();

if (m.isCanceled()){
if (m.isCanceled()) {
return;
}
m.setTask("Scanning " + dir.getPath());

//get all the regular (non directory) files
Set<File> all = new LinkedHashSet<File>(Arrays.asList(dir.listFiles(new FilenameFilter() {
File[] fileList = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return !new File(dir, name).isDirectory();
}
})));
});
if (fileList == null) {
// it can be null in case of I/O error, even if the
// dir is indeed a directory
continue;
}
Set<File> all = new LinkedHashSet<File>(Arrays.asList(fileList));

//scan all the files looking for spatial ones
for (File f : dir.listFiles()) {
Expand Down
Expand Up @@ -816,17 +816,17 @@ void doDirectImport(ImportTask task) throws IOException {
task.setState(ImportTask.State.RUNNING);

try {
//set up transform chain
// set up transform chain
TransformChain tx = task.getTransform();

//apply pre transform
// apply pre transform
if (!doPreTransform(task, task.getData(), tx)) {
return;
}

addToCatalog(task);

//apply pre transform
// apply post transform
if (!doPostTransform(task, task.getData(), tx)) {
return;
}
Expand Down

0 comments on commit ee1b5ab

Please sign in to comment.