当前位置: 首页>>代码示例>>Python>>正文


Python WKBWriter.write方法代码示例

本文整理汇总了Python中django.contrib.gis.geos.WKBWriter.write方法的典型用法代码示例。如果您正苦于以下问题:Python WKBWriter.write方法的具体用法?Python WKBWriter.write怎么用?Python WKBWriter.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.gis.geos.WKBWriter的用法示例。


在下文中一共展示了WKBWriter.write方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test04_wkbwriter

# 需要导入模块: from django.contrib.gis.geos import WKBWriter [as 别名]
# 或者: from django.contrib.gis.geos.WKBWriter import write [as 别名]
    def test04_wkbwriter(self):
        wkb_w = WKBWriter()

        # Representations of 'POINT (5 23)' in hex -- one normal and
        # the other with the byte order changed.
        g = GEOSGeometry('POINT (5 23)')
        hex1 = '010100000000000000000014400000000000003740'
        wkb1 = buffer(binascii.a2b_hex(hex1))
        hex2 = '000000000140140000000000004037000000000000'
        wkb2 = buffer(binascii.a2b_hex(hex2))

        self.assertEqual(hex1, wkb_w.write_hex(g))
        self.assertEqual(wkb1, wkb_w.write(g))

        # Ensuring bad byteorders are not accepted.
        for bad_byteorder in (-1, 2, 523, 'foo', None):
            # Equivalent of `wkb_w.byteorder = bad_byteorder`
            self.assertRaises(ValueError, wkb_w._set_byteorder, bad_byteorder)
            
        # Setting the byteorder to 0 (for Big Endian)
        wkb_w.byteorder = 0
        self.assertEqual(hex2, wkb_w.write_hex(g))
        self.assertEqual(wkb2, wkb_w.write(g))

        # Back to Little Endian
        wkb_w.byteorder = 1

        # Now, trying out the 3D and SRID flags.
        g = GEOSGeometry('POINT (5 23 17)')
        g.srid = 4326
        
        hex3d = '0101000080000000000000144000000000000037400000000000003140'
        wkb3d = buffer(binascii.a2b_hex(hex3d))
        hex3d_srid = '01010000A0E6100000000000000000144000000000000037400000000000003140'
        wkb3d_srid = buffer(binascii.a2b_hex(hex3d_srid))

        # Ensuring bad output dimensions are not accepted
        for bad_outdim in (-1, 0, 1, 4, 423, 'foo', None):
            # Equivalent of `wkb_w.outdim = bad_outdim`
            self.assertRaises(ValueError, wkb_w._set_outdim, bad_outdim)

        # These tests will fail on 3.0.0 because of a bug that was fixed in 3.1:
        # http://trac.osgeo.org/geos/ticket/216
        if not geos_version_info()['version'].startswith('3.0.'):
            # Now setting the output dimensions to be 3
            wkb_w.outdim = 3

            self.assertEqual(hex3d, wkb_w.write_hex(g))
            self.assertEqual(wkb3d, wkb_w.write(g))

            # Telling the WKBWriter to inlcude the srid in the representation.
            wkb_w.srid = True
            self.assertEqual(hex3d_srid, wkb_w.write_hex(g))
            self.assertEqual(wkb3d_srid, wkb_w.write(g))
开发者ID:0924wyr,项目名称:blog_code,代码行数:56,代码来源:test_io.py

示例2: test04_wkbwriter

