1
1
__author__ = 'matt'
2
2
__date__ = '11/24/13'
3
+ """
4
+ Constructors are classes that are designed to accept geometry/attribute data as input,
5
+ and convert to a serialized string, for POST'ing to Github using the Gist API.
6
+
7
+ Constructor classes rely on a duck typed interface. A stub class looks like the following:
8
+
9
+ class TopoJSONConstructor(object):
10
+ def __init__(self, records, geom_col='geometry'):
11
+ self.records = records
12
+ self.geom_col = geom_col
13
+
14
+ def encode(self):
15
+ raise NotImplementedError("TopoJSON Support Not Implemented In This Version.")
16
+
17
+ As seen above the required attributes for a constructor class are:
18
+ records - A list of dictionaries. Each dictionary represents a record to be serialized.
19
+ Dictionary key/values represent properties (tabular+geometry) for the record.
20
+ This attribute can be populated from any data source, but within the context
21
+ of this application, is the result of a call to psycopg2's fetchall() method.
22
+ geom_col - A string representing the key for the a record dictionary (contained in the
23
+ records list) that holds geometry information. Defaults to 'geometry'
24
+
25
+ An 'encode()' method is also required. This method should return a string representing the
26
+ serialized geometry with attributes.
27
+ """
3
28
4
29
import collections
5
30
import json
@@ -17,8 +42,6 @@ class GeoJSONConstructor(object):
17
42
records (LIST) - Each element is a dictionary representing
18
43
columns and values for a single geojson feature.
19
44
geom_col (STRING) - Indicates which dict key represents the geometry column.
20
-
21
- TODO: Include validation checks. Add Exception Handling.
22
45
"""
23
46
def __init__ (self , records , geom_col = 'geometry' ):
24
47
self .records = records
@@ -90,3 +113,21 @@ def encode(self):
90
113
features = [self .make_feature (row , self .geom_col ) for row in self .records ]
91
114
feature_collection = self .make_feature_collection (features )
92
115
return feature_collection
116
+
117
+
118
+ class TopoJSONConstructor (object ):
119
+ """
120
+ Given the following inputs, generate a TopoJSON feature collection.
121
+
122
+ Required Parameters:
123
+ records (LIST) - Each element is a dictionary representing
124
+ columns and values for a single geojson feature.
125
+ geom_col (STRING) - Indicates which dict key represents the geometry column.
126
+ """
127
+
128
+ def __init__ (self , records , geom_col = 'geometry' ):
129
+ self .records = records
130
+ self .geom_col = geom_col
131
+
132
+ def encode (self ):
133
+ raise NotImplementedError ("TopoJSON Support Not Implemented In This Version." )
0 commit comments