zoukankan      html  css  js  c++  java
  • 用python写fme数据转换脚本

    学了几天的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

  • 相关阅读:
    对一个或多个实体的验证失败。有关详细信息,请参阅“EntityValidationErrors”属性。
    Java基础学习笔记四 Java基础语法
    Java基础学习笔记一 Java介绍
    Java基础学习笔记二 Java基础语法
    Elasticsearch重要配置
    Elasticsearch配置
    Elasticsearch安装详解
    Elasticsearch文档查询
    Elasticsearch索引和文档操作
    Angular4项目,默认的package.json创建及配置
  • 原文地址:https://www.cnblogs.com/booolee/p/1550003.html
Copyright © 2011-2022 走看看