span8
斯潘4
I have a dataset containing a registry of addresses,(street,数,postal code etc.,以及一个包含输入信息的附加字段,例如24-44,也就是说,24-44之间的所有户数都包括在内,或-44等。
我需要将这些地址与另一个官方地址数据集(通过FeatureMerge)匹配,我希望能够找到24到44之间所有数字的匹配项。
I've managed to "mine" the text in the additional field and I've created a new attribute containing the upper range number (in this case 44 )
现在,I just need to have features that have the housenumbers that fall between the lower and upper range,and for this I obviously need a python script that can be used within the "pythoncaller" transformer and then run them through the feature merger.
I know a little bit of Python,但我所知道的一点显然不足以在FME中转换为python。
我知道我需要定义一个函数来注册这个数字范围,并且有一个for循环,它声明对于该范围内的每个数字,都会创建一个功能,并且地址包含该数字范围内的家庭号码。The function also needs to keep track of even and odd numbers.If the upper and lower range aren't both odd,或者两者兼而有之,它可以为该范围内的每个数字创建地址。如果不是,它只需要创建具有奇数或偶数个房间号的功能。
我希望我的解释足够清楚。Can someone help me along the way?写整个剧本不是必要的,因为我也喜欢自己去弄清楚。
下面是如何从戴维德里奇在蟒蛇中。
我在代码中添加了必要的样板文件:
import fmeobjectsclass split_house_numbers(): def input(self,特征):houseNumbers是列名houseNumbers=24-44 houseNumbers=feature.getattribute('houseNumbers')转换为列表spilt=[24,44]houseSplit=houseNumbers.split(“-”)如果len(houseSplit)==2:必须从文本转换为int startnum=int(houseSplit[0])#24 finishNum=int(housesplit[1])44测试startNum和finishNum或奇数或偶数,如果startNum%2==finishNum%2,则使用modulo:range(startNum、finishNum、stepsize)range(24,44,2)for x in range(startNum、finishNum、2):new_feature=feature.clone()new_feature.setattribute('newhouseNumber',x)这将输出一行以及所有其他列这将为24创建一个新记录,26、28、30…42 44 self.pyoutput(new_feature) else: # if its (24,27,1) for X in range(StartNum,FinishNum,1): new_feature = feature.clone() new_feature.setAttribute('newhousenumber',X) # would create a new record for 24,25,26,27 self.pyoutput(new_feature) else: feature.setAttribute('newhousenumber',houseSplit[0]) self.pyoutput(feature)
按照以下步骤配置pythoncaller:
If a feature enters containing户主=‘24—44’,然后将退出10个功能,其值如下:新数:
You can then pass these 10 features into e.g.特色合并。
您好!@门门戈,I'm still unclear what your goal is.
Do you need to create all the values within the range,或者需要测试特性的属性值是否在指定范围内?你的目的是什么?
导入fmeObjectsClass House_numbers():
def input(self,特点:
startnum=feature.getattribute('houseNumber')
StartNum = int(StartNum)
finishinum=feature.getattribute('上限\u编号')
finishNum=整数(finishNum)
如果startNum%2==finishNum%2:
对于范围内的x(startNum、finishNum、2):
新功能=feature.clone()
new_feature.setattribute('newhouseNumber',x)
self.pyoutput(new_feature)
其他:
for X in range(StartNum,FinishNum,1):
新功能=feature.clone()
new_feature.setattribute('newhouseNumber',x)
self.pyoutput(new_feature)
您好!高桥
I would really prefer to use Python since my workbench is already relatively large and going the other route would add even more transformers.import fmeobjectsclass house_numbers():def input(self,功能):startnum=feature.getattribute('housenumber')startnum=int(startnum)finishnumtext=feature.getattribute('upper_range_number')仅当finishnumtext有值if finishnumtext:finishnum=int(finishnumtext)if startnum%2==finishnum%2:对于范围内的x(startnum,finishnum,2):new_feature=feature.clone()new_feature.attribute('newhousenumber',x)self.pyoutput(new_feature)else:对于范围内的x(startnum,finishinum,1):new_feature=feature.clone()new_feature.setattribute('newhousenumber',x)self.pyoutput(new_feature)else:self.pyoutput(feature)
I admit I would probably do this in python myself,but I though I would try to do it in pure FME,and it's relatively straightforward (No looping required),虽然在生产中,我会增加合法价值的额外检查。
kb-地址.fmw
您可以在没有任何python或tcl的情况下做到这一点。(or witohout SQL trough the inlinequerier.)
使用StringReplacer;for instance search for (\d+)-(\d+) on the attribute with AllMatches (AM) and submatches (SM)
Test Value(SM{0} and Value SM{1} to check parity: mod(SM{0},2) = 0 AND mod(SM{1},2) = 0 for parity 2 and rest for 1.
分
按平价计算的sm 1-sm 0。Clone record by result,重新计算房屋编号
sm 0+_copynum*@值(奇偶校验)。
For including house letters it easier to convert them to their character code.
您好!@门门戈
Great choice in task as it covers quite a few python basics!
#houseNumbers是列名houseNumbers=24-44 houseNumbers=feature.getattribute('houseNumbers')转换为列表spilt=[24,44]houseSplit=houseNumbers.split(“-”)如果len(houseSplit)==2:必须从文本转换为intStartNum=int(houseSplit[0])24finishNum=int(houseSplit[1])44如果startNum和finishNum或同时测试奇数和奇数或者甚至使用moduloif startnum%2==finishinnum%2:range(startnum,finishinnum,stepsize)range(24,44,2)for x in range(startnum,finishinnum,2):feature.setattribute('newhousenumber',x)这将输出一行以及所有其他列将为24创建一个新记录,26、28、30…42 44self.pyoutput(feature)else:# if its (24,27,1)for X in range(StartNum,FinishNum,1):feature.setAttribute('newhousenumber',X)# would create a new record for 24,25,26,27self.pyoutput(feature)else:feature.setAttribute('newhousenumber',houseSplit[0])self.pyoutput(feature)
这应该是输入函数的主要部分
记住在本例中暴露新列“newhousenumber”
import fme
导入FmeObjects
#Define StartNum and Finishnum
StartNum = feature.getAttribute('housenumber') #24
finishNum=feature.getattribute(上限\u范围\u编号)44
#The rest stays more or less the same,except for the last else statement in your script.For now,我刚刚把它编辑了出来。测试StartNum和FinishNum或奇数或偶数,使用moduloif startNum%2==FinishNum%2:range(StartNum,FinishNum,StepSize)range(24,44,2)for x in range(StartNum,FinishNum,2):feature.setattribute('NewHouseNumber',X)这个输出的行与所有其他列都将创建一个新的记录RD为24,26、28、30…42 44 self.pyoutput(feature)else:如果范围内x的(24,27,1)(startnum,finishinnum,1):feature.setattribute('newhousenumber',x)将为24,25,26,27 self.pyoutput(feature)else:feature.setattribute('newhousenumber',housesplit[0])self.pyoutput(feature)
你好,在这个示例中,工具makereferenceaddress有许多pythoncaller的示例,用于分解许多类型的隐含子地址单元范围,您可以很容易地将其调整为房屋编号:
http://pm.maps.arcgis.com/home/item.html?ID=67FD0EAA9AA24D9D97FD93AEFE0585B8
I think I'm attaching the right source here:
注意,如果你需要尊重对等,增量将是2,not 1,in the code.
功能比较验证1 Answer
Running PyQGIS in FME PythonCaller transformer?2 Answers
python函数枚举2 Answers
有人有将我的python代码更新为python 3的提示吗?2 Answers
Use PythonCaller to get list of files in directory on FTP site6答
?2019安全亚搏在线软件公司|合法的