# 需要导入模块: from django.contrib.gis.geos import WKBWriter [as 别名]
# 或者: from django.contrib.gis.geos.WKBWriter import write [as 别名]
    def test04_wkbwriter(self):
        wkb_w = WKBWriter()

        # Representations of 'POINT (5 23)' in hex -- one normal and
        # the other with the byte order changed.
        g = GEOSGeometry('POINT (5 23)')
        hex1 = b'010100000000000000000014400000000000003740'
        wkb1 = memoryview(binascii.a2b_hex(hex1))
        hex2 = b'000000000140140000000000004037000000000000'
        wkb2 = memoryview(binascii.a2b_hex(hex2))

        self.assertEqual(hex1, wkb_w.write_hex(g))
        self.assertEqual(wkb1, wkb_w.write(g))

        # Ensuring bad byteorders are not accepted.
        for bad_byteorder in (-1, 2, 523, 'foo', None):
            # Equivalent of `wkb_w.byteorder = bad_byteorder`
            with self.assertRaises(ValueError):
                wkb_w._set_byteorder(bad_byteorder)

        # Setting the byteorder to 0 (for Big Endian)
        wkb_w.byteorder = 0
        self.assertEqual(hex2, wkb_w.write_hex(g))
        self.assertEqual(wkb2, wkb_w.write(g))

        # Back to Little Endian
        wkb_w.byteorder = 1

        # Now, trying out the 3D and SRID flags.
        g = GEOSGeometry('POINT (5 23 17)')
        g.srid = 4326

        hex3d = b'0101000080000000000000144000000000000037400000000000003140'
        wkb3d = memoryview(binascii.a2b_hex(hex3d))
        hex3d_srid = b'01010000A0E6100000000000000000144000000000000037400000000000003140'
        wkb3d_srid = memoryview(binascii.a2b_hex(hex3d_srid))

        # Ensuring bad output dimensions are not accepted
        for bad_outdim in (-1, 0, 1, 4, 423, 'foo', None):
            # Equivalent of `wkb_w.outdim = bad_outdim`
            with self.assertRaises(ValueError):
                wkb_w._set_outdim(bad_outdim)

        # Now setting the output dimensions to be 3
        wkb_w.outdim = 3

        self.assertEqual(hex3d, wkb_w.write_hex(g))
        self.assertEqual(wkb3d, wkb_w.write(g))

        # Telling the WKBWriter to include the srid in the representation.
        wkb_w.srid = True
        self.assertEqual(hex3d_srid, wkb_w.write_hex(g))
        self.assertEqual(wkb3d_srid, wkb_w.write(g))
开发者ID:01-,项目名称:django,代码行数:55,代码来源:test_io.py

示例3: test_empty_polygon_wkb

# 需要导入模块: from django.contrib.gis.geos import WKBWriter [as 别名]
# 或者: from django.contrib.gis.geos.WKBWriter import write [as 别名]
 def test_empty_polygon_wkb(self):
     p = Polygon(srid=4326)
     p_no_srid = Polygon()
     wkb_w = WKBWriter()
     wkb_w.srid = True
     for byteorder, hexes in enumerate([
         (b'000000000300000000', b'0020000003000010E600000000'),
         (b'010300000000000000', b'0103000020E610000000000000'),
     ]):
         wkb_w.byteorder = byteorder
         for srid, hex in enumerate(hexes):
             wkb_w.srid = srid
             self.assertEqual(wkb_w.write_hex(p), hex)
             self.assertEqual(GEOSGeometry(wkb_w.write_hex(p)), p if srid else p_no_srid)
             self.assertEqual(wkb_w.write(p), memoryview(binascii.a2b_hex(hex)))
             self.assertEqual(GEOSGeometry(wkb_w.write(p)), p if srid else p_no_srid)
开发者ID:ArcTanSusan,项目名称:django,代码行数:18,代码来源:test_io.py

示例4: convert_to_2d

# 需要导入模块: from django.contrib.gis.geos import WKBWriter [as 别名]
# 或者: from django.contrib.gis.geos.WKBWriter import write [as 别名]
def convert_to_2d(geom):
    """Convert a geometry from 3D to 2D"""
    from django.contrib.gis.geos import WKBWriter, WKBReader
    wkb_r = WKBReader()
    wkb_w = WKBWriter()
    wkb_w.outdim = 2
    return wkb_r.read(wkb_w.write(geom))
开发者ID:Ecotrust,项目名称:madrona_addons,代码行数:9,代码来源:models.py

示例5: test_empty_point_wkb

# 需要导入模块: from django.contrib.gis.geos import WKBWriter [as 别名]
# 或者: from django.contrib.gis.geos.WKBWriter import write [as 别名]
    def test_empty_point_wkb(self):
        p = Point(srid=4326)
        wkb_w = WKBWriter()

        wkb_w.srid = False
        with self.assertRaisesMessage(ValueError, 'Empty point is not representable in WKB.'):
            wkb_w.write(p)
        with self.assertRaisesMessage(ValueError, 'Empty point is not representable in WKB.'):
            wkb_w.write_hex(p)

        wkb_w.srid = True
        for byteorder, hex in enumerate([
            b'0020000001000010E67FF80000000000007FF8000000000000',
            b'0101000020E6100000000000000000F87F000000000000F87F',
        ]):
            wkb_w.byteorder = byteorder
            self.assertEqual(wkb_w.write_hex(p), hex)
            self.assertEqual(GEOSGeometry(wkb_w.write_hex(p)), p)
            self.assertEqual(wkb_w.write(p), memoryview(binascii.a2b_hex(hex)))
            self.assertEqual(GEOSGeometry(wkb_w.write(p)), p)
