zoukankan      html  css  js  c++  java
  • 要素类属性内容全角换半角

    近期天地图项目处理数据时由于原始数据质量较差,属性字段中多有全角字符,带来后期处理与开发不便,因此做了个属性全角换半角的脚本如下

    经验:Unicode处理

    # -*- coding: utf-8 -*-

    __author__ = 'tanshuai'

    import arcpy

    from arcpy import env

    fullCorner = ['0' , '1' , '2' , '3' , '4' ,

    '5' , '6' , '7' , '8' , '9' ,

    'A' , 'B' , 'C' , 'D' , 'E' ,

    'F' , 'G' , 'H' , 'I' , 'J' ,

    'K' , 'L' , 'M' , 'N' , 'O' ,

    'P' , 'Q' , 'R' , 'S' , 'T' ,

    'U' , 'V' , 'W' , 'X' , 'Y' ,

    'Z' , 'a' , 'b' , 'c' , 'd' ,

    'e' , 'f' , 'g' , 'h' , 'i' ,

    'j' , 'k' , 'l' , 'm' , 'n' ,

    'o' , 'p' , 'q' , 'r' , 's' ,

    't' , 'u' , 'v' , 'w' , 'x' ,

    'y' , 'z' , '-' , ' ' , ':' ,

    '.' , ',' , '/' , '%' , '#' ,

    '!' , '@' , '&' , '(' , ')' ,

    '<' , '>' , '"' , ''' , '?' ,

    '[' , ']' , '{' , '}' , '\' ,

    '|' , '+' , '=' , '_' , '^' ,

    '¥' , ' ̄' , '`']

    halfCorner = ['0', '1', '2', '3', '4',

    '5', '6', '7', '8', '9',

    'A', 'B', 'C', 'D', 'E',

    'F', 'G', 'H', 'I', 'J',

    'K', 'L', 'M', 'N', 'O',

    'P', 'Q', 'R', 'S', 'T',

    'U', 'V', 'W', 'X', 'Y',

    'Z', 'a', 'b', 'c', 'd',

    'e', 'f', 'g', 'h', 'i',

    'j', 'k', 'l', 'm', 'n',

    'o', 'p', 'q', 'r', 's',

    't', 'u', 'v', 'w', 'x',

    'y', 'z', '-', ' ', ':',

    '.', ',', '/', '%', '#',

    '!', '@', '&', '(', ')',

    '<', '>', '"', '\'','?',

    '[', ']', '{', '}', '\\',

    '|', '+', '=', '_', '^',

    '¥','~', '`']

    def replaceCharacter(fldValueText):

        for full in fullCorner:

            if fldValueText.find(full) > -1:

                index = fullCorner.index(full)

                half = halfCorner[index];

                fldValueText = fldValueText.replace(full, half)

        print fldValueText

        return fldValueText

    env.workspace = "E:\\test2"

    length = len(fullCorner)

    cursor = arcpy.UpdateCursor("test3.shp")

    try:

        for row in cursor:

            fieldList = arcpy.ListFields("test3.shp")

            for field in fieldList:

                if field.type == "String":

                    value = row.getValue(field.name)

                    valueTxt = value.encode('utf-8')

                    if len(valueTxt) > 0:

                        print valueTxt

                        resultValue = replaceCharacter(valueTxt)

                        row.setValue(field.name, resultValue)

                        cursor.updateRow(row)

                        print resultValue

                    else:

                        continue

    except Exception,e:

        print("错误"+e)

    finally:

        del row,cursor

    print("complete!")

  • 相关阅读:
    数组从文件中读取(接上问题)
    符合json格式要求的字符串转化为json字符串
    json-lib --->入门
    XStream-->别名;元素转属性;去除集合属性(剥皮);忽略不需要元素
    Ajax案例5-->省市联动
    Ajax案例4-->接收后台传递的XML数据
    Ajax案例3-->判断用户名是否被占用
    Ajax案例2-->POST请求
    Ajax案例1-->GET请求
    SecureCRT连接VMWare中的linux系统相关配置
  • 原文地址:https://www.cnblogs.com/Brune/p/3113119.html
Copyright © 2011-2022 走看看