Use python to write the fme data conversion script

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.