How does arcgis solve Chinese problems when using python scripts for field calculation,

Source: Internet
Author: User

How does arcgis solve Chinese problems when using python scripts for field calculation,

I. Introduction

Open an Attribute Table of a layer in arcgis to calculate a field in the Attribute Table. However, in general, the field calculator interface provided by arcgis is used to assign values to simple Q &, the script is not used to perform logical operations on field values. Since I have been learning python scripts recently, I have just met another friend who needs my assists (using arcgis graphics. I thought it could be done with ease. I didn't expect to move the stone to my feet. Let's talk about how I got my feet.

Ii. Problem description: change the value of "Hunan" in the test field to "Hunan ".

This logic is quite simple. Use python to write a corresponding method:

Def cal (value): if (value = 'hunan '): return value + 'province' else: return value

Run python code in arcgis, for example:

Note: The method to reference attribute fields is! Test!

Click "OK". An error is displayed. The error message is not displayed. Finally, you have searched for the information. It turns out that transcoding is required when python uses Chinese.

Iii. Solutions

So we can transcode the text in the above Code. The changed code is as follows:

Def cal (value): if (value = 'hunan '. decode ('utf-8'): return value + 'save '. decode ('utf-8') else: return value

Now there is no error. You need to add the decode ('utf-8') method to encode the strings "Hunan" and "Province.

This solves the problem of Processing Chinese characters using python scripts in arcgis.

Iv. Summary

If you use a python script in arcgis, You need to perform decode ('utf-8') transcoding on it as long as you encounter Chinese characters.

In addition, the python script editor provided in arcgis is extremely difficult to use. Therefore, you can edit the logic code in python, copy the code, and run it quickly and effectively.

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.