西班牙
斯潘4
你好!我花了整整5天的时间,没有开玩笑,试图达到这个结果,而且……我还是没有。考虑到这其实一点也不重要,而且我显然不能单独留下来,我终于让步了,加入了这个社区,看看你们中是否有人能帮我(用更少的时间)……亚搏国际在线官网
我想创造…相邻点的网络。输入是建筑物中心点的形状文件(通过参数指定起点);所需的输出是这些相同的点,属性将它们按以下顺序排列:
a)A点
b)离A点最近的点
c)离B点最近的点,不包括A点
d)离C点最近的点,不包括A和B
e)距离D点最近的点,不包括A、B和C
……等等。找到最近的邻居,但不包括最近的点,最近的点还不是链上较早的点。
实际上,我制作了一个循环自定义转换器,它几乎完全为我做到了这一点——然而,它严重依赖于neighborfinder transformer,它是一个阻塞的转换器,并且变得太慢太快。我知道我如何使用Python来完成这项工作,但是我的所有想法也需要比FME更灵活的循环(因为我想循环遍历所有的特性,但不能像Python那样)。内部一个循环变压器可以做到……)
即使我打这个我有更多的想法尝试,但,再次,我花了太多的时间在这上面,我不得不放弃。如果其他人有任何想法如何在流程中使用最少的手动步骤来完成此操作…我很想听!谢谢!:)
嗨@jdmiller95你的问题有多相似https://knowledge.亚搏在线safe.com/questions/45800/finding-neighbours-with-1-to-1-relationship.html吗?这些点已经有特定的顺序了吗?到A点最近的点可能是B点吗?总体目标是将点对在一起,还是创建每个点的单一网络,其中a点是种子点?
尝试在pythoncaller中使用以下代码来保留点属性:
从scipy。spatial import distance import fmeobjects def get_closest_node_index(node, nodes): return distance.cdist([node], nodes).argmin() class CreatePointTopology(): def __init__(self): self.nodes = [] self.attribs = [] def input(self, feature): node = feature.getCoordinate(0) self.nodes.append(node) attribs = {k:feature.getAttribute(k) for k in feature.getAllAttributeNames() if not k.startswith('fme_')} self.attribs.append(attribs) def close(self): from_node = self.nodes.pop(0) from_attribs = self.attribs.pop(0) while len(self.nodes) >= 1: output = fmeobjects.FMEFeature() to_node_idx = get_closest_node_index(from_node, self.nodes) to_node = self.nodes[to_node_idx] to_attribs = self.attribs[to_node_idx] for f in from_attribs.keys(): output.setAttribute('from_'+f, from_attribs[f]) for t in to_attribs.keys(): output.setAttribute('to_'+t, to_attribs[t]) output.addCoordinate(from_node[0], from_node[1]) output.addCoordinate(to_node[0], to_node[1]) from_node = self.nodes.pop(to_node_idx) from_attribs = self.attribs.pop(to_node_idx) self.pyoutput(output)
每个输出段将保留以“from_”或“to_”为前缀的点属性,例如。从具有属性的点出发的段X=1到一个带有属性的点X=2,将产生一个段withfrom_X= 1,to_X= 2。
如果您仍然需要使用LineCombiner,请确保启用“Generate List”,以避免丢失输出属性。
我们可以使用scipy做一些类似于NeighborhoodFinder的事情,使得“定制”行为和循环节点列表成为可能,同时消除之前的匹配。以下是来自PythonCaller的代码:
从scipy。spatial import distance import fmeobjects def get_closest_node_index(node, nodes): return distance.cdist([node], nodes).argmin() class CreatePointTopology(): def __init__(self): self.nodes = [] def input(self, feature): node = feature.getCoordinate(0) self.nodes.append(node) def close(self): current_node = self.nodes.pop(0) while len(self.nodes) >= 1: output = fmeobjects.FMEFeature() idx = get_closest_node_index(current_node, self.nodes) output.addCoordinate(current_node[0], current_node[1]) output.addCoordinate(self.nodes[idx][0], self.nodes[idx][1]) current_node = self.nodes.pop(idx) self.pyoutput(output)
主要的假设是所有的点都是2D的,第一个点是起始点。您需要确保至少有两个输入点。
我还附加了一个测试工作区(FME 2019.0.2.0)来显示上下文中的代码:CreatePointTopology.fmwt
这真是太棒了,谢谢!!我想知道……是否有一种方法可以将点的属性作为连接它们的线的属性?也就是说,对于我的目的,记录/查看这个特定的线段是连接Adams House和Smith House的能力?(我会在代码上戳一下,试着自己找出答案……but I'm just so close to my breaking point with brain power towards this project!)
当然,您可以简单地将必要的属性作为字典添加到self.nodes中。例14行:
my_attr1 = feature.getAttribute('my_attr1') node_dict = {node': node, 'my_attr1': my_attr1}
然后相应地更改代码的其余部分。
我不愿承认……but I have no idea what to change in the rest of the code to make things work with these lines added in :/ turns out I'm not as comfortable with Python as I tend to think, and I just can't seem to sort out what to do with later parts of the code to make sure it's still calling the right part of the dictionary or whatever?也只是因为我实际上不理解其余的代码/它调用什么属性/等等…你能在添加属性时提供更多的指导吗?
为了尝试理解这个问题,我使用PythonCaller做了一个小的原型。给定20个随机点,以蓝点为起点,返回如下“拓朴”:
这个符合你的要求吗?
?2019安全亚搏在线软件公司|合法的