本文整理汇总了Python中Translator.Translator.get_translator方法的典型用法代码示例。如果您正苦于以下问题:Python Translator.get_translator方法的具体用法?Python Translator.get_translator怎么用?Python Translator.get_translator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translator.Translator
的用法示例。
在下文中一共展示了Translator.get_translator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import get_translator [as 别名]
def test():
import os
opts = DefaultOptions()
opts.logger = Logger()
opts.logger.start_debug()
opts.sourceFile = os.path.abspath("./testdata/test.gdb/TRAILS_ln")
opts.outputFile = "./testdata/test_trails.osm"
opts.translator = Translator.get_translator("trails")
opts.datasetKey = get_pk_name(opts, 'nps:source_system_key_value')
makeosmfile(opts)
示例2: test
# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import get_translator [as 别名]
def test():
logger = Logger()
logger.start_debug()
featureclass = './tests/test.gdb/roads_ln'
logtable = './tests/test_road_sync.csv'
translator = Translator.get_translator('parkinglots')
api_server = OsmApiServer('test')
api_server.logger = logger
api_server.logger.start_debug()
xml = None
try:
xml = arc_build_osm_change_xml(featureclass, logtable, translator, api_server, logger)
except ValueError as e:
print e
if xml is not None:
data = Et.tostring(xml, encoding='utf-8')
osmchangefile = './tests/test_road_update.osm'
with open(osmchangefile, 'w', encoding='utf-8') as fw:
fw.write(data)
print "Done."
示例3: validation_test
# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import get_translator [as 别名]
def validation_test():
import OsmApiServer
from Translator import Translator
server = OsmApiServer.OsmApiServer('test')
sde = 'Database Connections/akr_facility_on_inpakrovmais_as_domainuser.sde'
test_list = [('./testdata/test.gdb/roads_ln', 'roads'),
('./testdata/test.gdb/trails_ln', 'trails'),
('./testdata/test.gdb/multipoints', 'generic'),
('./testdata/test.gdb/parkinglots_py', 'parkinglots'),
('./testdata/test.gdb/poi_pt', 'poi'),
('./testdata/test.gdb/trails_ln', 'none'),
('./testdata/test.gdb/trails_ln', None),
(sde + '/akr_facility.GIS.TRAILS_ln', 'trails'), # crashes python: da.cursor in ArcGIS 10.3 32bit
(sde + '/akr_facility.GIS.ROADS_ln', 'roads')
]
for src, tname in test_list:
print '**** Testing', src, 'with', tname
if tname is None:
translator = None
else:
translator = Translator.get_translator(tname)
print valid4upload(src, server, translator)
print valid4sync(src, translator)
示例4: cmdline
# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import get_translator [as 别名]
def cmdline():
# Setup program usage
usage = """%prog [Options] SRC LOG DST
or: %prog --help
Creates a file called DST from changes in SRC compared to LOG.
SRC is an ArcGIS feature class
LOG is an ArcGIS table that describes the features sent to places
DST is a OSM change file
"""
parser = optparse.OptionParser(usage=usage)
parser.add_option("-t", "--translator", dest="translator", type=str, help=(
"Name of translator to convert ArcGIS features to OSM Tags. " +
"Defaults to Generic."), default='generic')
parser.add_option("-s", "--server", dest="server", type=str, help=(
"Name of server to connect to. I.e. 'places', 'osm', 'osm-dev', 'local'." +
"Defaults to 'places'. Name must be defined in the secrets file."), default='places')
parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
help="Write processing step details to stdout.")
parser.add_option("-d", "--debug", dest="debug", action="store_true",
help="Write debugging details to stdout.")
parser.add_option("--changeset-id", dest="changesetId", type=int,
help="Sentinal ID number for the changeset. Only used " +
"when an osmChange file is being created. " +
"Defaults to -1.", default=-1)
parser.set_defaults(verbose=False, debug=False)
# Parse and process arguments
(options, args) = parser.parse_args()
if len(args) < 3:
parser.error(u"You must specify a source, log and destination")
elif len(args) > 3:
parser.error(u"You have specified too many arguments.")
# Input and output file
featureclass = args[0]
logtable = args[1]
osmchangefile = args[2]
if os.path.exists(osmchangefile):
parser.error(u"The destination file exist.")
# Translator
translator = Translator.get_translator(options.translator)
# API Server
if options.server:
api_server = OsmApiServer(options.server)
else:
api_server = OsmApiServer('places')
online = api_server.is_online()
if api_server.error:
print api_server.error
sys.exit(1)
if not online:
print "Server is not online right now, try again later."
sys.exit(1)
if not api_server.is_version_supported():
print "Server does not support version " + api_server.version + " of the OSM"
sys.exit(1)
logger = None
if options.verbose or options.debug:
logger = Logger()
if options.debug:
logger.start_debug()
api_server.logger = logger
# Build Change XML
xml = None
try:
xml = arc_build_osm_change_xml(featureclass, logtable, translator, api_server, logger)
except (ValueError, TypeError) as e:
print e
# Output results
if xml:
# TODO: do exception checking
data = Et.tostring(xml, encoding='utf-8')
with open(osmchangefile, 'w', encoding='utf-8') as fw:
fw.write(data)
print "Done."
示例5: makeosmfile
# 需要导入模块: from Translator import Translator [as 别名]
# 或者: from Translator.Translator import get_translator [as 别名]
def makeosmfile(options):
"""
Save or return (as an xml string) an OsmChange File.
:rtype : None, or (error string, None) or (None, xml_string) on success
:param options: a DefaultOptions() object with the input and control parameters
:return: (basestring, basestring)
"""
# Set/Reset/Clear the global state (list of geometries and features)
Geometry.elementIdCounter = options.id
Geometry.geometries = []
Feature.features = []
global vertices
vertices = {}
try:
if options.outputFile is None:
options.logger.info(u"Preparing to convert '{0:s}'."
.format(options.sourceFile))
else:
options.logger.info(u"Preparing to convert '{0:s}' to '{1:s}'."
.format(options.sourceFile, options.outputFile))
except AttributeError:
pass
if not options.translator:
try:
options.logger.info(u"Loading translator '{0:s}'.".format(options.translationMethod))
except AttributeError:
pass
translator = Translator.get_translator(options.translationMethod)
if translator.translation_module is None:
try:
options.logger.error(translator.error)
except AttributeError:
pass
else:
try:
options.logger.info(u"Successfully loaded '{0:s}' translation method ('{1:s}').".format(
translator.name, translator.path))
for function in translator.function_status:
options.logger.info(u"{1:s} method for function '{0:s}'".format(
function, translator.function_status[function]))
except AttributeError:
pass
options.translator = translator
parsedata(options)
if options.mergeNodes:
mergepoints(options)
if options.mergeWayNodes:
mergewaypoints(options)
options.translator.transform_pre_output(
Geometry.geometries, Feature.features)
error, data = output_xml(options)
if options.outputFile:
with open(options.outputFile, 'w', encoding='utf-8') as fw:
fw.write(data)
try:
options.logger.info(u"Wrote {0:d} elements to file '{1:s}'"
.format(-1 * Geometry.elementIdCounter, options.outputFile))
except AttributeError:
pass
else:
try:
options.logger.info(u"Returning {0:d} converted elements".format(-1 * Geometry.elementIdCounter))
except AttributeError:
pass
return error, data