本文整理汇总了Python中geotrek.core.models.Path.get_elevation_profile方法的典型用法代码示例。如果您正苦于以下问题:Python Path.get_elevation_profile方法的具体用法?Python Path.get_elevation_profile怎么用?Python Path.get_elevation_profile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geotrek.core.models.Path
的用法示例。
在下文中一共展示了Path.get_elevation_profile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_elevation
# 需要导入模块: from geotrek.core.models import Path [as 别名]
# 或者: from geotrek.core.models.Path import get_elevation_profile [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)
示例2: test_elevation_path
# 需要导入模块: from geotrek.core.models import Path [as 别名]
# 或者: from geotrek.core.models.Path import get_elevation_profile [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)