Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSIP 126, PPIO factories, direction support, and OGR implementation #936

Merged
merged 2 commits into from Feb 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 57 additions & 0 deletions doc/en/user/source/extensions/ogr.rst
Expand Up @@ -155,3 +155,60 @@ The file showcases all possible usage of the configuration elements:
* ``singleFile`` (since 2.0.3): if true the output of the conversion is supposed to be a single file that can be streamed directly back without the need to wrap it into a zip file
* ``mimeType`` (since 2.0.3): the mime type of the file returned when using ``singleFile``. If not specified ``application/octet-stream`` will be used as a default.

OGR based WPS Output Format
===========================

The OGR based WPS output format provides the ability to turn feature collection (vector layer) output types into formats supported by OGR,
using the same configuration and same machinery provided by the OGR WFS output format (which should also be installed for the WPS portion to work).

Unlike the WFS case the WPS output formats are receiving different treatment in WPS responses depending on whether they are binary, text, or xml, when the Execute response
style chosen by the client is "document":

* Binary types need to be base64 encoded for XML embedding
* Text types need to be included inside a CDATA section
* XML types can be integrated in the response as-is

In order to understand the nature of the output format a new optional configuration element, ``<type>``, can
be added to the ``ogr2ogr.xml`` configuration file in order to specify the output nature.
The possible values are ``binary``, ``text``, ``xml``, in case the value is missing, ``binary`` is assumed.
Here is an example showing all possible combinations:

.. code-block:: xml

<OgrConfiguration>
<ogr2ogrLocation>ogr2ogr</ogr2ogrLocation>
<!-- <gdalData>...</gdalData> -->
<formats>
<Format>
<ogrFormat>MapInfo File</ogrFormat>
<formatName>OGR-TAB</formatName>
<fileExtension>.tab</fileExtension>
<type>binary</type> <!-- not really required, it’s the default -->
</Format>
<Format>
<ogrFormat>MapInfo File</ogrFormat>
<formatName>OGR-MIF</formatName>
<fileExtension>.mif</fileExtension>
<option>-dsco</option>
<option>FORMAT=MIF</option>
</Format>
<Format>
<ogrFormat>CSV</ogrFormat>
<formatName>OGR-CSV</formatName>
<fileExtension>.csv</fileExtension>
<singleFile>true</singleFile>
<mimeType>text/csv</mimeType>
<option>-lco</option>
<option>GEOMETRY=AS_WKT</option>
<type>text</type>
</Format>
<Format>
<ogrFormat>KML</ogrFormat>
<formatName>OGR-KML</formatName>
<fileExtension>.kml</fileExtension>
<singleFile>true</singleFile>
<mimeType>application/vnd.google-earth.kml</mimeType>
<type>xml</type>
</Format>
</formats>
</OgrConfiguration>
51 changes: 51 additions & 0 deletions src/extension/ogr/ogr-wfs/pom.xml
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright (C) 2014- 2015 Open Source Geospatial Foundation. All rights reserved.
This code is licensed under the GPL 2.0 license, available at the root
application directory.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.geoserver.extension</groupId>
<artifactId>gs-ogr</artifactId>
<version>2.8-SNAPSHOT</version>
</parent>

<groupId>org.geoserver.extension</groupId>
<artifactId>gs-ogr-wfs</artifactId>
<packaging>jar</packaging>
<name>OGR WFS</name>

<dependencies>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-wfs</artifactId>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-main</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-ows</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.mockrunner</groupId>
<artifactId>mockrunner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
@@ -1,20 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2014 - Open Source Geospatial Foundation. All rights reserved.
This code is licensed under the GPL 2.0 license, available at the root
application directory.
-->
<!-- Copyright (C) 2014 - 2015 Open Source Geospatial Foundation. All rights
reserved. This code is licensed under the GPL 2.0 license, available at the
root application directory. -->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<bean id="ogr2ogrOutputFormat" class="org.geoserver.wfs.response.Ogr2OgrOutputFormat">
<constructor-arg ref="geoServer"/>
<constructor-arg ref="geoServer" />
</bean>
<bean id="ogr2ogrConfigurator" class="org.geoserver.wfs.response.Ogr2OgrConfigurator">
<constructor-arg>
<ref local="ogr2ogrOutputFormat"/>
<ref local="ogr2ogrOutputFormat" />
</constructor-arg>
</bean>

</beans>
Expand Up @@ -24,20 +24,20 @@

