坐标串生成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,有坐标点。
障碍:红线并不完全闭合,其他红线的干扰
解决思路:特征筛选,坐标点在面上最多的面判定为目标红线