def test_dumps(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import Point point = Point([600000, 200000], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual(result, '{"spatialReference": {"wkid": 21781}, "attributes": {"name": "toto"}, "y": 200000, "x": 600000}')
def test_dumps_polygon3D(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import Polygon point = Polygon([[(600000, 200000, 500), (650000, 250000, 400), (700000, 250000, 670), (600000, 2000, 500)]], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual(result, '{"rings": [[[600000, 200000, 500], [650000, 250000, 400], [700000, 250000, 670], [600000, 2000, 500]]], "spatialReference": {"wkid": 21781}, "hasZ": true, "attributes": {"name": "toto"}}')
def test_dumps_multiline3D(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import MultiLineString point = MultiLineString([[(600000, 200000, 555), (650000, 250000, 555)], [(700000, 230000, 666), (800000, 340000, 666)]], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual(result, '{"paths": [[[600000, 200000, 555], [650000, 250000, 555]], [[700000, 230000, 666], [800000, 340000, 666]]], "spatialReference": {"wkid": 21781}, "hasZ": true, "attributes": {"name": "toto"}}')
def test_dumps_line3D(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import LineString point = LineString([(600000, 200000, 450), (650000, 250000, 500)], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual(result, '{"paths": [[[600000, 200000, 450], [650000, 250000, 500]]], "spatialReference": {"wkid": 21781}, "hasZ": true, "attributes": {"name": "toto"}}')
def test_dumps_multipoint3D(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import MultiPoint point = MultiPoint([(600000, 200000, 450), (650000, 250000, 650)], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual(result, '{"spatialReference": {"wkid": 21781}, "points": [[600000, 200000, 450], [650000, 250000, 650]], "hasZ": true, "attributes": {"name": "toto"}}')
def test_dumps(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import Point point = Point([600000, 200000], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual( result, '{"spatialReference": {"wkid": 21781}, "attributes": {"name": "toto"}, "y": 200000, "x": 600000}' )
def test_dumps_multipolygon2D(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import MultiPolygon point = MultiPolygon([ ([(600000, 200000), (650000, 250000), (700000, 250000), (600000, 2000)],), ([(600000, 200000), (650000, 250000), (700000, 250000), (600000, 2000)],) ], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual(result, '{"attributes": {"name": "toto"}, "rings": [[[600000, 200000], [650000, 250000], [700000, 250000], [600000, 2000]], [[600000, 200000], [650000, 250000], [700000, 250000], [600000, 2000]]], "spatialReference": {"wkid": 21781}}')
def test_dumps_line3D(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import LineString point = LineString([(600000, 200000, 450), (650000, 250000, 500)], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual( result, '{"paths": [[[600000, 200000, 450], [650000, 250000, 500]]], "spatialReference": {"wkid": 21781}, "hasZ": true, "attributes": {"name": "toto"}}' )
def test_dumps_multipoint3D(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import MultiPoint point = MultiPoint([(600000, 200000, 450), (650000, 250000, 650)], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual( result, '{"spatialReference": {"wkid": 21781}, "points": [[600000, 200000, 450], [650000, 250000, 650]], "hasZ": true, "attributes": {"name": "toto"}}' )
def test_dumps_polygon3D(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import Polygon point = Polygon([[(600000, 200000, 500), (650000, 250000, 400), (700000, 250000, 670), (600000, 2000, 500)]], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual( result, '{"rings": [[[600000, 200000, 500], [650000, 250000, 400], [700000, 250000, 670], [600000, 2000, 500]]], "spatialReference": {"wkid": 21781}, "hasZ": true, "attributes": {"name": "toto"}}' )
def test_dumps_multiline3D(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import MultiLineString point = MultiLineString([[ (600000, 200000, 555), (650000, 250000, 555) ], [(700000, 230000, 666), (800000, 340000, 666)]], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual( result, '{"paths": [[[600000, 200000, 555], [650000, 250000, 555]], [[700000, 230000, 666], [800000, 340000, 666]]], "spatialReference": {"wkid": 21781}, "hasZ": true, "attributes": {"name": "toto"}}' )
def test_dumps_multipolygon2D(self): from chsdi.esrigeojsonencoder import dumps as esri_dumps from geojson import MultiPolygon point = MultiPolygon([([(600000, 200000), (650000, 250000), (700000, 250000), (600000, 2000)], ), ([(600000, 200000), (650000, 250000), (700000, 250000), (600000, 2000)], )], properties={'name': 'toto'}) result = esri_dumps(point) self.assertEqual( result, '{"attributes": {"name": "toto"}, "rings": [[[600000, 200000], [650000, 250000], [700000, 250000], [600000, 2000]], [[600000, 200000], [650000, 250000], [700000, 250000], [600000, 2000]]], "spatialReference": {"wkid": 21781}}' )
def _render(value, system): if isinstance(value, (list, tuple)): value = self.collection_type(value) ret = esri_dumps(value) request = system.get('request') if request is not None: response = request.response ct = response.content_type if ct == response.default_content_type: callback = request.params.get(self.jsonp_param_name) if callback is None: response.content_type = 'application/json' else: response.content_type = 'text/javascript' ret = '%(callback)s(%(json)s);' % {'callback': callback, 'json': ret} return ret