POST
|
Hi andrew! Thanks for your reply. Unfortunately the commands you sent me do not solve my problem. Vietnamese Script is a kind of awkward coded. So I am not sure if there is a built in solution for this. I just found the following link descriping vn character sets. http://vietunicode.sourceforge.net/ Most important for me is the TCVN3. So I could do a dictionary and look up every single character and replace it by the corresponding unicode character. However from my feeling I would say that this would slow down my code dramatically and doesn't look like the brightest solution. Besdides I don't know how to step through the characters as some TCVN3 character sets have one other two characters to symbolize 1 unicode character (e.g.â =© but �? = Aµ). Any suggestions? I also came across an old script dealing with a similar problem in 9.3. but though i modified it I can not get it to run in arcgis10. I keep getting an error stating 'Result' object has no attribute 'GetOutput' # Simple script for conversion of Vietnamese encoding
import arcpy
from arcpy import env
import os
import string
import csv
arcpy.env.overwriteOutput = True
def Convert(str,s,d):
global _Unicode, _TCVN3, _KhongDau
result = u''
for c in str:
idx = s.find(c)
if idx >= 0:
c = d[idx]
result += c
return result
# Array of characters (Using Tuple instead of List)
_Unicode = (
#'�??�??�?�?�??�??�??�?ª�?Š�??�??�??�??�??�??'
u'â�?�?�?�?Đê�?ô�?ơƠưƯ'
#u'\xe2\xc2\u0103\u0102\u0111\u0110\xea\xca\xf4\xd4\u01a1\u01a0\u01b0\u01af'
#'�??�??�??�??���??�?�?���������Ẫ��������ẵ���'
u'áÁà�?ảẢã�?ạẠấẤầẦẩẨẫẪậẬắẮằẰẳẲẵẴặẶ'
#u'\xe1\xc1\xe0\xc0\u1ea3\u1ea2\xe3\xc3\u1ea1\u1ea0\u1ea5\u1ea4\u1ea7\u1ea6\u1ea9\u1ea8\u1eab\u1eaa\u1ead\u1eac\u1eaf\u1eae\u1eb1\u1eb0\u1eb3\u1eb2\u1eb5\u1eb4\u1eb7\u1eb6'
#'�??�??�??�??áº?Ẻáº?áº?áº?áº?áº?áº?á??á??á?�?á??á??á??á??á??�??�??�??�?�?á??á??�??�??á??á?Š'
u'é�?è�?ẻẺẽẼẹẸếẾề�?�?�?�?�?�?�?íÍì�?�?�?ĩĨ�?�?'
#u'\xe9\xc9\xe8\xc8\u1ebb\u1eba\u1ebd\u1ebc\u1eb9\u1eb8\u1ebf\u1ebe\u1ec1\u1ec0\u1ec3\u1ec2\u1ec5\u1ec4\u1ec7\u1ec6\xed\xcd\xec\xcc\u1ec9\u1ec8\u0129\u0128\u1ecb\u1eca'
#'�??�??�??�??á??á?Ž�?µ�??á??á?�?á??á??á??á??á??á??á??á??á??á??á??á?šá??á?�?á?Ÿá?žá??á??á??á??'
u'ó�?ò�?ỏ�?õ�?ọ�?�?Ố�?�?�?�?�?�?�?�?�?�?ờ�?�?�?ỡỠợỢ'
#u'\xf3\xd3\xf2\xd2\u1ecf\u1ece\xf5\xd5\u1ecd\u1ecc\u1ed1\u1ed0\u1ed3\u1ed2\u1ed5\u1ed4\u1ed7\u1ed6\u1ed9\u1ed8\u1edb\u1eda\u1edd\u1edc\u1edf\u1ede\u1ee1\u1ee0\u1ee3\u1ee2'
#'�?º�?š�??�??á??á??�??�??á??á??á??á??á??á?ªá??á??á??á??á??á??á??á??á??á??á??á??á?µá??�??�??'
u'ú�?ù�?ủỦũŨụỤứỨừỪửỬữỮựỰỳỲỷỶỹỸỵỴýÝ'
#u'\xfa\xda\xf9\xd9\u1ee7\u1ee6\u0169\u0168\u1ee5\u1ee4\u1ee9\u1ee8\u1eeb\u1eea\u1eed\u1eec\u1eef\u1eee\u1ef1\u1ef0\u1ef3\u1ef2\u1ef7\u1ef6\u1ef9\u1ef8\u1ef5\u1ef4\xfd\xdd'
)
_KhongDau = (
u'aAaAdDeEoOoOuU'
u'aAaAaAaAaAaAaAaAaAaAaAaAaAaAaA'
u'eEeEeEeEeEeEeEeEeEeEiIiIiIiIiI'
u'oOoOoOoOoOoOoOoOoOoOoOoOoOoOoO'
u'uUuUuUuUuUuUuUuUuUuUyYyYyYyYyY'
)
_TCVN3= (
#'�??�??�??�??�??�??�?ª�??�??�??�??�??�??�??'
u'©¢¨¡®§ª£«¤¬¥*¦'
#'\xa9\xa2\xa8\xa1\xae\xa7\xaa\xa3\xab\xa4\xac\xa5\xad\xa6'
#'�??�??�?µ�?µ�??�??�??�??�??�??�?Š�?Š�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??'
u'¸¸µµ¶¶··¹¹�?�?�?�?�?�?�?�?�?�?¾¾»»¼¼½½�?�?'
#'\xb8\xb8\xb5\xb5\xb6\xb6\xb7\xb7\xb9\xb9\xca\xca\xc7\xc7\xc8\xc8\xc9\xc9\xcb\xcb\xbe\xbe\xbb\xbb\xbc\xbc\xbd\xbd\xc6\xc6'
#'�??�??�?�?�?�?�?Ž�?Ž�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�?�?�?�?�?ž�?ž'
u'ÐÐ�?�?�?�?ÏÏ�?�?�?�?�?�?�?�?�?�?�?�?ÝÝ�?�?�?�?�?�?�?�?'
#u'\xcf\xcf\xd1\xd1\xd5\xd5\xd2\xd2\xd3\xd3\xd4\xd4\xd6\xd6\xdd\xdd\xd7\xd7\xd8\xd8\xdc\xdc\xde\xde'
#'�??�??�?Ÿ�?Ÿ�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�?ª�?ª�??�??�??�??�??�??'
u'ãã�?�?ááââääèèååææççééííêêëëììîî'
#'\xe2\xe2\xe4\xe4\xe8\xe8\xe5\xe5\xe6\xe6\xe7\xe7\xe9\xe9\xed\xed\xea\xea\xeb\xeb\xec\xec\xee\xee'
#'�??�??�??�??�??�??�??�??�??�??�??�??�?µ�?µ�??�??�??�??�??�??�?º�?º�??�??�??�??�??�??�??�??'
u'óóïïññòòôôøøõõöö÷÷ùùúúûûüüþþýý'
#'\xf3\xf3\xef\xef\xf1\xf1\xf2\xf2\xf4\xf4\xf8\xf8\xf5\xf5\xf6\xf6\xf7\xf7\xf9\xf9\xfa\xfa\xfb\xfb\xfc\xfc\xfe\xfe\xfd\xfd'
)
def ConvertEncoding(input_fc,input_fd,newfd,sE,dE):
global arcpy
rows = arcpy.UpdateCursor(input_fc)
result = arcpy.GetCount_management(input_fc)
count = int(result.GetOutput(0))
arcpy.SetProgressor("step", "Reading", 0, count, 1)
for row in iter(rows.next, None):
string1 = row.GetValue(input_fd)
if string1.strip() <> "":
newvalue = Convert(row.GetValue(input_fd),sE,dE)
row.SetValue(newfd,newvalue)
rows.UpdateRow(row )
else:
row.SetValue(newfd,"")
rows.UpdateRow(row)
arcpy.SetProgressorPosition()
arcpy.ResetProgressor()
del rows
del row
#Input paramaters
inputShapefile ="C://Project/TCVN.shp" #arcpy.GetParameterAsText(0)
inputFields = "TCVN"
outputShapefile = "C://Project/UNI.shp"#arcpy.GetParameterAsText(2)
#Processing block
#Copy to new shapefile
arcpy.CopyFeatures_management(inputShapefile, outputShapefile)
# Add new field for storing result
#gp.AddField(outputShapefile,newField,"TEXT","#","#",254)#,"#","NON_NULLABLE","NON_REQUIRED","#")
#Processing conversion of encoding
inputFL = inputFields.split(";")
for inputField in inputFL:
ConvertEncoding(outputShapefile,inputField,inputField,_TCVN3,_Unicode)
arcpy.AddMessage("Finish!")
that is the original one # Simple script for conversion of Vietnamese encoding
import arcgisscripting
gp = arcgisscripting.create(9.3)
def Convert(str,s,d):
global _Unicode, _TCVN3, _KhongDau
result = u''
for c in str:
idx = s.find(c)
if idx >= 0:
c = d[idx]
result += c
return result
# Array of characters (Using Tuple instead of List)
_Unicode = (
#'�??�??�?�?�??�??�??�?ª�?Š�??�??�??�??�??�??'
u'â�?�?�?�?Đê�?ô�?ơƠưƯ'
#u'\xe2\xc2\u0103\u0102\u0111\u0110\xea\xca\xf4\xd4\u01a1\u01a0\u01b0\u01af'
#'�??�??�??�??���??�?�?���������Ẫ��������ẵ���'
u'áÁà�?ảẢã�?ạẠấẤầẦẩẨẫẪậẬắẮằẰẳẲẵẴặẶ'
#u'\xe1\xc1\xe0\xc0\u1ea3\u1ea2\xe3\xc3\u1ea1\u1ea0\u1ea5\u1ea4\u1ea7\u1ea6\u1ea9\u1ea8\u1eab\u1eaa\u1ead\u1eac\u1eaf\u1eae\u1eb1\u1eb0\u1eb3\u1eb2\u1eb5\u1eb4\u1eb7\u1eb6'
#'�??�??�??�??áº?Ẻáº?áº?áº?áº?áº?áº?á??á??á?�?á??á??á??á??á??�??�??�??�?�?á??á??�??�??á??á?Š'
u'é�?è�?ẻẺẽẼẹẸếẾề�?�?�?�?�?�?�?íÍì�?�?�?ĩĨ�?�?'
#u'\xe9\xc9\xe8\xc8\u1ebb\u1eba\u1ebd\u1ebc\u1eb9\u1eb8\u1ebf\u1ebe\u1ec1\u1ec0\u1ec3\u1ec2\u1ec5\u1ec4\u1ec7\u1ec6\xed\xcd\xec\xcc\u1ec9\u1ec8\u0129\u0128\u1ecb\u1eca'
#'�??�??�??�??á??á?Ž�?µ�??á??á?�?á??á??á??á??á??á??á??á??á??á??á??á?šá??á?�?á?Ÿá?žá??á??á??á??'
u'ó�?ò�?ỏ�?õ�?ọ�?�?Ố�?�?�?�?�?�?�?�?�?�?ờ�?�?�?ỡỠợỢ'
#u'\xf3\xd3\xf2\xd2\u1ecf\u1ece\xf5\xd5\u1ecd\u1ecc\u1ed1\u1ed0\u1ed3\u1ed2\u1ed5\u1ed4\u1ed7\u1ed6\u1ed9\u1ed8\u1edb\u1eda\u1edd\u1edc\u1edf\u1ede\u1ee1\u1ee0\u1ee3\u1ee2'
#'�?º�?š�??�??á??á??�??�??á??á??á??á??á??á?ªá??á??á??á??á??á??á??á??á??á??á??á??á?µá??�??�??'
u'ú�?ù�?ủỦũŨụỤứỨừỪửỬữỮựỰỳỲỷỶỹỸỵỴýÝ'
#u'\xfa\xda\xf9\xd9\u1ee7\u1ee6\u0169\u0168\u1ee5\u1ee4\u1ee9\u1ee8\u1eeb\u1eea\u1eed\u1eec\u1eef\u1eee\u1ef1\u1ef0\u1ef3\u1ef2\u1ef7\u1ef6\u1ef9\u1ef8\u1ef5\u1ef4\xfd\xdd'
)
_KhongDau = (
u'aAaAdDeEoOoOuU'
u'aAaAaAaAaAaAaAaAaAaAaAaAaAaAaA'
u'eEeEeEeEeEeEeEeEeEeEiIiIiIiIiI'
u'oOoOoOoOoOoOoOoOoOoOoOoOoOoOoO'
u'uUuUuUuUuUuUuUuUuUuUyYyYyYyYyY'
)
_TCVN3= (
#'�??�??�??�??�??�??�?ª�??�??�??�??�??�??�??'
u'©¢¨¡®§ª£«¤¬¥*¦'
#'\xa9\xa2\xa8\xa1\xae\xa7\xaa\xa3\xab\xa4\xac\xa5\xad\xa6'
#'�??�??�?µ�?µ�??�??�??�??�??�??�?Š�?Š�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??'
u'¸¸µµ¶¶··¹¹�?�?�?�?�?�?�?�?�?�?¾¾»»¼¼½½�?�?'
#'\xb8\xb8\xb5\xb5\xb6\xb6\xb7\xb7\xb9\xb9\xca\xca\xc7\xc7\xc8\xc8\xc9\xc9\xcb\xcb\xbe\xbe\xbb\xbb\xbc\xbc\xbd\xbd\xc6\xc6'
#'�??�??�?�?�?�?�?Ž�?Ž�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�?�?�?�?�?ž�?ž'
u'ÐÐ�?�?�?�?ÏÏ�?�?�?�?�?�?�?�?�?�?�?�?ÝÝ�?�?�?�?�?�?�?�?'
#u'\xcf\xcf\xd1\xd1\xd5\xd5\xd2\xd2\xd3\xd3\xd4\xd4\xd6\xd6\xdd\xdd\xd7\xd7\xd8\xd8\xdc\xdc\xde\xde'
#'�??�??�?Ÿ�?Ÿ�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�??�?ª�?ª�??�??�??�??�??�??'
u'ãã�?�?ááââääèèååææççééííêêëëììîî'
#'\xe2\xe2\xe4\xe4\xe8\xe8\xe5\xe5\xe6\xe6\xe7\xe7\xe9\xe9\xed\xed\xea\xea\xeb\xeb\xec\xec\xee\xee'
#'�??�??�??�??�??�??�??�??�??�??�??�??�?µ�?µ�??�??�??�??�??�??�?º�?º�??�??�??�??�??�??�??�??'
u'óóïïññòòôôøøõõöö÷÷ùùúúûûüüþþýý'
#'\xf3\xf3\xef\xef\xf1\xf1\xf2\xf2\xf4\xf4\xf8\xf8\xf5\xf5\xf6\xf6\xf7\xf7\xf9\xf9\xfa\xfa\xfb\xfb\xfc\xfc\xfe\xfe\xfd\xfd'
)
def ConvertEncoding(input_fc,input_fd,newfd,sE,dE):
global gp
rows = gp.updatecursor(input_fc)
result = gp.GetCount_management(input_fc)
count = int(result.GetOutput(0))
gp.SetProgressor("step", "Reading", 0, count, 1)
for row in iter(rows.next, None):
string1 = row.GetValue(input_fd)
if string1.strip() <> "":
newvalue = Convert(row.GetValue(input_fd),sE,dE)
row.SetValue(newfd,newvalue)
rows.UpdateRow(row)
else:
row.SetValue(newfd,"")
rows.UpdateRow(row)
gp.SetProgressorPosition()
gp.ResetProgressor()
del rows
del row
#Input paramaters
inputShapefile = gp.GetParameterAsText(0)
inputFields = gp.GetParameterAsText(1)
outputShapefile = gp.GetParameterAsText(2)
#Processing block
gp.toolbox = "management"
try:
#Copy to new shapefile
gp.CopyFeatures_management(inputShapefile,outputShapefile)
# Add new field for storing result
#gp.AddField(outputShapefile,newField,"TEXT","#","#",254)#,"#","NON_NULLABLE","NON_REQUIRED","#")
#Processing conversion of encoding
inputFL = inputFields.split(";")
for inputField in inputFL:
ConvertEncoding(outputShapefile,inputField,inputField,_TCVN3,_Unicode)
gp.AddMessage("Finish!")
#Free resources
except:
gp.GetMessage(2)
del gp
Thanks a lot for your help cheers chris
... View more
02-02-2012
05:01 PM
|
1
|
1
|
1561
|
POST
|
Hi! Here is my problem. I have a bulk of attribute tables with string columns. Those string columns contain text that has been written in Vietnamese font (.vn arial, VNI Windows, VIQR and others). Mostly each attribute table contains only one Font. So now if i open a map it looks like that "di??n tÝch, d©n sè c¸c ®¬n v?? hµnh chÝnh cña thµnh phè" instead of "di??n tích, dân s?? các ???n v?? hành chính c?a". All this different fonts are a big mess and people who didn't install the fonts can not read it. To keep it short the best way is to bring it all to unicode which I d like to do in Python. What I am thinking about is: 1) Step through the attribute table 2) Read the field value (original Text) 3) Convert it to Unicode (This I don't know how to) 4) Update the field with the Converted text and so on Anybody out there who can give me a hand on this? Or any other time saving solutions? Best regards Chris P.S. For few files i used to do it as follows: 1) Export the attribute table as a .dbf file 2) Open it in Excel and copy the whole table into clipboard 3) Open a program called UniKey 4) Pressing ctrl+shift+f6 - which converts the text in the clipboard to unicode (u have to define the source and output dataset first) 5) Paste it over the orig dbf table 6) In Arcgis join it with the original table 7) Use the field calculator to copy the joined table to the original one It is obviously why i don't want to do that hundred of times.
... View more
02-01-2012
09:52 PM
|
0
|
5
|
7862
|
POST
|
Hi! Just out of my distant memory to give you an idea 1) Open georeferencing toolbox 2) Use add control point and first click on a known coordinate on your map (e.g. crosspoints of the grid) second click anywhere else doesnt matter where (just to finsih creating the link) 3) Go to View Link table and change the values of X Map and Y Map to the correct values (The x y values you get from the grid written on your paper map ) of the Links origin point (where you clicked first). 4) Repeat steps for 4 points in each corner of your map 5) Under Georeferencing/Transformation you can choose which transformation you like 6) At the end press Update Georeferencing Hope that helps you to get started.
... View more
01-11-2012
06:08 PM
|
0
|
0
|
391
|
POST
|
Hi just some hints for you. I didn't try it. Just wrote from memory. 1) Leave it hard coded and replace it when your code works e.g. TargetProject= "Coordinate Systems/Projected Coordinate Systems/UTM/WGS 1984/Northern Hemisphere/WGS 1984 UTM Zone 18N.prj" later you replace it by: TargetProject=arcpy.GetParameterAsText(0) 2/3) try this: #for" in_data" use the describe command to ge the name of the current projection desc = arcpy.Describe("C:/Data/example.gdb/yourshape") in_data=desc.name #for the new shape use the old + some string. I often make mistakes in combining so counter check out_data=str(str(in_data) + "_projected.shp") Rename_management (in_data, out_data) 4) Try this: desc = arcpy.Describe("C:/Data/example.gdb/yourshape") sr = desc.spatialReference if str(sr) ==TargetProject: #then do your stuff etc. else: print: "Already correct coordinate System" good luck chris
... View more
10-10-2011
12:23 AM
|
0
|
0
|
545
|
POST
|
Hi! ever thought about using ArcHydrotools? ftp://ftp.esri.com/ArcHydro/Setup10/2.0.1.125/ It is an extension you have to install. I didn't use it in ArcGis10 but in 9.3 it was foolproof with a good documentation Good Luck Chris
... View more
09-26-2011
07:16 AM
|
0
|
0
|
187
|
POST
|
Hi Mark! Thanks again. It gets a little bit off topic so I will start a new topic on how to use python in a better way when I find some time. Thanks again Cu around
... View more
09-21-2011
07:03 PM
|
0
|
0
|
1033
|
POST
|
Hello Stacy! Solution number one worked perfectly well for me. Thanks a lot
... View more
09-21-2011
06:59 PM
|
0
|
0
|
292
|
POST
|
Hi! So I wrote some Python code to List all Maps in a folder and some more properties and stuff. Everything keeps running perfectly smooth if I use it in the ArcmapGeoprocessing/Python Command Window. But if I want to run it as a Script it fails. Giving me this Error message <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid.
ERROR 000732: Input Table: Dataset MXD_Overview_Table does not exist or is not supported
Failed to execute (AddField). The new table (MXD_Overview_Table) is created, but for some reason Python can not add fields if running as a script. What is it I am missing? Thanks for your help Chris P.S: I ve Windows 7 for 64 bit, ARCGIS10 Editor Licence with Service Pack 2 installed, on a Dell with a Intel i 7 and 8GB of Ram and plenty of space on my harddisk. My Code is: #List all maps and there properties in a folder
# Import system modules
import arcpy, os, glob
import sys
import traceback
# Overwrite pre-existing files
arcpy.env.overwriteOutput = True
#This is the folder containing your MXD's
arcpy.env.workspace = r"P:/RAME/GIS/2011/Maps" #arcpy.GetParameterAsText(0)
baseFolder=arcpy.env.workspace
#The Geodatabase to store the Resulting table in
geoDataBasePath="P:/RAME/GIS/2011/RAME.gdb" #arcpy.GetParameterAsText(1)
#The Name of the New Table containing the MXD-List
NewTable="MXD_Overview_Table" #arcpy.GetParameterAsText(2)
#Define Workspace
#Create New Lists for Layers and Sources of Layers
mxdFileNames=[]
workspaces=[baseFolder]
#Create a new table containing Name of MXD, Path of MXD, Selected MXD Properties, Layers in the MXD and Sources (Shapefiles on which the Layers are based of the MXD)
field_length=255
field_length2=3000
arcpy.CreateTable_management(geoDataBasePath, NewTable)
arcpy.AddField_management(NewTable, "MXD_Name", 'TEXT', '', '', field_length, "MXD_Name")
arcpy.AddField_management(NewTable, "MXD_Path", 'TEXT', '', '', field_length, "MXD Fullpath")
arcpy.AddField_management(NewTable, "Author", 'TEXT', '', '', field_length, "Authors of MXD")
arcpy.AddField_management(NewTable, "Credits", 'TEXT', '', '', field_length, "Credits")
arcpy.AddField_management(NewTable, "Descript", 'TEXT', '', '', field_length2, "Map Description")
arcpy.AddField_management(NewTable, "Summary", 'TEXT', '', '', field_length2, "Map Summary")
arcpy.AddField_management(NewTable, "Tags", 'TEXT', '', '', field_length, "Map Tags")
arcpy.AddField_management(NewTable, "Saved", 'TEXT','','',field_length2,"Date Saved")
arcpy.AddField_management(NewTable, "Layers", 'TEXT', '', '', field_length2,"Layers included in Map")
arcpy.AddField_management(NewTable, "FeatureCl", 'TEXT', '', '', field_length2, "Featureclasses included in Map")
#Lets grab a listing of all MXD's in our workspace; baseFolder
b = arcpy.ListWorkspaces("*", "Folder")
workspaces.extend(b)
for workspace in workspaces:
#Lets grab a listing of all MXD's in our workspace; baseFolder
allItems = os.listdir(workspace)
# filter out just .mxd's
mxdFileNames = [(x) for x in allItems if x.endswith('.mxd')]
#For each mxd get all parameters. To do this step through the mxd list
for name in mxdFileNames:
try:#get mxd
arcpy.env.workspace=baseFolder
temp= str(str("%s" %workspace)+"\\"+name)
mxd = arcpy.mapping.MapDocument(temp)
namemxd= str("%s" % mxd.title)
filePath=str(mxd.filePath)
author="%s" % mxd.author
credits_="%s" % mxd.credits
dateSaved="%s" % mxd.dateSaved
description="%s" % mxd.description
summary="%s" % mxd.summary
tags="%s" % mxd.tags
#list all the layers for MXD after another from above
try:
Source=[]
LyrList=[]
mxdlyrs=arcpy.mapping.ListLayers(mxd)
for lyr in mxdlyrs:
name=lyr.longName
if lyr.supports("dataSource"):
dataSource=lyr.dataSource
else:
dataSource="Not defined"
LyrList.extend([str(name)])
Source.extend([str(dataSource)])
except ValueError:
#get error message if there is a problem getting lyr name or lyr source
print "Invalid Layer in MXD:",filePath,"."
arcpy.AddError( 'Invalid Layer in MXD:',filePath, '. Maybe because of a missing template.')
finally:
#Create a Insert Cursor to insert new rows and write each value in the corresponding field
cursor = arcpy.InsertCursor(geoDataBasePath+"\\"+NewTable)
row = cursor.newRow()
row.MXD_Name=str(namemxd)
row.MXD_Path=str(filePath)
if len(LyrList)>3000:
LyrList=["More than 3000 characters. To many to be written to the file"]
else:
row.Layers=str(LyrList)
if len(Source)>3000:
Source=["More than 3000 characters. To many to be written to the file"]
else:
row.FeatureCl=str(Source)
row.Author=author
row.Credits=str(credits_)
row.Descript=str(description)
row.Saved=str(dateSaved)
row.Summary=str(summary)
row.Tags=str(tags)
cursor.insertRow(row)
# tidy up
del row
del cursor
except ValueError:
print "Invalid MXD:",filePath,". Open the mxd in ArcMap and check for errors."
arcpy.AddError( 'Invalid MXD:',filePath, '. Open the mxd in ArcMap and check for errors.')
... View more
09-20-2011
08:28 PM
|
0
|
3
|
621
|
POST
|
Hi Marc! I appreciate your hints. 1) I agree I should handle the error messages more carefully. I've one more question on that. Sometimes when programming python gives me an error message telling me there is a mistake in a certain line(25), but in IDLE Python it is another line(20). Any idea about that? 2) Touché. Just stupidly copied code : ) Thanks again Chris
... View more
09-15-2011
04:47 PM
|
0
|
0
|
1033
|
POST
|
Hi! Thanks to all of you ! I finally finished it today. I copied the lines of Mathew, but I discovered that my original problem was that I choose an reserved field name for a field i added. ArcView changed it and add a "_" which I didn't realize. So now it is working perfectly fine. So anybody who is interested in a tool creating a table with all table field properties of a geodatabase fell free to try it. Best regards again Chris # Export all the field properties of each table in the Geodatabse to a new table
# in the same Geodatabase. If the table already exists the old one will be
# overwritten. If a problem occurs a message will appear in the python window, so
# check the window before closing.
import arcpy
from arcpy import env
# Overwrite pre-existing files
arcpy.env.overwriteOutput = True
# Get input information. Target Geodatabase and Name of the New table containing
# the Table field properties.
geoDataBasePath=arcpy.GetParameterAsText(0)
NewTable=arcpy.GetParameterAsText(1)
# Set the current workspace
# Create a new table
try:
env.workspace = geoDataBasePath
arcpy.CreateTable_management(geoDataBasePath, NewTable)
# Naming the fields of the outputtable
inFeatures = NewTable
fieldName1="field_name"
fieldName2="aliasName_"
fieldName3="baseName_"
fieldName4="domain_"
fieldName5="isNullabl_"
fieldName6="precision_"
fieldName7="required_"
fieldName8="scale_"
fieldName9="type_"
fieldName10="length_"
fieldName11="editable_"
fieldName12="Table_Name"
fieldLength=255
# Execute AddField new fields. All fields are set as text even if they contain numbers.
arcpy.AddField_management(inFeatures, fieldName12, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName1, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName2, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName3, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName4, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName5, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName6, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName7, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName8, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName9, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName10, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName11, "TEXT", "", "", fieldLength)
#List all tables in the Geodatabase
tableList = arcpy.ListTables()
x=0
# For all tables list all fields
for table in tableList:
try:
fieldList = arcpy.ListFields(table)
for field in fieldList:
#Get the name of the current table
nametable=str(tableList )
#make a new list and add the name of the table and the properties
#of each field to the list
NewList=[]
NewList.extend ([str(field.name),str(field.aliasName),str(field.baseName),str(field.domain),str(field.isNullable),str(field.precision),str(field.required),str(field.scale), str(field.type),str(field.length),str(field.editable), nametable])
#Use an insert cursor to add new rows with the field properties
cursor = arcpy.InsertCursor(NewTable)
row = cursor.newRow()
row.field_name = NewList[0]
row.aliasName_ = NewList[1]
row.baseName_ = NewList[2]
row.domain_ = NewList[3]
row.isNullabl_=NewList[4]
row.precision_ = NewList[5]
row.required_ = NewList[6]
row.scale_ = NewList[7]
row.type_ = NewList[8]
row.length_ = NewList[9]
row.editable_ = NewList[10]
row.Table_Name = NewList[11]
cursor.insertRow(row)
x=x+1
#add warning message in the python window if a problem with the table appears.
#Even a problem is reported the output is normally fine. But check to make sure.
except:
print "The crazy clown says there is a problem with table ", nametable, ". Check the results for this table."
except:
print "\nError!\n"
del row
del cursor
del NewList
... View more
09-15-2011
01:08 AM
|
0
|
0
|
1033
|
POST
|
Hi! I try to use the arcpy.ListFields command. It only works when I type in the name of the shape file directly. It does not work when I try to use a shapefile name from a list. So to chekc my Code I added the print comand and it perfectly prints out the name of the shape. Example: 'River' But the code still doesn't work. If I enter 'River' manually it works perfectly fine. Any idea where the mistake might be? Thanks a lot Doesn't work: while x <= leta:
Listfieldx = str("'" + str(tableList )+"'")
print Listfieldx
fieldList = arcpy.ListFields(Listfieldx,"*","*") I tried also fieldList = arcpy.ListFields(Listfieldx) fieldList = arcpy.ListFields(str(Listfieldx)) etc, etc... Does work: while x <= leta:
Listfieldx = str("'" + str(tableList )+"'")
print Listfieldx
fieldList = arcpy.ListFields('River') Best regards Chris p.s. here the whole code #Export all the field properties of each table in the Geodatabse
import arcpy
from arcpy import env
# Overwrite pre-existing files
arcpy.env.overwriteOutput = True
# Set the current workspace
#
# Set local variables
#Create a new table
try:
geoDataBasePath = "P:/RAME/GIS/2011/Report.mdb"
env.workspace = geoDataBasePath
NewTable = "FieldProperties"
arcpy.CreateTable_management(geoDataBasePath, NewTable)
# For each field in the feature class, print all properties
# Set local variables
inFeatures = NewTable
fieldName1="name"
fieldName2="aliasName"
fieldName3="baseName"
fieldName4="domain"
fieldName5="isNullable"
fieldName6="precision"
fieldName7="required"
fieldName8="scale"
fieldName9="type"
fieldName10="length"
fieldName11="editable"
fieldName12="FC"
fieldLength=255
# Execute AddField new fields
arcpy.AddField_management(inFeatures, fieldName1, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName2, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName3, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName4, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName5, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName6, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName7, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName8, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName9, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName10, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName11, "TEXT", "", "", fieldLength)
arcpy.AddField_management(inFeatures, fieldName12, "TEXT", "", "", fieldLength)
#List all tables in the Geodatabase
tableList = arcpy.ListTables()
for table in tableList:
print table
#how many tables are there
leta = len(tableList)
print leta
x=0
#loop through all tables
while x <= leta:
Listfieldx = str("'" + str(tableList )+"'")
print Listfieldx
fieldList = arcpy.ListFields(Listfieldx,"*","*")
print str(fieldList)
for field in fieldList:
print 1
NewList=[]
fc=str(tableList )
print fc
NewList.extend ([str(fc),str(field.name),str(field.aliasName),str(field.baseName),str(field.domain),str(field.isNullable),str(field.precision),str(field.required),str(field.scale), str(field.type),str(field.length),str(field.editable)])
print NewList
cursor = arcpy.InsertCursor(fc)
print 2
row = cursor.newRow()
row.FC=NewList[11]
row.name = NewList[0]
row.aliasName = NewList[1]
row.baseName = NewList[2]
row.domain = NewList[3]
row.isNullable = NewList[4]
row.precision = NewList[5]
row.required = NewList[6]
row.scale = NewList[7]
row.type = NewList[8]
row.length = NewList[9]
row.editable = NewList[10]
print 3
cursor.insertRow(row)
del NewList
x=x+1
del row
print 99
del cursor
del NewList
except:
print "\nError!\n"
del row
del cursor
del NewList
... View more
09-13-2011
09:42 AM
|
0
|
9
|
5611
|
POST
|
Hi! I wanted to use the Code to define the deviation from north in degree. Where north would be 0 east 90 south 180 and west 270. So I changed the code to this: 180 + math.atan2((!Shape.lastpoint.X! - !Shape.firstpoint.X!),(!Shape.lastpoint.Y! - !Shape.firstpoint.Y!)) * (180 / math.pi) So far so good, BUT for everything in western direction I get a negative value eg. -90 instead of 270. Any mathematical genius that can enlighten me? Thanks Chris
... View more
09-06-2011
07:30 PM
|
0
|
0
|
5059
|
POST
|
Hi! Thanks for ur reply! BUT that is not what i am looking for. I speak about several hundred rows. I m looking for some command. Like "rankdata" or sth. like this. I wonder that i didnt find any other entry in the forum. For me it looks odd that this very standard function is not available. cu Chris
... View more
06-09-2011
07:33 AM
|
0
|
0
|
676
|
POST
|
Hi! What I am looking for is giving the FieldA a Rank depending on the values in FieldB. I would like to end up with sth. like this. Can i do this easy in the field calculator? Rank orig. Value 1 5 2 7 3 14 4 23 in python i did it like this: import arcpy, numpy, os from arcpy import env
import arcpy, numpy, os
ShapeName=arcpy.GetParameterAsText(0)
Field=arcpy.GetParameterAsText(1)
RankField=arcpy.GetParameterAsText(2)
rows = arcpy.SearchCursor(ShapeName)
d=[]
for row in rows :
FieldValue=row.getValue(Field)
d.append(FieldValue)
d.sort()
arcpy.AddMessage(d)
del rows
rows2 = arcpy.UpdateCursor(ShapeName,"","",RankField,"")
row2= rows2.next()
while row2:
x=0
for i in d:
y=d
if row2.getValue(Field)==y:
rank2=d.index(y)
rank=rank2+1
row2.setValue(RankField, rank)
rows2.updateRow(row2)
x=x+1
row2 = rows2.next()
del rows2 Thanks for any help
... View more
06-08-2011
07:37 PM
|
0
|
7
|
2355
|
POST
|
Hi! Thanks for your answer. I also had problems to delete the temp. shapefiles. So i think i ll try what oliver suggests. Thank you
... View more
06-06-2011
02:53 AM
|
0
|
0
|
227
|
Title | Kudos | Posted |
---|---|---|
1 | 02-02-2012 05:01 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|