-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialize GeoJson with an optional BBOX element.
Introduces settings to turn on the serialization of a 'bbox' element for Feature and FeatureCollection objects.
- Loading branch information
Showing
9 changed files
with
147 additions
and
35 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
json/src/main/java/org/geolatte/geom/json/FeatureCollectionSerializer.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 @@ | ||
package org.geolatte.geom.json; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import org.geolatte.geom.Box; | ||
import org.geolatte.geom.Feature; | ||
import org.geolatte.geom.FeatureCollection; | ||
import org.geolatte.geom.Position; | ||
|
||
import java.io.IOException; | ||
|
||
public class FeatureCollectionSerializer<P extends Position, ID> extends JsonSerializer<FeatureCollection<P, ID>> { | ||
|
||
private final Settings settings; | ||
|
||
FeatureCollectionSerializer(Settings settings) { | ||
this.settings = settings; | ||
} | ||
|
||
@Override | ||
public void serialize(FeatureCollection<P, ID> featureColl, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { | ||
gen.writeStartObject(); | ||
gen.writeStringField("type", FeatureCollection.TYPE); | ||
Box<?> box = featureColl.getBbox(); | ||
if (box != null && !box.isEmpty() && settings.isSet(Setting.SERIALIZE_FEATURE_COLLECTION_BBOX)) { | ||
gen.writeFieldName("bbox"); | ||
gen.writeObject(featureColl.getBbox()); | ||
} | ||
gen.writeArrayFieldStart("features"); | ||
for (Feature<?, ?> f : featureColl.getFeatures()) { | ||
gen.writeObject(f); | ||
} | ||
gen.writeEndArray(); | ||
gen.writeEndObject(); | ||
|
||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
json/src/main/java/org/geolatte/geom/json/FeatureSerializer.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,39 @@ | ||
package org.geolatte.geom.json; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import org.geolatte.geom.Box; | ||
import org.geolatte.geom.Feature; | ||
import org.geolatte.geom.Position; | ||
|
||
import java.io.IOException; | ||
|
||
public class FeatureSerializer<P extends Position, ID> extends JsonSerializer<Feature<P, ID>> { | ||
|
||
private final Settings settings; | ||
|
||
public FeatureSerializer(Settings settings) { | ||
this.settings = settings; | ||
} | ||
|
||
@Override | ||
public void serialize(Feature<P, ID> feature, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { | ||
gen.writeStartObject(); | ||
gen.writeStringField("type", Feature.TYPE); | ||
if (feature.getId() != null) { | ||
gen.writeFieldName("id"); | ||
gen.writeObject(feature.getId()); | ||
} | ||
Box<?> box = feature.getBbox(); | ||
if (box != null && !box.isEmpty() && settings.isSet(Setting.SERIALIZE_FEATURE_BBOX)) { | ||
gen.writeFieldName("bbox"); | ||
gen.writeObject(box); | ||
} | ||
gen.writeFieldName("geometry"); | ||
gen.writeObject(feature.getGeometry()); | ||
gen.writeFieldName("properties"); | ||
gen.writeObject(feature.getProperties()); | ||
gen.writeEndObject(); | ||
} | ||
} |
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
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
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
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
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
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