开发者ID:ArcTanSusan,项目名称:django,代码行数:22,代码来源:test_io.py

示例6: _handle_geom

# 需要导入模块: from django.contrib.gis.geos import WKBWriter [as 别名]
# 或者: from django.contrib.gis.geos.WKBWriter import write [as 别名]
 def _handle_geom(self, geometry):
     """ Geometry processing (in place), depending on options """
     # Optional force 2D
     if self.options.get('force2d'):
         wkb_w = WKBWriter()
         wkb_w.outdim = 2
         geometry = GEOSGeometry(wkb_w.write(geometry), srid=geometry.srid)
     # Optional geometry simplification
     simplify = self.options.get('simplify')
     if simplify is not None:
         geometry = geometry.simplify(tolerance=simplify, preserve_topology=True)
     # Optional geometry reprojection
     if self.srid != geometry.srid:
         geometry.transform(self.srid)
     return geometry
开发者ID:point97,项目名称:django-geojson,代码行数:17,代码来源:serializers.py

示例7: _prepare_geometry

# 需要导入模块: from django.contrib.gis.geos import WKBWriter [as 别名]
# 或者: from django.contrib.gis.geos.WKBWriter import write [as 别名]
 def _prepare_geometry(self, field, value):
     """
     Reduce geometry to two dimensions if models.GeometryField
     dim parameter does not request otherwise.
     """
     # TODO: DO we need to add 2D to 3D conversation filling z
     # with 0s or is this taken care of implicitely?
     # (cannot be easily tested since 3d is not supported by
     # spatialite backend in Django 1.6.)
     from django.contrib.gis.geos import WKBWriter, GEOSGeometry
     if isinstance(value, (str, unicode)):
         value = GEOSGeometry(value)
     wkb_writer = WKBWriter()
     if isinstance(value, GEOSGeometry):
         if value.hasz and field.dim == 2:
             value = GEOSGeometry(wkb_writer.write(value))
     return value
开发者ID:rogeriofalcone,项目名称:django-etl-sync,代码行数:19,代码来源:generators.py

示例8: _handle_geom

# 需要导入模块: from django.contrib.gis.geos import WKBWriter [as 别名]
# 或者: from django.contrib.gis.geos.WKBWriter import write [as 别名]
    def _handle_geom(self, value):
        """ Geometry processing (in place), depending on options """
        if value is None:
            geometry = None
        elif isinstance(value, dict) and 'type' in value:
            geometry = value
        else:
            if isinstance(value, GEOSGeometry):
                geometry = value
            else:
                try:
                    # this will handle string representations (e.g. ewkt, bwkt)
                    geometry = GEOSGeometry(value)
                except ValueError:
                    # if the geometry couldn't be parsed.
                    # we can't generate valid geojson
                    error_msg = 'The field ["%s", "%s"] could not be parsed as a valid geometry' % (
                        self.geometry_field, value
                    )
                    raise SerializationError(error_msg)

            # Optional force 2D
            if self.options.get('force2d'):
                wkb_w = WKBWriter()
                wkb_w.outdim = 2
                geometry = GEOSGeometry(wkb_w.write(geometry), srid=geometry.srid)
            # Optional geometry simplification
            simplify = self.options.get('simplify')
            if simplify is not None:
                geometry = geometry.simplify(tolerance=simplify, preserve_topology=True)
            # Optional geometry reprojection
            if geometry.srid and geometry.srid != self.srid:
                geometry.transform(self.srid)
            # Optional bbox
            if self.options.get('bbox_auto'):
                self._current['bbox'] = geometry.extent

        self._current['geometry'] = geometry
开发者ID:harshalgalgale,项目名称:django-geojson,代码行数:40,代码来源:serializers.py


注:本文中的django.contrib.gis.geos.WKBWriter.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。