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


Python Path.save方法代码示例

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


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

示例1: test_elevation

# 需要导入模块: from geotrek.core.models import Path [as 别名]
# 或者: from geotrek.core.models.Path import save [as 别名]
    def test_elevation(self):
        # Create a simple fake DEM
        conn = connections[DEFAULT_DB_ALIAS]
        cur = conn.cursor()
        cur.execute('CREATE TABLE mnt (rid serial primary key, rast raster)')
        cur.execute('INSERT INTO mnt (rast) VALUES (ST_MakeEmptyRaster(3, 3, 0, 3, 1, -1, 0, 0, %s))', [settings.SRID])
        cur.execute('UPDATE mnt SET rast = ST_AddBand(rast, \'16BSI\')')
        for x in range(1, 4):
            for y in range(1, 4):
                cur.execute('UPDATE mnt SET rast = ST_SetValue(rast, %s, %s, %s::float)', [x, y, x+y])
        conn.commit_unless_managed()

        # Create a geometry and check elevation-based indicators
        p = Path(geom=LineString((1.5,1.5,0), (2.5,1.5,0), (1.5,2.5,0)))
        self.assertEqual(p.ascent, 0)
        self.assertEqual(p.descent, 0)
        self.assertEqual(p.min_elevation, 0)
        self.assertEqual(p.max_elevation, 0)
        p.save()
        self.assertEqual(p.ascent, 1)
        self.assertEqual(p.descent, -2)
        self.assertEqual(p.min_elevation, 3)
        self.assertEqual(p.max_elevation, 5)

        # Check elevation profile
        profile = p.get_elevation_profile()
        self.assertEqual(len(profile), 3)
        self.assertEqual(profile[0][0], 0.0)
        self.assertEqual(profile[0][1], 4)
        self.assertTrue(1.4 < profile[1][0] < 1.5)
        self.assertEqual(profile[1][1], 5)
        self.assertTrue(3.8 < profile[2][0] < 3.9)
        self.assertEqual(profile[2][1], 3)
开发者ID:Web5design,项目名称:Geotrek,代码行数:35,代码来源:tests.py

示例2: ElevationTest

# 需要导入模块: from geotrek.core.models import Path [as 别名]
# 或者: from geotrek.core.models.Path import save [as 别名]
class ElevationTest(TestCase):

    def setUp(self):
        # Create a simple fake DEM
        conn = connections[DEFAULT_DB_ALIAS]
        cur = conn.cursor()
        cur.execute('CREATE TABLE mnt (rid serial primary key, rast raster)')
        cur.execute('INSERT INTO mnt (rast) VALUES (ST_MakeEmptyRaster(3, 3, 0, 3, 1, -1, 0, 0, %s))', [settings.SRID])
        cur.execute('UPDATE mnt SET rast = ST_AddBand(rast, \'16BSI\')')
        for x in range(1, 4):
            for y in range(1, 4):
                cur.execute('UPDATE mnt SET rast = ST_SetValue(rast, %s, %s, %s::float)', [x, y, x+y])
        conn.commit_unless_managed()
        self.path = Path(geom=LineString((1.5,1.5,0), (2.5,1.5,0), (1.5,2.5,0)))
        self.path.save()

    def tearDown(self):
        conn = connections[DEFAULT_DB_ALIAS]
        cur = conn.cursor()
        self.path.delete()
        cur.execute('DROP TABLE mnt;')

    def test_elevation_path(self):
        p = self.path
        self.assertEqual(p.ascent, 1)
        self.assertEqual(p.descent, -2)
        self.assertEqual(p.min_elevation, 3)
        self.assertEqual(p.max_elevation, 5)

        # Check elevation profile
        profile = p.get_elevation_profile()
        self.assertEqual(len(profile), 4)  # minimum possible (since p.length < sampling resolution)
        self.assertEqual(profile[0][0], 0.0)
        self.assertEqual(profile[0][3], 4)
        self.assertTrue(2.4 < profile[-1][0] < 2.5)  # p.geom.length
        self.assertEqual(profile[-1][3], 3)

    def test_elevation_topology_line(self):
        topo = TopologyFactory.create(no_path=True)
        topo.add_path(self.path, start=0.2, end=0.7)
        topo.save()

        self.assertEqual(topo.ascent, 0)
        self.assertEqual(topo.descent, 0)
        self.assertEqual(topo.min_elevation, 4)
        self.assertEqual(topo.max_elevation, 5)

    def test_elevation_topology_point(self):
        topo = TopologyFactory.create(no_path=True)
        topo.add_path(self.path, start=0.5, end=0.5)
        topo.save()

        self.assertEqual(topo.ascent, 0)
        self.assertEqual(topo.descent, 0)
        self.assertEqual(topo.min_elevation, 5)
        self.assertEqual(topo.max_elevation, 5)
