FME 應用cad處理

codedecipher發表於2020-11-13

座標串生成cad檔案

import fme
import fmeobjects
from fmeobjects import FMELogFile
from fmeobjects import FMEFeature, FMEPoint, FMELine, FMEGeometryTools,FMECurve,FMEPolygon


# Template Function interface:
def processFeature(feature):
    pass

# Template Class Interface:
class FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
   
        List_counter = feature.getAttribute('_element_count')
        
        points = []
        for i in range(int(List_counter)):
            x = feature.getAttribute('_list{'+str(i)+'}.X')
            y = feature.getAttribute('_list{'+str(i)+'}.Y')
            
            point = FMEPoint(x,y)
            
            #points.append(point)
            
            points.append((x,y))
            #FMELogFile().logMessageString(str(point))
        
        curve = FMELine(points)
        
        ploygon = FMEPolygon(curve)
              
        #FMELogFile().logMessageString(str(fa))
        
        ft = FMEFeature()
        ft.setGeometry(ploygon)
        self.pyoutput(ft)
    def close(self):
        pass
        

合併cad圖層

import fme
import fmeobjects
import re

# Template Function interface:
def processFeature(feature):
    pass

# Template Class Interface:
class FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        
        name = feature.getAttribute('fme_feature_type')
        
        match = [["高壓|Kv","高壓線"],["W|倉儲","倉儲用地"],["公路","公路"],["ROAD|RD|S1|S3|交通|路","道路"],["R|居住","居住用地"],["G2|防護綠地","防護綠地"],["M|工業","工業用地"],["G1|公共綠地","公共綠地"],["G3|S2|廣場","廣場用地"],["教育","教育科研用地"],["RIVER|E1|河","河流"],["B1|CR|C2|市場|商業","商業用地"],["B4","公用設施營業用地"],["A3|中小學","中小學用地"],["U|C9|公共設施|市政","市政用地"],["A2|C3|文體|文化","文化娛樂"],["C4|體育","體育用地"],["S3|停車","停車場"],["C7|文物|古蹟","文物古蹟"],["A1|C1|行政|辦公","行政辦公用地"],["A5|C5|醫療|衛生","醫療衛生用地"],["村鎮|村莊","村莊"],["儲備","備用地"]]
        
        
        for i in range(0,len(match)):
            
            reg = re.search(match[i][0],name)
            if(reg!=None ):
                feature.setAttribute('fme_feature_type',match[i][1])
                self.pyoutput(feature)
                break
    def close(self):
        pass

相關文章