FME 应用cad处理

该博客内容涉及使用Python处理CAD文件中的坐标数据,生成CAD几何对象如线和多边形,并进行图层合并操作。具体包括从特征中提取坐标点生成线条和多边形,根据特征类型匹配并修改图层名称,以及设置和提取特定属性信息。此外,还讨论了如何从CAD坐标点中筛选出红线特征,强调了特征筛选和坐标点判断的条件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

坐标串生成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

输出信息

from fmeobjects import FMELogFile

FMELogFile().logMessageString("hello world")

创建属性

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


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

# Template Class Interface:
class FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
   
        path = feature.getAttribute('autocad_xrecord_data_list{1}')
        
        path = path.replace("string:","")
        path = path.replace(".txt","")
        
        str_list = re.split(",|,",path)
        
        FMELogFile().logMessageString(str(str_list))
        try:
            feature.setAttribute('agent',str(str_list[0]))
            feature.setAttribute('landid',str(str_list[1]))
            feature.setAttribute('projname',str(str_list[2]))
        except Exception as e:
            FMELogFile().logMessageString(str(e))
        pass
        self.pyoutput(feature)
        
    def close(self):
        pass
        


读取多个cad坐标点生成红线

import fme
import fmeobjects
# Template Function interface:
# When using this function, make sure its name is set as the value of
# the 'Class or Function to Process Features' transformer parameter

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

# Template Class Interface:
# When using this class, make sure its name is set as the value of
# the 'Class or Function to Process Features' transformer parameter
class FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        #self.pyoutput(feature)
        
        List_counter = feature.getAttribute('_element_count')
        
        xs = []
        ys = []
        for i in range(int(List_counter)):
            
            text = feature.getAttribute('_list{'+str(i)+'}.autocad_text_string')
            
            if(re.search("X *=",text)!=None):
                xs.append(float(text.split("=")[1]))           
            if(re.search("Y *=",text)!=None):
                ys.append(float(text.split("=")[1]))
            
        points = []
        for i in range(0,len(xs)):
            points.append((ys[i],xs[i]))
            
        curve = FMELine(points)
        ploygon = FMEPolygon(curve)
        
        FMELogFile().logMessageString(str(xs))
         
        ft = FMEFeature()
        ft.setGeometry(ploygon)
        ft.setAttribute('path',str(feature.getAttribute('autocad_source_filename')))
        self.pyoutput(ft)
             
    def close(self):
        pass

在这里插入图片描述

提取红线

提取条件:红色,宽度大于0,有坐标点。
障碍:红线并不完全闭合,其他红线的干扰
解决思路:特征筛选,坐标点在面上最多的面判定为目标红线

在这里插入图片描述
在这里插入图片描述

通过WorkplaceRunner 一个一个文件进行处理
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值