本文整理汇总了Python中geotrek.core.models.Path类的典型用法代码示例。如果您正苦于以下问题:Python Path类的具体用法?Python Path怎么用?Python Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_latestupdate_delete
def test_latestupdate_delete(self):
for i in range(10):
PathFactory.create()
t1 = dbnow()
self.assertTrue(t1 > Path.latest_updated())
(Path.objects.all()[0]).delete()
self.assertFalse(t1 > Path.latest_updated())
示例2: test_elevation
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)
示例3: ElevationTest
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)
示例4: test_elevation_topology_point
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)
示例5: test_point_geom_3d
def test_point_geom_3d(self):
"""
+
/ \
/ X \
+ +
"""
p1 = PathFactory.create(geom=LineString((0, 0, 1000), (4, 4, 2000)))
p2 = PathFactory.create(geom=LineString((4, 4, 2000), (8, 0, 0)))
poi = Point(3, 1, srid=settings.SRID)
position, distance = Path.interpolate(p1, poi)
self.assertTrue(almostequal(0.5, position))
self.assertTrue(almostequal(-1.414, distance))
# Verify that deserializing this, we obtain the same original coordinates
# (use lat/lng as in forms)
poi.transform(settings.API_SRID)
poitopo = Topology.deserialize({'lat': poi.y, 'lng': poi.x})
# Computed topology properties match original interpolation
self.assertTrue(almostequal(0.5, poitopo.aggregations.all()[0].start_position))
self.assertTrue(almostequal(-1.414, poitopo.offset))
# Resulting geometry
self.assertTrue(almostequal(3, poitopo.geom.x))
self.assertTrue(almostequal(1, poitopo.geom.y))
self.assertTrue(almostequal(0, poitopo.geom.z))
示例6: test_elevation_path
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)
示例7: setUp
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()
示例8: test_topology_linked_to_not_draft
def test_topology_linked_to_not_draft(self):
path_draft = PathFactory.create(name="draft",
geom='LINESTRING(0 0, 1 0, 2 0)',
draft=True)
path_draft.save()
path_normal = PathFactory.create(name="normal",
geom='LINESTRING(0 3, 1 3, 2 3)',
draft=False)
path_normal.save()
point = Point(0, 0, srid=settings.SRID)
closest = Path.closest(point)
self.assertEqual(point.wkt, 'POINT (0 0)')
self.assertEqual(closest, path_normal)
示例9: test_structure
def test_structure(structure, stake):
user = self.userfactory(password='booh')
p = user.profile
p.structure = structure
p.save()
success = self.client.login(username=user.username, password='booh')
self.assertTrue(success)
response = self.client.get(Path.get_add_url())
self.assertEqual(response.status_code, 200)
self.assertTrue('form' in response.context)
form = response.context['form']
self.assertTrue('stake' in form.fields)
stakefield = form.fields['stake']
self.assertTrue((stake.pk, unicode(stake)) in stakefield.choices)
self.client.logout()
示例10: test_deserialize_point
def test_deserialize_point(self):
PathFactory.create()
# Take a point
p = Point(2, 1, 0, srid=settings.SRID)
p.transform(settings.API_SRID)
closest = Path.closest(p)
# Check closest path
self.assertEqual(closest.geom.coords, ((1.0, 1.0, 0.0), (2.0, 2.0, 0.0)))
# The point has same x as first point of path, and y to 0 :
topology = Topology.deserialize('{"lng": %s, "lat": %s}' % (p.x, p.y))
self.assertAlmostEqual(topology.offset, -0.7071, 3)
self.assertEqual(len(topology.paths.all()), 1)
pagg = topology.aggregations.get()
self.assertTrue(almostequal(pagg.start_position, 0.5))
self.assertTrue(almostequal(pagg.end_position, 0.5))
示例11: test_structurerelated_filter_with_none
def test_structurerelated_filter_with_none(self):
s1 = StructureFactory.create()
s2 = StructureFactory.create()
st0 = StakeFactory.create(structure=None)
st1 = StakeFactory.create(structure=s1)
st2 = StakeFactory.create(structure=s2)
user = self.userfactory(password='booh')
p = user.profile
p.structure = s1
p.save()
success = self.client.login(username=user.username, password='booh')
self.assertTrue(success)
response = self.client.get(Path.get_add_url())
self.assertEqual(response.status_code, 200)
self.assertTrue('form' in response.context)
form = response.context['form']
self.assertTrue('stake' in form.fields)
stakefield = form.fields['stake']
self.assertTrue((st0.pk, unicode(st0)) in stakefield.choices)
self.assertTrue((st1.pk, unicode(st1)) in stakefield.choices)
self.assertFalse((st2.pk, unicode(st2)) in stakefield.choices)
示例12: test_paths_bystructure
def test_paths_bystructure(self):
user = UserFactory()
p1 = PathFactory()
p2 = PathFactory(structure=Structure.objects.create(name="other"))
self.assertEqual(user.profile.structure, p1.structure)
self.assertNotEqual(user.profile.structure, p2.structure)
self.assertEqual(len(Structure.objects.all()), 2)
self.assertEqual(len(Path.objects.all()), 2)
self.assertEqual(Path.in_structure.for_user(user)[0], Path.for_user(user)[0])
self.assertTrue(p1 in Path.in_structure.for_user(user))
self.assertFalse(p2 in Path.in_structure.for_user(user))
# Change user structure on-the-fly
profile = user.profile
profile.structure = p2.structure
profile.save()
self.assertEqual(user.profile.structure.name, "other")
self.assertFalse(p1 in Path.in_structure.for_user(user))
self.assertTrue(p2 in Path.in_structure.for_user(user))
示例13: InfrastructureStructureManager
in_structure = InfrastructureStructureManager()
class Meta:
proxy = True
verbose_name = _(u"Infrastructure")
verbose_name_plural = _(u"Infrastructures")
@classmethod
def path_infrastructures(cls, path):
return cls.objects.filter(aggregations__path=path).distinct('pk')
@classmethod
def topology_infrastructures(cls, topology):
return cls.objects.filter(aggregations__path__in=topology.paths.all()).distinct('pk')
Path.add_property('infrastructures', lambda self: Infrastructure.path_infrastructures(self))
Topology.add_property('infrastructures', lambda self: Infrastructure.topology_infrastructures(self))
class SignageGISManager(gismodels.GeoManager):
""" Overide default typology mixin manager, and filter by type. """
def get_query_set(self):
return super(SignageGISManager, self).get_query_set().filter(type__type=INFRASTRUCTURE_TYPES.SIGNAGE)
class SignageStructureManager(StructureRelatedManager):
""" Overide default structure related manager, and filter by type. """
def get_query_set(self):
return super(SignageStructureManager, self).get_query_set().filter(type__type=INFRASTRUCTURE_TYPES.SIGNAGE)
示例14: is_publishable
def is_publishable(self):
return self.is_complete() and self.has_geom_valid()
def __unicode__(self):
return u"%s (%s - %s)" % (self.name, self.departure, self.arrival)
@classmethod
def path_treks(cls, path):
return cls.objects.existing().filter(aggregations__path=path).distinct('pk')
@classmethod
def topology_treks(cls, topology):
return cls.objects.existing().filter(aggregations__path__in=topology.paths.all()).distinct('pk')
Path.add_property('treks', lambda self: Trek.path_treks(self))
Topology.add_property('treks', lambda self: Trek.topology_treks(self))
Intervention.add_property('treks', lambda self: self.topology.treks if self.topology else [])
Project.add_property('treks', lambda self: self.edges_by_attr('treks'))
class TrekRelationshipManager(models.Manager):
use_for_related_fields = True
def get_query_set(self):
# Select treks foreign keys by default
qs = super(TrekRelationshipManager, self).get_query_set().select_related('trek_a', 'trek_b')
# Exclude deleted treks
return qs.exclude(trek_a__deleted=True).exclude(trek_b__deleted=True)
示例15: physical_type_csv_display
self.physical_type
)
@property
def physical_type_csv_display(self):
return unicode(self.physical_type)
@classmethod
def path_physicals(cls, path):
return cls.objects.existing().select_related('physical_type').filter(aggregations__path=path).distinct('pk')
@classmethod
def topology_physicals(cls, topology):
return cls.overlapping(topology).select_related('physical_type')
Path.add_property('physical_edges', PhysicalEdge.path_physicals, _(u"Physical edges"))
Topology.add_property('physical_edges', PhysicalEdge.topology_physicals, _(u"Physical edges"))
Intervention.add_property('physical_edges', lambda self: self.topology.physical_edges if self.topology else [], _(u"Physical edges"))
Project.add_property('physical_edges', lambda self: self.edges_by_attr('physical_edges'), _(u"Physical edges"))
class LandType(StructureRelated):
name = models.CharField(max_length=128, db_column='foncier', verbose_name=_(u"Name"))
right_of_way = models.BooleanField(db_column='droit_de_passage', verbose_name=_(u"Right of way"))
class Meta:
db_table = 'f_b_foncier'
verbose_name = _(u"Land type")
verbose_name_plural = _(u"Land types")
ordering = ['name']