用python寫fme資料轉換指令碼

來源:互聯網
上載者:User

學了幾天的python和FME Objects,發現之間教程裡的很多個物件已經過時了,而且文法和vb相差比較大,但概念還是一樣的,下面寫一段python代碼,將這幾天學習的對象聯絡一下,下面的代碼功能是讀schema feature和data feature,並顯示feature的屬性和關聯的座標系,並使用FMEDialog對象來設定源和目標,並做格式轉換,一下代碼經過測試,運行正常。

import pyfme

FME_GEOMETRY_TYPE={
    0:"FME_GEOM_UNDEFINED",
    1:"FME_GEOM_POINT",
    2:"FME_GEOM_LINE",
    4:"FME_GEOM_POLYGON",
    8:"FME_GEOM_DONUT",
    256:"FME_GEOM_PIP",
    512:"FME_GEOM_AGGREGATE",
    }

session=pyfme.FMESession()
dialog=session.createDialog()

pr=dialog.sourcePrompt("","")
reader=pyfme.FMEReader(pr[0])
reader.open(pr[1],pr[2])

pw=dialog.destPrompt("","")
writer=pyfme.FMEWriter(pw[0])
writer.open(pw[1],pw[2])

theend=True
while theend:
    feature=pyfme.FMEFeature()
    theend=reader.readSchema(feature)
    if theend:
        print "\n------------%s----------" % "Schema Feature Infomation"
        print "Geometry Type: " + str(FME_GEOMETRY_TYPE[feature.getGeometryType()])
        print "Feature Type: " + str(feature.getFeatureType())
        print "CoordinateSystem Name: " + feature.getCoordinateSystem()
        csm=pyfme.FMECoordSysManager()
        csp=csm.getOGCCoordSys(feature.getCoordinateSystem())
        print "CoordinateSystem Information:\n%s\n" % csp
        writer.addSchema(feature)

theend=True
while theend:
    feature=pyfme.FMEFeature()
    theend=reader.read(feature)
    if theend:
        print "\n------------%s----------\n" % "Data Feature Infomation"
        print "GeometryType: " + str(FME_GEOMETRY_TYPE[feature.getGeometryType()])
        print "FeatureType: " + str(feature.getFeatureType())
        print "CoordinateSystem: " + feature.getCoordinateSystem()
        print "CoordinateSystem List:\n%s\n" % feature.getCoordinates()
        writer.write(feature)

reader.close()

writer.close()

del reader

del writer

運行環境 FME DESKTOP 2009 ,pyfme for python 2.5,python 2.5

 

轉載請註明文章來源 http://www.cnblogs.com/booolee

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.