Exemple #1
0
    def test_serialize_wkb(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        from shapely.geometry.point import Point
        wkb = from_shape(Point(1.0, 2.0))
        self.assertEquals('{"type": "Point", "coordinates": [1.0, 2.0]}',
                          geom_schema.serialize({}, wkb))
Exemple #2
0
    def test_serialize_wkb(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        from shapely.geometry.point import Point
        wkb = from_shape(Point(1.0, 2.0))
        self.assertEquals(
            '{"type": "Point", "coordinates": [1.0, 2.0]}',
            geom_schema.serialize({}, wkb))
Exemple #3
0
    def test_deserialize_valid_geojson(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        from shapely.geometry.point import Point
        expected_wkb = WKBElement(Point(1.0, 2.0).wkb)

        wkb = geom_schema.deserialize(
            {}, '{"type": "Point", "coordinates": [1.0, 2.0]}')
        self.assertEquals(expected_wkb.desc, wkb.desc)
Exemple #4
0
    def test_serialize_reproject(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry(srid=4326, map_srid=3857)

        from shapely.geometry.point import Point
        wkb = from_shape(Point(1.0, 2.0), 4326)
        geo_json = json.loads(geom_schema.serialize({}, wkb))
        self.assertEquals('Point', geo_json['type'])
        self.assertAlmostEqual(111319.49079327231, geo_json['coordinates'][0])
        self.assertAlmostEqual(222684.20850554455, geo_json['coordinates'][1])
Exemple #5
0
    def test_deserialize_valid_geojson(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        from shapely.geometry.point import Point
        expected_wkb = WKBElement(Point(1.0, 2.0).wkb)

        wkb = geom_schema.deserialize(
            {}, '{"type": "Point", "coordinates": [1.0, 2.0]}')
        self.assertEquals(expected_wkb.desc, wkb.desc)
Exemple #6
0
    def test_serialize_reproject(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry(srid=4326, map_srid=3857)

        from shapely.geometry.point import Point
        wkb = from_shape(Point(1.0, 2.0), 4326)
        geo_json = json.loads(geom_schema.serialize({}, wkb))
        self.assertEquals('Point', geo_json['type'])
        self.assertAlmostEqual(111319.49079327231, geo_json['coordinates'][0])
        self.assertAlmostEqual(222684.20850554455, geo_json['coordinates'][1])
Exemple #7
0
    def test_serialize_4d_wkb(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        wkb = geomet_wkb.dumps(
            {'type': 'Point', 'coordinates': [1.0, 2.0, 3.0, 4.0]},
            big_endian=False)
        self.assertEquals(
            {"type": "Point", "coordinates": [1.0, 2.0, 3.0, 4.0]},
            json.loads(geom_schema.serialize({}, from_wkb(wkb))))
Exemple #8
0
    def test_deserialize_4d(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        expected_wkb = from_wkb(geomet_wkb.dumps(
            {'type': 'Point', 'coordinates': [1.0, 2.0, 3.0, 4.0]},
            big_endian=False))

        wkb = geom_schema.deserialize(
            {}, '{"type": "Point", "coordinates": [1.0, 2.0, 3.0, 4.0]}')
        self.assertEquals(expected_wkb.desc, wkb.desc)
Exemple #9
0
    def test_deserialize_reproject(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry(srid=4326, map_srid=3857)

        wkb = geom_schema.deserialize(
            {}, '{"type": "Point", '
            '"coordinates": [111319.49079327231, 222684.20850554455]}')
        self.assertEquals(4326, wkb.srid)

        shape = to_shape(wkb)
        self.assertAlmostEqual(1.0, shape.x)
        self.assertAlmostEqual(2.0, shape.y)
Exemple #10
0
    def test_deserialize_reproject(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry(srid=4326, map_srid=3857)

        wkb = geom_schema.deserialize(
            {},
            '{"type": "Point", '
            '"coordinates": [111319.49079327231, 222684.20850554455]}')
        self.assertEquals(4326, wkb.srid)

        shape = to_shape(wkb)
        self.assertAlmostEqual(1.0, shape.x)
        self.assertAlmostEqual(2.0, shape.y)
Exemple #11
0
    def test_serialize_4d_wkb(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        wkb = geomet_wkb.dumps(
            {
                'type': 'Point',
                'coordinates': [1.0, 2.0, 3.0, 4.0]
            },
            big_endian=False)
        self.assertEqual({
            "type": "Point",
            "coordinates": [1.0, 2.0, 3.0, 4.0]
        }, json.loads(geom_schema.serialize({}, from_wkb(wkb))))
Exemple #12
0
    def test_deserialize_4d(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        expected_wkb = from_wkb(
            geomet_wkb.dumps(
                {
                    'type': 'Point',
                    'coordinates': [1.0, 2.0, 3.0, 4.0]
                },
                big_endian=False))

        wkb = geom_schema.deserialize(
            {}, '{"type": "Point", "coordinates": [1.0, 2.0, 3.0, 4.0]}')
        self.assertEqual(expected_wkb.desc, wkb.desc)
Exemple #13
0
    def test_serialize_invalid_wrong_type(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        self.assertRaises(
            Invalid, geom_schema.deserialize, {},
            '{"type": "InvalidType", "coordinates": [1.0, 2.0]}')
Exemple #14
0
    def test_serialize_null(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        self.assertEquals(null, geom_schema.serialize({}, null))
Exemple #15
0
    def test_serialize_invalid(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        self.assertRaises(Invalid, geom_schema.serialize, {}, 'Point(1 0)')
Exemple #16
0
    def test_serialize_null(self):
        from c2corg_api.ext.colander_ext import Geometry
        geom_schema = Geometry()

        self.assertEquals(null, geom_schema.serialize({}, null))