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

Added support of GeoJSON #941

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions deegree-services/deegree-services-wfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
</dependency>
</dependencies>

</project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
import org.deegree.services.jaxb.wfs.DisabledResources;
import org.deegree.services.jaxb.wfs.FeatureTypeMetadata;
import org.deegree.services.jaxb.wfs.GMLFormat;
import org.deegree.services.jaxb.wfs.GeoJSONFormat;
import org.deegree.services.jaxb.wfs.IdentifierGenerationOptionType;
import org.deegree.services.jaxb.wfs.RequestType;
import org.deegree.services.metadata.MetadataUtils;
Expand All @@ -140,6 +141,7 @@
import org.deegree.services.ows.OWS110ExceptionReportSerializer;
import org.deegree.services.ows.PreOWSExceptionReportSerializer;
import org.deegree.services.wfs.format.Format;
import org.deegree.services.wfs.format.geojson.GeoJsonFormat;
import org.deegree.services.wfs.query.StoredQueryHandler;
import org.deegree.workspace.ResourceIdentifier;
import org.deegree.workspace.ResourceInitException;
Expand Down Expand Up @@ -578,6 +580,7 @@ private void initFormats( List<JAXBElement<? extends AbstractFormatType>> format
mimeTypeToFormat.put( "text/xml; subtype=\"gml/3.1.1\"", gml31 );
mimeTypeToFormat.put( "text/xml; subtype=\"gml/3.2.1\"", gml32 );
mimeTypeToFormat.put( "text/xml; subtype=\"gml/3.2.2\"", gml32 );
mimeTypeToFormat.put( "application/geo+json", new GeoJsonFormat( this ) );
} else {
LOG.debug( "Using customized format configuration." );
for ( JAXBElement<? extends AbstractFormatType> formatEl : formatList ) {
Expand All @@ -586,6 +589,9 @@ private void initFormats( List<JAXBElement<? extends AbstractFormatType>> format
Format format = null;
if ( formatDef instanceof GMLFormat ) {
format = new org.deegree.services.wfs.format.gml.GmlFormat( this, (GMLFormat) formatDef );
} else if (formatDef instanceof GeoJSONFormat ){
boolean allowOtherCrsThanWGS84 = ((GeoJSONFormat) formatDef).isAllowOtherCrsThanWGS84();
format = new GeoJsonFormat( this, allowOtherCrsThanWGS84 );
} else if ( formatDef instanceof CustomFormat ) {
CustomFormat cf = (CustomFormat) formatDef;
String className = cf.getJavaClass();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.deegree.services.wfs.format.geojson;

import java.io.Closeable;
import java.io.IOException;

import org.deegree.cs.exceptions.TransformationException;
import org.deegree.cs.exceptions.UnknownCRSException;
import org.deegree.feature.Feature;

/**
* Writer for GeoJSON documents.
*
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
*/
public interface GeoJsonFeatureWriter extends Closeable {

/**
* Starts a new FeatureCollection.
*
* To finish this FeatureCollection call endFeatureCollection
*
* @throws IOException
* if GeoJSON could no be written
*/
void startFeatureCollection()
throws IOException;

/**
*
* Ends the written FeatureCollection.
*
* Ensure that start FeatureCollection was called before.
*
* @throws IOException
* if GeoJSON could no be written
*/
void endFeatureCollection()
throws IOException;

/**
* Writes a new Feature into the FeatureCollection.
*
* @param feature
* the feature to write, never <code>null</code>
* @throws IOException
* if GeoJSON could no be written
* @throws TransformationException
* if a geometry to export cannot be transformed to CRS:84
* @throws UnknownCRSException
* if the CRS of the geometry is not supported
*/
void write( Feature feature )
throws IOException, TransformationException, UnknownCRSException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.deegree.services.wfs.format.geojson;

import static org.deegree.protocol.wfs.getfeature.ResultType.RESULTS;

import org.deegree.protocol.wfs.describefeaturetype.DescribeFeatureType;
import org.deegree.protocol.wfs.getfeature.GetFeature;
import org.deegree.protocol.wfs.getfeature.ResultType;
import org.deegree.protocol.wfs.getgmlobject.GetGmlObject;
import org.deegree.protocol.wfs.getpropertyvalue.GetPropertyValue;
import org.deegree.services.controller.utils.HttpResponseBuffer;
import org.deegree.services.wfs.WebFeatureService;
import org.deegree.services.wfs.format.Format;
import org.deegree.services.wfs.format.geojson.request.GeoJsonGetFeatureHandler;

/**
* {@link Format} implementation for GeoJSON (https://tools.ietf.org/html/rfc7946).
*
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
*/
public class GeoJsonFormat implements Format {

private final GeoJsonGetFeatureHandler geoJsonGetFeatureHandler;

private boolean allowOtherCrsThanWGS84;

/**
* Instantiate {@link GeoJsonFormat}
*
* @param webFeatureService
* the {@link WebFeatureService} using this format, never <code>null</code>
*/
public GeoJsonFormat( WebFeatureService webFeatureService ) {
this.geoJsonGetFeatureHandler = new GeoJsonGetFeatureHandler( webFeatureService );
}

/**
* Instantiate {@link GeoJsonFormat}
*
* @param webFeatureService
* the {@link WebFeatureService} using this format, never <code>null</code>
* @param allowOtherCrsThanWGS84
* <code>true</code> if the DefaultCRS of the WFS or the CRS of the GetFeature request should be used,
* otherwise <code>false</code> (default is WGS84 as specified in GeoJson)
*/
public GeoJsonFormat( WebFeatureService webFeatureService, boolean allowOtherCrsThanWGS84 ) {
this.geoJsonGetFeatureHandler = new GeoJsonGetFeatureHandler( webFeatureService );
this.allowOtherCrsThanWGS84 = allowOtherCrsThanWGS84;
}

@Override
public void destroy() {
// nothing to do
}

@Override
public void doGetFeature( GetFeature request, HttpResponseBuffer response )
throws Exception {

ResultType type = request.getPresentationParams().getResultType();
if ( type == RESULTS || type == null ) {
geoJsonGetFeatureHandler.doGetFeatureResults( request, response, allowOtherCrsThanWGS84 );
} else {
throw new UnsupportedOperationException( "GetFeature with RESULTTYPE=HITS for GeoJSON is not supported" );
}
}

@Override
public void doDescribeFeatureType( DescribeFeatureType request, HttpResponseBuffer response, boolean isSoap )
throws Exception {
throw new UnsupportedOperationException( "DescribeFeatureType for GeoJSON is not supported" );
}

@Override
public void doGetGmlObject( GetGmlObject request, HttpResponseBuffer response )
throws Exception {
throw new UnsupportedOperationException( "GetGmlObject for GeoJSON is not supported" );
}

@Override
public void doGetPropertyValue( GetPropertyValue getPropertyValue, HttpResponseBuffer response )
throws Exception {
throw new UnsupportedOperationException( "GetPropertyValue for GeoJSON is not supported" );
}

}
Loading