POST
|
Last week I finally solved this problem and I thought I'd post the answer here for future reference. After sending this question to the ESRI helpdesk I got the confirmation that it was possible to use tools in a toolset and after some more trying and searching I found the problem, I made an error with the toolname. When you open the tool properties there's is a name field and a label field. For importing tools the only field that matters is the name field and it turns out I was looking to the label field in the catalog view. In my case those were nearly identical but the toolname had a "(2)" behind it due to me copying the tool. So the moral of this story is to watch your Label and Name fields and in case of toolboxes also the Alias field carefully and it should all work like a charm. cheers, Marc
... View more
10-02-2013
12:26 AM
|
1
|
0
|
215
|
POST
|
Hi there, In arcgis 10 I'm trying to import a model that's located in a custom toolbox with the arcpy.ImportToolbox method. This is working ok as long as the model is located in the toolbox root but once I put the model in a toolset I'm getting an error: AttributeError: 'module' object has no attribute 'TestModel_Database'. Since models in toolbox need to have unique names I assumed the location in a toolset didn't matter but is there some additional info I need to add to the function? I can't seem to find any reference to importing toolsets on the forums, help sites or internet so any info is appreciated. Below I pasted a piece of code I'm using to test importing a model that creates a featureclass and adds a field. import arcpy arcpy.env.overwriteOutput =1 arcpy.ImportToolbox(r"S:\GEOINFO\11_Peilgegevens\PeildataVerwerken") Parameter01 = "xxTest" Parameter02 = "Testfield" arcpy.TestModel_Database(Parameter01, Parameter02) As a bonus question, we're going to upgrade to Arcgis 10. or 10.2 in a couple of months, is this method changing in higher versions? I found a lot of references to python toolboxes so I'm just wondering. Cheers and thanks in advance for any advice, Marc
... View more
08-21-2013
01:06 AM
|
0
|
1
|
964
|
POST
|
Nils, It's possible but I'm not sure it's faster or easier than adding a few more tools in modelbuilder. I'd put the field names in a list and then you can loop the AddField command through that list. I'm not yet sure how you can handle different datatypes for the fields though. With all fields of the TEXT type it would look like this
Shapefile = r"C:\xxx\xxx\your shapefile here.shp"
FieldList = ["Field1", "Field2", "Field3", "etc"]
for Column in FieldList:
arcpy.AddField_management(Shapefile, Column, "TEXT")
You can add more parameters after the field type to determine the field length, precision, etc Hope this is helpful. Marc
... View more
05-31-2013
01:26 AM
|
0
|
0
|
193
|
POST
|
Have not tried this, so don't know if it would work, but you might try to MakeXYeventLayer http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000006z000000 . Like I said, not tried in python, but in ArcGIS, this lets you select the x/y fields from a table, and creates a point event theme from it and carries all the attributes in the original table itself. Then, just export the event theme to shapefile. Just a thought, R_ Perhaps I should have mentioned it but that was our initial thought as well, however we ran into some problems with that as well, I can not get the tool to accept the input file for some reason. Here's what I tried on the file and as with the other question, all suggestions are welcome (code is below and the CSV file itself is also attached) - The tool does not accept a semi-colon as separator. Exchanging this character for a comma solves this problem but if you want to keep the original file you have to make a copy of the file. That's already two extra steps. - The first three lines have are additional data which is not needed in teh shapefile so they have to be deleted, otherwise the tool cannot find the right fieldnames (am I correct here?). I didn't get this to work in python yet so I did it manually but that should be possible I think. - If I follow the example from the ESRI help file on this tool I still get the message that the file does not exist or is not accepted. this is also the case if I try to drag it into the tool outside of python. Additionally I changed the file extension from the original .UVA2 to .CSV. Essentially it's still just a txt file so I don't think this is an issue.
import arcpy
FileIn = r"S:\GEOINFO\01_Basis_info\12_BAG\Adresseerbare object special\Test.csv"
OutLayer = r"S:\GEOINFO\01_Basis_info\12_BAG\Adresseerbare object special\OutLayer.lyr"
x_coords = "Xcoordinaat (RD)"
y_coords = "Ycoordinaat (RD)"
arcpy.MakeXYEventLayer_management (FileIn, x_coords, y_coords, OutLayer)
arcpy.CopyFeatures_management(OutLayer, r"S:\GEOINFO\01_Basis_info\12_BAG\Adresseerbare object special\Test.shp")
print "Finished"
... View more
05-31-2013
12:59 AM
|
0
|
0
|
2264
|
POST
|
Hi all, I'm trying to convert an ASCII file to a point feature class. I've been busy with this little project on and off for a few weeks now but it seems I've run out of ideas finally :). The idea behind the script below is that it will be implemented as a tool eventually and it has to take other ASCII files as input as well although they have the same structure as the example in the attachment. At least one of them is in the order of 185 MB, so quite large. The code I have sofar works without errors, it creates a shapefile with the correct name, it adds the correct fieldnames and it creates the correct number of points from the ASCII file in the right location. There are still two critical things lacking though before I can turn it into a tool: 1) While I figured out how to add the fields I can't seem to get the fieldtype right. Some fields should be of type String but others should be Double or Long. Somebody gave me the tip to use a try and except on the data to test if it can be made into an integer, if not it's text, otherwise it's a Double. I understand the logic behind it, I'm just struggling to implement it. How do you link the result for the try and except to the fields that are created? 2) The script now creates the correct points but the only data that is attached to them is the X,Y data in the shape attributes. Short of *manually* letting the script write each item in the list of the current line to the correct field (in the same way I write the X,Y geometry) is there a quick way of getting all the data from the ASCII to the table correctly? I feel there should be a way but I was not able to find it yet or come up with one. Thanks in advance for any answers, I hope someone can help me out here. Cheers, Marc
#Script settings en voorbereiding
#Check out any necessary licenses
import arcpy, string, os, sys, linecache
arcpy.env.overwriteOutput =1
#Inputs
File = r"S:\GEOINFO\01_Basis_info\12_BAG\Adresseerbare object special\ADRESOBJECT_SPS_20130131.UVA2"
InName = os.path.splitext(os.path.basename(File))[0]
print InName
OutDatabase = r"S:\GEOINFO\01_Basis_info\12_BAG\BAG.gdb\Adresseerbare_Object_Special"
print OutDatabase
OutShape = str(OutDatabase) + "\\" + str(InName)
print OutShape
InputASCII = file(File, "r")
# Create shapefile
arcpy.CreateFeatureclass_management(r"S:\GEOINFO\01_Basis_info\12_BAG\BAG.gdb\Adresseerbare_Object_Special", InName, "Point", "", "", "", "PROJCS['RD_New',GEOGCS['GCS_Amersfoort',DATUM['D_Amersfoort',SPHEROID['Bessel_1841',6377397.155,299.1528128]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Double_Stereographic'],PARAMETER['False_Easting',155000.0],PARAMETER['False_Northing',463000.0],PARAMETER['Central_Meridian',5.38763888888889],PARAMETER['Scale_Factor',0.9999079],PARAMETER['Latitude_Of_Origin',52.15616055555555],UNIT['Meter',1.0]]")
print "Shapefile created"
#Read and create columns from ASCII
Headerline = linecache.getline (File,4)
TextList = Headerline.split(';')
for Column in TextList:
arcpy.AddField_management(OutShape, Column, "TEXT")
print "Field names added"
#Create points from ASCII
Icur = arcpy.InsertCursor(OutShape)
LineCorrect = 0
LineError = 0
for Line in InputASCII.readlines ()[4:]:
try:
Row = Icur.newRow()
List = Line.split(";")
Point = arcpy.Point((List[20]), (List[21]))
print Point.X
print Point.Y
Row.setValue("Shape", Point)
Icur.insertRow(Row)
LineCorrect = LineCorrect + 1
del Row
except:
LineError = LineError + 1
del Row
del Icur
print "LineCorrect = " + str(LineCorrect)
print "LineError = " + str(LineError)
#-------------------------------------------------------------------------------
#Close files
InputASCII.close
... View more
05-29-2013
07:51 AM
|
0
|
4
|
6422
|
POST
|
Hi Arek, Thanks a lot, that solved it indeed. I was focusing too much on the line where the error showed so thank you for pointing me to the previous line. Cheers, Marc
... View more
01-14-2013
03:00 AM
|
0
|
0
|
276
|
Title | Kudos | Posted |
---|---|---|
1 | 10-02-2013 12:26 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|