Revision: 5189
          http://sourceforge.net/p/jump-pilot/code/5189
Author:   edso
Date:     2016-11-15 11:31:49 +0000 (Tue, 15 Nov 2016)
Log Message:
-----------
refine handling when geom or props are NULL

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-15 10:02:05 UTC (rev 5188)
+++ core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONConstants.java     
2016-11-15 11:31:49 UTC (rev 5189)
@@ -10,9 +10,4 @@
 
   public static final String TYPE_FEATURE = "Feature";
   public static final String TYPE_FEATURECOLLECTION = "FeatureCollection";
-
-  // for performance reasons, prevent concatenating the same string
-  public static final String EMPTY_GEOMETRY = "\"" + GEOMETRY
-      + "\": {\"type\":\"GeometryCollection\",\"geometries\":[]}";
-  public static final String EMPTY_PROPERTIES = "\"" + PROPERTIES + "\" : 
null";
 }

Modified: 
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONFeatureCollectionWrapper.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONFeatureCollectionWrapper.java
      2016-11-15 10:02:05 UTC (rev 5188)
+++ 
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONFeatureCollectionWrapper.java
      2016-11-15 11:31:49 UTC (rev 5189)
@@ -166,8 +166,9 @@
           if (featureSchema.getAttributeType(key) == ATTRIBUTETYPE_NULL) {
             featureSchema.setAttributeType(key, type);
           }
-          // this column hosts mixed attrib types eg. String/Long, NULL values 
are allowed though
-          else if (type != ATTRIBUTETYPE_NULL){
+          // this column hosts mixed attrib types eg. String/Long, NULL values
+          // are allowed though
+          else if (type != ATTRIBUTETYPE_NULL) {
             columnsWithMixedValues.add(key);
           }
         }
@@ -215,7 +216,7 @@
    */
   public FeatureCollection getFeatureCollection() {
     // set type to String for mixed columns
-    for (String key : new LinkedList<String>(columnsWithMixedValues) ) {
+    for (String key : new LinkedList<String>(columnsWithMixedValues)) {
       featureSchema.setAttributeType(featureSchema.getAttributeIndex(key),
           AttributeType.STRING);
       columnsWithMixedValues.remove(key);
@@ -296,7 +297,7 @@
         Geometry geometry = (Geometry) value;
         if (geometry != null)
           geometryJson = new GeoJsonWriter().write(geometry);
-      } 
+      }
       // attrib to json
       else {
         // we do NOT save null values to minimize the file size
@@ -313,22 +314,18 @@
       }
     }
 
-    // the GeoJSON specs expect a geometry to be written, it might be empty 
though
-    if (geometryJson != null)
-      geometryJson = "\"" + GeoJSONConstants.GEOMETRY + "\": " + geometryJson;
-    else
-      geometryJson = GeoJSONConstants.EMPTY_GEOMETRY;
+    // the GeoJSON specs expect a geometry to be written, it might be null
+    geometryJson = "\"" + GeoJSONConstants.GEOMETRY + "\": " + geometryJson;
 
-    // the GeoJSON specs expect properties to be written, it might be null 
when empty
+    // wrap array list, null value stays plain
     if (propertiesJson != null)
-      propertiesJson = "\"" + GeoJSONConstants.PROPERTIES + "\": { "
-          + propertiesJson + " }";
-    else
-      propertiesJson = GeoJSONConstants.EMPTY_PROPERTIES;
+      propertiesJson = "{ " + propertiesJson + " }";
+    // the GeoJSON specs expect properties to be written, it might be null
+    propertiesJson = "\"" + GeoJSONConstants.PROPERTIES + "\": "
+        + propertiesJson;
 
     return "{ \"" + GeoJSONConstants.TYPE + "\": \""
-        + GeoJSONConstants.TYPE_FEATURE + "\""
-        + ", " + propertiesJson
-        + ", " + geometryJson;
+        + GeoJSONConstants.TYPE_FEATURE + "\"" + ", " + propertiesJson + ", "
+        + geometryJson + " }";
   }
 }


------------------------------------------------------------------------------
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to