Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Structured grid coverage controller implementation
- Loading branch information
Showing
7 changed files
with
444 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/restconfig-ng/src/main/java/org/geoserver/catalog/rest/FeatureCollectionConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/restconfig-ng/src/main/java/org/geoserver/catalog/rest/FormatCollectionWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...restconfig-ng/src/main/java/org/geoserver/catalog/rest/GMLFeatureCollectionConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...config-ng/src/main/java/org/geoserver/catalog/rest/GeoJSONFeatureCollectionConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
Oops, something went wrong.