开发者ID:leplatrem,项目名称:Geotrek,代码行数:58,代码来源:test_elevation.py

示例3: test_elevation_topology_point

# 需要导入模块: from geotrek.core.models import Path [as 别名]
# 或者: from geotrek.core.models.Path import save [as 别名]
    def test_elevation_topology_point(self):
        p = Path(geom=LineString((1.5,1.5,0), (2.5,1.5,0), (1.5,2.5,0)))
        p.save()

        topo = TopologyFactory.create(no_path=True)
        topo.add_path(p, start=0.5, end=0.5)
        topo.save()

        self.assertEqual(topo.ascent, 0)
        self.assertEqual(topo.descent, 0)
        self.assertEqual(topo.min_elevation, 5)
        self.assertEqual(topo.max_elevation, 5)
开发者ID:ymzoughi,项目名称:Geotrek,代码行数:14,代码来源:test_elevation.py

示例4: test_elevation_path

# 需要导入模块: from geotrek.core.models import Path [as 别名]
# 或者: from geotrek.core.models.Path import save [as 别名]
    def test_elevation_path(self):
        # Create a geometry and check elevation-based indicators
        p = Path(geom=LineString((1.5,1.5,0), (2.5,1.5,0), (1.5,2.5,0)))
        self.assertEqual(p.ascent, 0)
        self.assertEqual(p.descent, 0)
        self.assertEqual(p.min_elevation, 0)
        self.assertEqual(p.max_elevation, 0)
        p.save()
        self.assertEqual(p.ascent, 1)
        self.assertEqual(p.descent, -2)
        self.assertEqual(p.min_elevation, 3)
        self.assertEqual(p.max_elevation, 5)

        # Check elevation profile
        profile = p.get_elevation_profile()
        self.assertEqual(len(profile), 4)  # minimum possible (since p.length < sampling resolution)
        self.assertEqual(profile[0][0], 0.0)
        self.assertEqual(profile[0][3], 4)
        self.assertTrue(2.4 < profile[-1][0] < 2.5)  # p.geom.length
        self.assertEqual(profile[-1][3], 3)
开发者ID:ymzoughi,项目名称:Geotrek,代码行数:22,代码来源:test_elevation.py

示例5: test_link_closest_visible_path

# 需要导入模块: from geotrek.core.models import Path [as 别名]
# 或者: from geotrek.core.models.Path import save [as 别名]
    def test_link_closest_visible_path(self):
        """
        Topology must be linked to the closest visible path only
        """
        path_visible = Path(name="visible",
                            geom='LINESTRING(0 0, 1 0, 2 0)',
                            visible=True)
        path_visible.save()
        path_unvisible = Path(name="unvisible",
                              geom='LINESTRING(0 3, 1 3, 2 3)',
                              visible=False)
        path_unvisible.save()

        # default manager see 1 path
        self.assertEqual(Path.objects.count(), 1)

        # custom manager see 2 paths
        self.assertEqual(Path.include_invisible.count(), 2)

        # create topo on visible path
        topology = TopologyHelper._topologypoint(0, 0, None).reload()

        # because FK and M2M are used with default manager only, others tests are in SQL
        conn = connections[DEFAULT_DB_ALIAS]
        cur = conn.cursor()
        cur.execute(
            """
            SELECT t.id as id_path,
                   et.evenement as id_topology,
                   t.visible as visible
            FROM e_r_evenement_troncon et
            JOIN l_t_troncon t ON et.troncon=t.id
            WHERE et.evenement={topo_id}
            """.format(topo_id=topology.pk))

        datas = dictfetchall(cur)

        # topo must be linked to visible path
        self.assertIn(topology.pk, [ele['id_topology'] for ele in datas], u"{}".format(datas))
        self.assertIn(path_visible.pk, [ele['id_path'] for ele in datas], u"{}".format(datas))
        self.assertNotIn(path_unvisible.pk, [ele['id_path'] for ele in datas], u"{}".format(datas))

        # new topo on invible path
        topology = TopologyHelper._topologypoint(0, 3, None).reload()

        cur.execute(
            """
            SELECT t.id as id_path,
                   et.evenement as id_topology,
                   t.visible as visible
            FROM e_r_evenement_troncon et
            JOIN l_t_troncon t ON et.troncon=t.id
            WHERE et.evenement={topo_id}
            """.format(topo_id=topology.pk))

        datas = dictfetchall(cur)

        self.assertIn(topology.pk, [ele['id_topology'] for ele in datas], u"{}".format(datas))
        self.assertIn(path_visible.pk, [ele['id_path'] for ele in datas], u"{}".format(datas))
        self.assertNotIn(path_unvisible.pk, [ele['id_path'] for ele in datas], u"{}".format(datas))
        cur.close()
开发者ID:makinacorpus,项目名称:Geotrek,代码行数:63,代码来源:test_topology.py


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