POST
|
Thanks for the hint (Calculate Value is now "shaded" too) - unfortunately it didn't have any effect. I think the order of the processes works according to plan, but for some reason the string I'm trying to create by "Calculate value" does not seem to have a proper format. How would you create the output file name, if you wanted to base it on the input file's name? Or is there another/better way to import 50 files (csv or xls) into point shapes? Regards, Eric
... View more
09-19-2013
02:17 AM
|
0
|
0
|
1125
|
POST
|
Hi! I'm trying to automate the following process within the model builder: 1. Import Excel xls-files, that each contain point elevation data with x,y and z values 2. Convert them into separate shape files while using the original xls file name as the output file name Therefore I've setup the following model: [ATTACH=CONFIG]27506[/ATTACH] The problem occurs while trying to copy the features to an output shape when using the expression for the new file name. Since for iterating the Excel files I need to activate the Recursive option to scan the worksheets within each xls file. The extracted "File" then contains a "$" at the end to mark the worksheet (so if for instance the input file is 001b.xls, the extracted name within "File" is 001b$). Because of the error message "000354 : The name contains invalid characters" i assumed that the "$" is the problem and used the Calculate Value tool with r"%File%".replace("$","") as an Expression and string as the Data Type. Unfortunately this doesn't help, although the calculated value seems to be correct (without the "$")... Hence my questions are: a) What exactly is causing the error and how can I solve it? b) What other possibilities would I have to manipulate the input file name for output, for instance if I want to use only a part of the name or add an automated counter? Thanks in advance for any help!
... View more
09-17-2013
03:52 AM
|
0
|
3
|
6377
|
POST
|
The comparison operation was the reason it crashed, I didn't know that it works different with strings... As soon as I changed it according to your example it works well! However, the getPart() method seems to work with the Point object, at least it doesn't produce any error. In fact, if I remove the line, the output seems to be only one point (out of >1000) and even with the wrong coordinates - weird. But I will have a deeper look into those object differences you mentioned! Thanks for the quick help!
... View more
02-18-2013
04:29 AM
|
0
|
0
|
500
|
POST
|
Hi! I'm pretty new into Python and just do my first steps by modifying existing code to match my problem. The aim is to change the X/Y coordinates of all features within a feature class / shapefile and save the transformed features in a new file. For this I've used a well working example code to switch X/Y coordinates of polygons and modified it: # Import system modules import arcpy import sys import os import traceback import string def Transform_XY(infc, outfc, outfcSR): # Transforms the X,Y coordinates of a feature class # Check type of input feature class infcType = arcpy.Describe(infc).shapeType if not arcpy.Exists(infc): AddMsgAndPrint("Input feature class not found! Script stops here.") return if not arcpy.Exists(outfc): fpath, fname = os.path.split(outfc) arcpy.CreateFeatureclass_management(fpath, fname, infcType, infc, "DISABLED", "DISABLED", outfcSR) AddMsgAndPrint("New shapefile of type " + infcType + " created...") else: AddMsgAndPrint("Output feature class already exists, please specify new location! Script stops here.") return # Define cursors for input & output readRows = arcpy.SearchCursor(infc) readRow = readRows.next() insRows = arcpy.InsertCursor(outfc) insRow = insRows.next() AddMsgAndPrint("Cursors Created...") # Update progress info in dialog box arcpy.SetProgressor("default") result = arcpy.GetCount_management(infc) count = int(result.getOutput(0)) fcount = 0 AddMsgAndPrint("Progressor Created...") # Create temporary geometry objects inPoly_Array = arcpy.Array() inPt = arcpy.Point() outPt = arcpy.Point() fieldList = arcpy.ListFields(infc) for field in fieldList: AddMsgAndPrint(field.name) # Transformation Parameters for affine transformation (example Helsinki-VVY -> ETRS-GK-25) A = 6654650.14636 B = 0.99998725362 C = 0.00120230340 D = 25447166.49457 # Loop through all features in the source feature class shapefieldname = arcpy.gp.Describe(infc).ShapeFieldName while readRow: fcount += 1 partnum = 0 inType = readRow.getValue(shapefieldname) if infcType == "Polygon" or "Polyline": partcount = inType.partCount # Update progressor message progressMessage = "Processing source feature: " + str(fcount) + " of " + str(count) arcpy.SetProgressorLabel(progressMessage) # Coordinate transformation if infcType == "Polygon" or "Polyline": while partnum < partcount: part = inType.getPart(partnum) inPt = part.next() while inPt: outPt.Y = A + (B * inPt.Y) - (C * inPt.X) outPt.X = D + (C * inPt.Y) + (B * inPt.X) inPoly_Array.append(outPt) inPt = part.next() outPoly = insRows.newRow() outPoly.Shape = inPoly_Array for field in fieldList: if field.name != "FID" and field.name != "Shape": fieldValue = readRow.getValue(field.name) AddMsgAndPrint(field.name) AddMsgAndPrint(fieldValue) outPoly.setValue(field.name, fieldValue) insRows.insertRow(outPoly) partnum += 1 inPoly_Array.removeAll() else: inPt = inType.getPart() outPt.Y = A + (B * inPt.Y) - (C * inPt.X) outPt.X = D + (C * inPt.Y) + (B * inPt.X) outFeature = insRows.newRow() outFeature.Shape = outPt insRows.insertRow(outFeature) readRow = readRows.next() return def AddMsgAndPrint(message): arcpy.AddMessage(message) print message return 0 #+-------------------------------------------------------------------------------------+ # Main Process Loop #+-------------------------------------------------------------------------------------+ # Create the Geoprocessor object and set the overwrite setting arcpy.OverWriteOutput = True try: # # Input Parameters # # infc - input feature class # outfc - output feature class # outfcSR - output feature class' spatial reference infc = arcpy.GetParameterAsText(0) outfc = arcpy.GetParameterAsText(1) outfcSR = arcpy.GetParameterAsText(2) Transform_XY(infc, outfc, outfcSR) AddMsgAndPrint("Transformation completed...") # Done except arcpy.ExecuteError: # Get the geoprocessing error messages msgs = arcpy.GetMessage(0) msgs += arcpy.GetMessages(2) # Return geoprocessing error messages for use with a script tool arcpy.AddError(msgs) # Print geoprocessing error messages for use in Python/PythonWin print msgs except: # Get the traceback object tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # Concatenate error message pymsg = tbinfo + "\n" + str(sys.exc_type)+ ": " + str(sys.exc_value) # Return python error messages for use with a script tool arcpy.AddError(pymsg) # Print Python error messages for use in Python/PythonWin print pymsg I'm running the code as a script form a custom toolbox, so i can specify the inputs manually. The code works fine for polygons and polylines, only as soon as i choose a shapefile with point features I'm getting the message: 'Point' object has no attribute 'next'. What am I doing wrong? Thanks in advance for any help!
... View more
02-17-2013
11:09 PM
|
0
|
4
|
758
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|