Skip to content

Instantly share code, notes, and snippets.

@AlexArcPy
Created April 20, 2016 19:50
Show Gist options
  • Save AlexArcPy/6a20812f88f71f3e8dd3e6073477cfd6 to your computer and use it in GitHub Desktop.
Save AlexArcPy/6a20812f88f71f3e8dd3e6073477cfd6 to your computer and use it in GitHub Desktop.
Calling fmeobjects with Python: FMEUniversalReader and FMEUniversalWriter
import sys
sys.path.append(r"C:\Program Files (x86)\FME\fmeobjects\python27")
from fmeobjects import *
import os
root_folder = r"C:\GIS\fme"
#----------------------------------------------------------------------
def read_features():
"""Reads all features within input shapefile, projects it and writes
to the output shapefile"""
try:
reader = FMEUniversalReader("SHAPE", False, [])
reader.open(os.path.join(root_folder,r"Data\BikePaths_L.shp"),
['UPPER_CASE_ATTR_NAMES','NO'])
writer = FMEUniversalWriter("SHAPE",{})
writer.open(os.path.join(root_folder,"out"),
['UPPER_CASE_ATTR_NAMES','NO'])
schemaFeature = reader.readSchema()
while schemaFeature != None:
writer.addSchema(schemaFeature)
schemaFeature = reader.readSchema()
feature = reader.read()
while feature != None:
feature.reproject("EPSG:3857")
writer.write(feature)
feature = reader.read()
reader.close()
writer.close()
except FMEException, err:
print "FMEException: %s" % err
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment