Skip to content

Commit

Permalink
Structured grid coverage controller implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Mar 29, 2017
1 parent 0fb2427 commit 87dfd4e
Show file tree
Hide file tree
Showing 7 changed files with 444 additions and 55 deletions.
6 changes: 5 additions & 1 deletion src/restconfig-ng/pom.xml
Expand Up @@ -31,7 +31,11 @@
<artifactId>gs-wcs</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-geojson</artifactId>
<version>${gt.version}</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.geoserver</groupId>
Expand Down
@@ -0,0 +1,38 @@
/* (c) 2017 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.catalog.rest;

import java.io.IOException;

import org.geoserver.rest.converters.BaseMessageConverter;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotReadableException;

/**
* Base class for converters handling (wrapped) feature collections
*/
public abstract class FeatureCollectionConverter extends BaseMessageConverter {

@Override
public boolean canRead(Class clazz, MediaType mediaType) {
return false;
}

@Override
public Object read(Class clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
throw new UnsupportedOperationException();
}

SimpleFeatureCollection getFeatures(Object o) {
if(o instanceof FormatCollectionWrapper) {
return ((FormatCollectionWrapper) o).getCollection();
} else {
return (SimpleFeatureCollection) o;
}
}
}
@@ -0,0 +1,40 @@
/* (c) 2017 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.catalog.rest;

import org.geotools.data.simple.SimpleFeatureCollection;

/**
* Base class for collection wrappers used to decide the output format in the controller code
*/
public abstract class FormatCollectionWrapper {

SimpleFeatureCollection collection;

public FormatCollectionWrapper(SimpleFeatureCollection collection) {
this.collection = collection;
}

public SimpleFeatureCollection getCollection() {
return collection;
}

public static class XMLCollectionWrapper extends FormatCollectionWrapper {

public XMLCollectionWrapper(SimpleFeatureCollection collection) {
super(collection);
}

}

public static class JSONCollectionWrapper extends FormatCollectionWrapper {

public JSONCollectionWrapper(SimpleFeatureCollection collection) {
super(collection);
}

}

}
@@ -0,0 +1,45 @@
/* (c) 2017 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.catalog.rest;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.geoserver.catalog.rest.FormatCollectionWrapper.XMLCollectionWrapper;
import org.geotools.GML;
import org.geotools.GML.Version;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.stereotype.Component;

@Component
public class GMLFeatureCollectionConverter extends FeatureCollectionConverter {

@Override
public List getSupportedMediaTypes() {
return Arrays.asList(MediaType.APPLICATION_XML);
}

@Override
public void write(Object t, MediaType contentType, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
SimpleFeatureCollection features = getFeatures(t);
GML gml = new GML(Version.WFS1_0);
gml.setNamespace("gf", features.getSchema().getName().getNamespaceURI());
// gml.setFeatureBounding(false);
gml.encode(outputMessage.getBody(), features);
}

@Override
public boolean canWrite(Class clazz, MediaType mediaType) {
return (SimpleFeatureCollection.class.isAssignableFrom(clazz)
| XMLCollectionWrapper.class.isAssignableFrom(clazz))
&& getSupportedMediaTypes().contains(mediaType);
}

}
@@ -0,0 +1,45 @@
/* (c) 2017 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.catalog.rest;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.geoserver.catalog.rest.FormatCollectionWrapper.JSONCollectionWrapper;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.geojson.feature.FeatureJSON;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.stereotype.Component;

@Component
public class GeoJSONFeatureCollectionConverter extends FeatureCollectionConverter {

@Override
public List getSupportedMediaTypes() {
return Arrays.asList(MediaType.APPLICATION_JSON,
MediaType.valueOf(CatalogController.TEXT_JSON));
}

@Override
public void write(Object t, MediaType contentType, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
SimpleFeatureCollection features = getFeatures(t);
final FeatureJSON json = new FeatureJSON();
boolean geometryless = features.getSchema().getGeometryDescriptor() == null;
json.setEncodeFeatureCollectionBounds(!geometryless);
json.setEncodeFeatureCollectionCRS(!geometryless);
json.writeFeatureCollection(features, outputMessage.getBody());
}

@Override
public boolean canWrite(Class clazz, MediaType mediaType) {
return (SimpleFeatureCollection.class.isAssignableFrom(clazz) && getSupportedMediaTypes().contains(mediaType))
|| JSONCollectionWrapper.class.isAssignableFrom(clazz);
}

}

0 comments on commit 87dfd4e

Please sign in to comment.