After learning python and FME Objects for a few days, I found that many Objects in the tutorial are outdated, and the syntax and vb are quite different, but the concept is the same. Below I will write a piece of python code, link the objects learned over the past few days. The following code function is to read schema feature and data feature, display the attributes of feature and the associated coordinate system, and use the FMEDialog object to set the source and target, the code is tested and runs normally.
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
Running Environment fme desktop 2009, pyfme for python 2.5, python 2.5
Reprinted please indicate the source http://www.cnblogs.com/booolee