本文整理汇总了Python中geotrek.core.factories.PathAggregationFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python PathAggregationFactory.create方法的具体用法?Python PathAggregationFactory.create怎么用?Python PathAggregationFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geotrek.core.factories.PathAggregationFactory
的用法示例。
在下文中一共展示了PathAggregationFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_topology_geom
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_topology_geom(self):
p1 = PathFactory.create(geom=LineString((0, 0, 0), (2, 2, 2)))
p2 = PathFactory.create(geom=LineString((2, 2, 2), (2, 0, 0)))
p3 = PathFactory.create(geom=LineString((2, 0, 0), (4, 0, 0)))
# Type Point
t = TopologyFactory.create(no_path=True)
PathAggregationFactory.create(topo_object=t, path=p1,
start_position=0.5, end_position=0.5)
t = Topology.objects.get(pk=t.pk)
self.assertEqual(t.geom, Point((1, 1, 1)))
# 50% of path p1, 100% of path p2
t = TopologyFactory.create(no_path=True)
PathAggregationFactory.create(topo_object=t, path=p1,
start_position=0.5)
PathAggregationFactory.create(topo_object=t, path=p2)
t = Topology.objects.get(pk=t.pk)
self.assertEqual(t.geom, LineString((1, 1, 1), (2, 2, 2), (2, 0, 0)))
# 100% of path p2 and p3, with offset of 1
t = TopologyFactory.create(no_path=True, offset=1)
PathAggregationFactory.create(topo_object=t, path=p2)
PathAggregationFactory.create(topo_object=t, path=p3)
t.save()
self.assertEqual(t.geom, LineString((3, 2, 2), (3, 1, 0), (4, 1, 0)))
# Change offset, geometry is computed again
t.offset = 0.5
t.save()
self.assertEqual(t.geom, LineString((2.5, 2, 2), (2.5, 0.5, 0), (4, 0.5, 0)))
示例2: test_length
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_length(self):
e = TopologyFactory.build(no_path=True)
self.assertEqual(e.length, 0)
e.save()
self.assertEqual(e.length, 0)
PathAggregationFactory.create(topo_object=e)
e.save()
self.assertNotEqual(e.length, 0)
示例3: test_path_helpers
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_path_helpers(self):
if not self.factory:
return # ignore abstract test
p = PathFactory.create()
self.assertEquals(len(getattr(p, self.helper_name)), 0)
l = self.factory.create(no_path=True)
PathAggregationFactory.create(topo_object=l, path=p)
self.assertEqual([o.pk for o in getattr(p, self.helper_name).all()],
[l.pk])
示例4: test_recompute_pk_reverse_AB_CD
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_recompute_pk_reverse_AB_CD(self):
"""
A---------------B + C-------------------D B----------------AD----------------C
| | |--| | => | | | |--|
E1 (0.2) | E3 (0.2, 0.3) | | E1 (0.4) | E3 (0.8, 0.9)
E2 (0.6) E4 (0.8) E2 (0.2) E4 (0.6)
In case of AB == CD, matching A and D
"""
path_AB = PathFactory.create(name="PATH_AB", geom=LineString((10, 1), (0, 1)))
path_CD = PathFactory.create(name="PATH_CD", geom=LineString((20, 1), (10, 1)))
e1 = TopologyFactory.create(geom=Point(2, 2))
a1 = PathAggregationFactory.create(path=path_AB, topo_object=e1)
e2 = TopologyFactory.create(geom=Point(6, 1))
a2 = PathAggregationFactory.create(path=path_AB, topo_object=e2)
e3 = TopologyFactory.create(geom=LineString((2, 1), (3, 1),))
a3 = PathAggregationFactory.create(path=path_CD, topo_object=e3)
e4 = TopologyFactory.create(geom=Point(8, 2))
a4 = PathAggregationFactory.create(path=path_CD, topo_object=e4)
path_AB_original_length = path_AB.length
path_CD_original_length = path_CD.length
path_AB.merge_path(path_CD)
self.assertEqual(path_AB.geom, LineString((0, 1), (10, 1), (20, 1)))
# reload updated objects
a1_updated = PathAggregation.objects.get(pk=a1.pk)
a2_updated = PathAggregation.objects.get(pk=a2.pk)
a3_updated = PathAggregation.objects.get(pk=a3.pk)
a4_updated = PathAggregation.objects.get(pk=a4.pk)
# test pk recompute on path_1 : new pk = old pk * old_path_1_length / new_path_1_length
self.assertEqual(a1_updated.start_position, (1 - a1.start_position) * (path_AB_original_length / path_AB.length))
self.assertEqual(a1_updated.end_position, (1 - a1.end_position) * (path_AB_original_length / path_AB.length))
self.assertEqual(a2_updated.start_position, (1 - a2.start_position) * (path_AB_original_length / path_AB.length))
self.assertEqual(a2_updated.end_position, (1 - a1.end_position) * (path_AB_original_length / path_AB.length))
# test pk recompute on path_2 : new pk = old pk * old_path_2_length / new_path_1_length + old_path_1_length / new_path_1_length
self.assertEqual(a3_updated.start_position, (1 - a3.start_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length)
self.assertEqual(a3_updated.end_position, (1 - a3.end_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length)
self.assertEqual(a4_updated.start_position, (1 - a4.start_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length)
self.assertEqual(a4_updated.end_position, (1 - a4.end_position) * (path_CD_original_length / path_AB.length) + path_AB_original_length / path_AB.length)
# test offset changes
e1_updated = Topology.objects.get(pk=e1.pk)
self.assertEqual(e1_updated.offset, -e1.offset)
e4_updated = Topology.objects.get(pk=e4.pk)
self.assertEqual(e4_updated.offset, -e4.offset)
示例5: create_pair_of_distinct_by_topo_intervention
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def create_pair_of_distinct_by_topo_intervention(self):
p1, seek_path = self.create_pair_of_distinct_path()
topo_1 = TopologyFactory.create(no_path=True)
PathAggregationFactory.create(topo_object=topo_1, path=p1, start_position=0, end_position=1)
seek_topo = TopologyFactory.create(no_path=True)
PathAggregationFactory.create(topo_object=seek_topo, path=seek_path, start_position=0, end_position=1)
it_p1 = InterventionFactory.create(topology=topo_1)
seek_it = InterventionFactory.create(topology=seek_topo)
return seek_it, seek_path
示例6: test_elevation
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_elevation(self):
trek = TrekFactory.create(no_path=True)
p1 = PathFactory.create(geom=LineString((1, 0, 1), (0, 0, 1), (0, 1, 1)))
p2 = PathFactory.create(geom=LineString((0, 1, 1), (1, 1, 1), (1, 2, 2)))
PathAggregationFactory.create(topo_object=trek, path=p1,
start_position=0.5)
PathAggregationFactory.create(topo_object=trek, path=p2)
trek = Trek.objects.get(pk=trek.pk) # reload to get computed fields
actual_profile = trek.elevation_profile
expected_profile = ((0, 1), (1, 1), (2, 1), (2 + 2 ** 0.5, 2))
self.assertItemsEqual(actual_profile, expected_profile)
示例7: test_filter_by_physical_edge
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_filter_by_physical_edge(self):
seek_inter, seek_path = self.create_pair_of_distinct_by_topo_intervention()
edge = PhysicalEdgeFactory(no_path=True)
PathAggregationFactory.create(topo_object=edge, path=seek_path, start_position=0, end_position=1)
edge.reload()
# filter by physical type
data = {'physical_type': edge.physical_type.pk}
qs = InterventionFilterSet(data=data).qs
self.assertEqual(len(qs), 1)
self.assertEqual(qs[0], seek_inter)
示例8: test_helpers
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_helpers(self):
p = PathFactory.create()
self.assertEquals(len(p.infrastructures), 0)
sign = SignageFactory.create(no_path=True)
PathAggregationFactory.create(topo_object=sign, path=p, start_position=0.5, end_position=0.5)
self.assertItemsEqual(p.signages, [sign])
infra = InfrastructureFactory.create(no_path=True)
PathAggregationFactory.create(topo_object=infra, path=p)
self.assertItemsEqual(p.infrastructures, [infra])
示例9: test_filter_by_competence_edge
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_filter_by_competence_edge(self):
seek_proj, seek_path = self.create_pair_of_distinct_by_topo_project()
edge = CompetenceEdgeFactory(no_path=True)
PathAggregationFactory.create(topo_object=edge, path=seek_path, start_position=0, end_position=1)
edge.reload()
# filter by organization
data = { 'competence': edge.organization.pk }
qs = ProjectFilter(data=data).qs
self.assertEqual(len(qs), 1)
self.assertEqual(qs[0], seek_proj)
示例10: test_filter_by_land_edge
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_filter_by_land_edge(self):
seek_proj, seek_path = self.create_pair_of_distinct_by_topo_project()
edge = LandEdgeFactory(no_path=True)
PathAggregationFactory.create(topo_object=edge, path=seek_path, start_position=0, end_position=1)
edge.reload()
# filter by land type
data = {'land_type': edge.land_type.pk}
qs = ProjectFilterSet(data=data).qs
self.assertEqual(len(qs), 1)
self.assertEqual(qs[0], seek_proj)
示例11: test_filter_by_work_management_edge
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_filter_by_work_management_edge(self):
seek_proj, seek_path = self.create_pair_of_distinct_by_topo_project()
edge = WorkManagementEdgeFactory(no_path=True)
PathAggregationFactory.create(topo_object=edge, path=seek_path, start_position=0, end_position=1)
edge.reload()
# filter by organization
data = {'work': edge.organization.pk}
qs = ProjectFilterSet(data=data).qs
self.assertEqual(len(qs), 1)
self.assertEqual(qs[0], seek_proj)
示例12: test_helpers
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_helpers(self):
trek = TrekFactory.create(no_path=True)
p1 = PathFactory.create(geom=LineString((0, 0), (4, 4)))
p2 = PathFactory.create(geom=LineString((4, 4), (8, 8)))
poi = POIFactory.create(no_path=True)
PathAggregationFactory.create(topo_object=trek, path=p1,
start_position=0.5)
PathAggregationFactory.create(topo_object=trek, path=p2)
PathAggregationFactory.create(topo_object=poi, path=p1,
start_position=0.6, end_position=0.6)
# /!\ District are automatically linked to paths at DB level
d1 = DistrictFactory.create(geom=MultiPolygon(
Polygon(((-2, -2), (3, -2), (3, 3), (-2, 3), (-2, -2)))))
# Ensure related objects are accessible
self.assertItemsEqual(trek.pois, [poi])
self.assertItemsEqual(poi.treks, [trek])
self.assertItemsEqual(trek.districts, [d1])
# Ensure there is no duplicates
PathAggregationFactory.create(topo_object=trek, path=p1,
end_position=0.5)
self.assertItemsEqual(trek.pois, [poi])
self.assertItemsEqual(poi.treks, [trek])
d2 = DistrictFactory.create(geom=MultiPolygon(
Polygon(((3, 3), (9, 3), (9, 9), (3, 9), (3, 3)))))
self.assertItemsEqual(trek.districts, [d1, d2])
示例13: test_filter_by_signage_management_edge
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_filter_by_signage_management_edge(self):
seek_inter, seek_path = self.create_pair_of_distinct_by_topo_intervention()
edge = SignageManagementEdgeFactory(no_path=True)
PathAggregationFactory.create(topo_object=edge, path=seek_path, start_position=0, end_position=1)
edge.reload()
# filter by organization
data = {'signage': edge.organization.pk}
qs = InterventionFilterSet(data=data).qs
self.assertEqual(len(qs), 1)
self.assertEqual(qs[0], seek_inter)
示例14: test_junction_point
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_junction_point(self):
p1 = PathFactory.create(geom=LineString((0, 0, 0), (2, 2, 2)))
p2 = PathFactory.create(geom=LineString((0, 0, 0), (2, 0, 0)))
p3 = PathFactory.create(geom=LineString((0, 2, 2), (0, 0, 0)))
# Create a junction point topology
t = TopologyFactory.create(no_path=True)
self.assertEqual(len(t.paths.all()), 0)
pa = PathAggregationFactory.create(topo_object=t, path=p1,
start_position=0.0, end_position=0.0)
self.assertItemsEqual(t.paths.all(), [p1, p2, p3])
# Update to a non junction point topology
pa.end_position = 0.4
pa.save()
self.assertItemsEqual(t.paths.all(), [p1])
# Update to a junction point topology
pa.end_position = 0.0
pa.save()
self.assertItemsEqual(t.paths.all(), [p1, p2, p3])
示例15: test_remove_poi
# 需要导入模块: from geotrek.core.factories import PathAggregationFactory [as 别名]
# 或者: from geotrek.core.factories.PathAggregationFactory import create [as 别名]
def test_remove_poi(self):
"""
poi is linked with AB
poi
+ D
* |
* |
A---------B C
|----|
e1
we got after remove AB :
poi
+ * * * * * * * D
|
|
C
poi is linked with DC and e1 is deleted
"""
ab = PathFactory.create(name="AB", geom=LineString((0, 0), (1, 0)))
PathFactory.create(name="CD", geom=LineString((2, 0), (2, 1)))
poi = POIFactory.create(no_path=True, offset=1)
e1 = TopologyFactory.create(no_path=True)
PathAggregationFactory.create(path=ab, topo_object=e1, start_position=0.5, end_position=1)
poi.add_path(ab, start=0.5, end=0.5)
poi.save()
self.assertTrue(almostequal(1, poi.offset))
self.assertEqual(poi.geom, Point(0.5, 1.0, srid=2154))
ab.delete()
poi.reload()
e1.reload()
self.assertEqual(len(Path.objects.all()), 1)
self.assertEqual(e1.deleted, True)
self.assertEqual(poi.deleted, False)
self.assertTrue(almostequal(1.5, poi.offset))