/**
* Loads the ogr2ogr.xml configuration file and configures the output format accordingly.
*
* <p>Also keeps tabs on the configuration file, reloading the file as needed.
*
* <p>Also keeps tabs on the configuration file, reloading the file as needed.
* @author Administrator
*
*/
public class Ogr2OgrConfigurator implements ApplicationListener<ContextClosedEvent> {
private static final Logger LOGGER = Logging.getLogger(Ogr2OgrConfigurator.class);

Ogr2OgrOutputFormat of;
public Ogr2OgrOutputFormat of;

OGRWrapper wrapper;

Resource configFile;

// ConfigurationPoller
private ResourceListener listener = new ResourceListener() {
public void changed(ResourceNotification notify) {
Expand All @@ -47,13 +47,14 @@ public void changed(ResourceNotification notify) {

public Ogr2OgrConfigurator(Ogr2OgrOutputFormat format) {
this.of = format;

GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class);
configFile = loader.get("ogr2ogr.xml");
loadConfiguration();
configFile.addListener( listener );
}

protected void loadConfiguration() {
public void loadConfiguration() {
// start with the default configuration, override if we can load the file
OgrConfiguration configuration = OgrConfiguration.DEFAULT;
try {
Expand Down
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand All @@ -10,6 +10,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -135,20 +136,21 @@ public void setGdalData(String gdalData) {
public String getMimeType(Object value, Operation operation) throws ServiceException {
GetFeatureRequest request = GetFeatureRequest.adapt(operation.getParameters()[0]);
String outputFormat = request.getOutputFormat();

String mimeType = "";
OgrFormat format = formats.get(outputFormat);
if (format == null) {
throw new WFSException("Unknown output format " + outputFormat);
} else if (format.singleFile && request.getQueries().size() <= 1) {
if(format.mimeType != null) {
return format.mimeType;
if (format.mimeType != null) {
mimeType = format.mimeType;
} else {
// use a default binary blob
return "application/octet-stream";
mimeType = "application/octet-stream";
}
} else {
return "application/zip";
mimeType = "application/zip";
}
return mimeType;
}

@Override
Expand Down Expand Up @@ -192,6 +194,15 @@ public void addFormat(OgrFormat parameters) {
formats.put(parameters.formatName, parameters);
}

/**
* Get a list of supported ogr format
*
* @return
*/
public List<OgrFormat> getFormats() {
return new ArrayList<OgrFormat>(formats.values());
}

/**
* Programmatically removes all formats
*
Expand Down
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand All @@ -9,11 +9,11 @@

/**
* Represents the ogr2ogr output format configuration as a whole.
* Only used for XStream driven de-serialization
* Only used for XStream driven de-serialization
* @author Andrea Aime - OpenGeo

*/
class OgrConfiguration {
public class OgrConfiguration {
public static final OgrConfiguration DEFAULT;
static {
DEFAULT = new OgrConfiguration();
Expand All @@ -23,15 +23,15 @@ class OgrConfiguration {
DEFAULT.formats = new OgrFormat[] {
new OgrFormat("MapInfo File", "OGR-TAB", ".tab", false, null),
new OgrFormat("MapInfo File", "OGR-MIF", ".mif", false, null, "-dsco", "FORMAT=MIF"),
new OgrFormat("CSV", "OGR-CSV", ".csv", true, "text/csv"),
new OgrFormat("KML", "OGR-KML", ".kml", true, "application/vnd.google-earth.kml"),
new OgrFormat("CSV", "OGR-CSV", ".csv", true, "text/csv", OgrType.TEXT),
new OgrFormat("KML", "OGR-KML", ".kml", true, "application/vnd.google-earth.kml", OgrType.XML),
};
}
String ogr2ogrLocation;
String gdalData;
OgrFormat[] formats;

public String ogr2ogrLocation;
public String gdalData;
public OgrFormat[] formats;

public static void main(String[] args) {
// generates the default configuration xml and prints it to the output
XStream xstream = Ogr2OgrConfigurator.buildXStream();
Expand Down
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand All @@ -10,8 +10,9 @@
import java.util.List;

/**
* Parameters defining an output format generated using ogr2ogr from
* either a GML dump
* Parameters defining an output format generated using ogr2ogr from either a GML or a shapefile
* dump
*
* @author Andrea Aime - OpenGeo
*
*/
Expand All @@ -20,44 +21,56 @@ public class OgrFormat {
* The -f parameter
*/
public String ogrFormat;

/**
* The GeoServer output format name
*/
public String formatName;

/**
* The extension of the generated file, if any (shall include a dot, example, ".tab")
*/
public String fileExtension;

/**
* The options that will be added to the command line
*/
public List<String> options;


/**
* The type of format, used to instantiate the correct converter
*/
public OgrType type;

/**
* If the output is a single file that can be streamed back. In that case we also need
* to know the mime type
* If the output is a single file that can be streamed back. In that case we also need to know the mime type
*/
public boolean singleFile;

/**
* The mime type of the single file output
*/
public String mimeType;

public OgrFormat(String ogrFormat, String formatName, String fileExtension, boolean singleFile,
String mimeType, String... options) {
public OgrFormat(String ogrFormat, String formatName, String fileExtension, boolean singleFile,
String mimeType, OgrType type, String... options) {
this.ogrFormat = ogrFormat;
this.formatName = formatName;
this.fileExtension = fileExtension;
this.singleFile = singleFile;
this.mimeType = mimeType;
if(options != null) {
this.type = type;
if (options != null) {
this.options = new ArrayList<String>(Arrays.asList(options));
}
if (type == null) {
this.type = OgrType.BINARY;
}
}

public OgrFormat(String ogrFormat, String formatName, String fileExtension, boolean singleFile,
String mimeType, String... options) {
this(ogrFormat, formatName, fileExtension, singleFile, mimeType, OgrType.BINARY, options);
}


}
@@ -0,0 +1,15 @@
/* (c) 2015 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/

package org.geoserver.wfs.response;

/**
* Enumeration to mapping possible OGR types
*
*/

public enum OgrType {
BINARY, TEXT, XML;
}