Revision: 5150
http://sourceforge.net/p/jump-pilot/code/5150
Author: edso
Date: 2016-11-04 14:52:27 +0000 (Fri, 04 Nov 2016)
Log Message:
-----------
optimize previous patch
add empty geometry write out although OJ actually does not allow null
geometries, just to be sure
Modified Paths:
--------------
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONConstants.java
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONFeatureCollectionWrapper.java
Modified:
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONConstants.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONConstants.java
2016-11-04 14:14:33 UTC (rev 5149)
+++ core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONConstants.java
2016-11-04 14:52:27 UTC (rev 5150)
@@ -10,4 +10,6 @@
public static final String TYPE_FEATURE = "Feature";
public static final String TYPE_FEATURECOLLECTION = "FeatureCollection";
+
+ public static final String EMPTY_GEOMETRY = "\"geometry\":
{\"type\":\"GeometryCollection\",\"geometries\":[]}";
}
Modified:
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONFeatureCollectionWrapper.java
===================================================================
---
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONFeatureCollectionWrapper.java
2016-11-04 14:14:33 UTC (rev 5149)
+++
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONFeatureCollectionWrapper.java
2016-11-04 14:52:27 UTC (rev 5150)
@@ -282,32 +282,41 @@
String name = schema.getAttributeName(i);
AttributeType type = schema.getAttributeType(i);
Object value = feature.getAttribute(i);
-
- // we do NOT save null values to minimize the file size
- if (value == null)
- continue;
- // Date objects should be saved quoted in String representation
- if (type.equals(AttributeType.DATE))
- value = String.valueOf(value);
-
+ // geometry to json
if (i == schema.getGeometryIndex()) {
Geometry geometry = (Geometry) value;
if (geometry != null)
geometryJson = new GeoJsonWriter().write(geometry);
- } else {
+ }
+ // attrib to json
+ else {
+ // we do NOT save null values to minimize the file size
+ if (value == null)
+ continue;
+
+ // Date objects should be saved quoted in String representation
+ if (type.equals(AttributeType.DATE))
+ value = String.valueOf(value);
+
String json = JSONObject.toString(name, value);
propertiesJson = propertiesJson != null ? propertiesJson + ", " + json
: json;
}
}
+ // the GeoJSON specs expect a geometry to be written, it might be empty
though
if (geometryJson != null)
- geometryJson = "\"geometry\": " + geometryJson;
+ geometryJson = "\"" + GeoJSONConstants.GEOMETRY + "\": " + geometryJson;
+ else
+ geometryJson = GeoJSONConstants.EMPTY_GEOMETRY;
+
if (propertiesJson != null)
- propertiesJson = "\"properties\": { " + propertiesJson + " }";
+ propertiesJson = "\"" + GeoJSONConstants.PROPERTIES + "\": { "
+ + propertiesJson + " }";
- return "{ \"type\": \"Feature\""
+ return "{ \"" + GeoJSONConstants.TYPE + "\": \""
+ + GeoJSONConstants.TYPE_FEATURE + "\""
+ (propertiesJson != null ? ", " + propertiesJson : "")
+ (geometryJson != null ? ", " + geometryJson : "") + " }";
}
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel