[Featureserver] Support for serializing additional data types with vectorformats

Ajna Cackovic lists at arc-productions.com
Fri Jul 29 14:53:26 EDT 2011


I found that I needed obtain data in GeoJSON format of an unsupported
data type that was read in from Django. In SimpleJSON, there is a
function, default, that allows you to define serializers for
unsupported data types but this isn't present in vectorformat's
GeoJSON encoder. So that I could use the decoded Django data without
modification, I modified the GeoJSON encoder to accept this parameter
and pass it to json_dumps. Is there interest in including this code in
the SVN? I've included the diff below:

svn diff -r 2:3
Index: trunk/vectorformats/Formats/GeoJSON.py
===================================================================
--- trunk/vectorformats/Formats/GeoJSON.py	(revision 2)
+++ trunk/vectorformats/Formats/GeoJSON.py	(revision 3)
@@ -29,7 +29,7 @@
        return feature


-    def encode(self, features, to_string=True, **kwargs):
+    def encode(self, features, to_string=True, default=None, **kwargs):
        """
        Encode a list of features to a JSON object or string.

@@ -52,7 +52,7 @@
                      }

        if to_string:
-            result = json_dumps(result_data)
+            result = json_dumps(result_data, default=default)
        else:
            result = result_data
        return result


More information about the Featureserver mailing list