POST
|
Indeed, I also received a few suggestions here: arcgis desktop - Python Syntax Error when running Python Snippet of successful geoprocess - Geographic Information Syste… Thanks for your feedback!
... View more
08-25-2014
09:27 AM
|
0
|
0
|
1232
|
POST
|
I am having an issue with a simple python snippet. Here's the background: I wanted to include an additional step in a nightly update script that replaces characters in a field that simply do not play nice with a web application that allows users to query the data. These characters included angle brackets ("<" and ">") which I was trying to replace with "Less Than" and "Greater Than". So when I was testing the Field Calculation, I finally got it to work the way I wanted to, and as I have done with so many other snippets, I simply copied the Python Snippet of the geoprocess, and pasted into my script. Below is the snippet: arcpy.CalculateField_management("path/to/my/layer","field","RemoveBad( !field!)","PYTHON_9.3","def RemoveBad(x):/n x = x.replace('<=', ' Less Than or Equal To ')/n x = x.replace('>=', ' Greater Than or Equal To ')/n x = x.replace('<', ' Less Than ')/n x = x.replace('>', ' Greater Than ')/n x = x.replace('=', ' Equal To ')/n x = x.strip()/n return x") Now in my script, I do have a log that reports geoprocessing errors, so when I run the script, I am getting the following: Executing: CalculateField path\to\my\layer field RemoveBad( !field!) PYTHON_9.3 "def RemoveBad(x):/n x = x.replace('<=', ' Less Than or Equal To ' )/n x = x.replace('>=', ' Greater Than or Equal To ')/n x = x.replace('<', ' Less Than ')/n x = x.replace('>', ' Greater Than ')/n x = x.replace('=', ' Equal To ')/n x = x.strip()/n return x" Start Time: Mon Aug 25 09:35:32 2014 Failed to execute. Parameters are not valid. ERROR 000989: Python syntax error: Parsing error SyntaxError: invalid syntax (line 1) Failed to execute (CalculateField). Failed at Mon Aug 25 09:35:32 2014 (Elapsed Time: 0.00 seconds) So I started combing through the script but I cannot find the issue, which leads me to believe it has something to do with the angle brackets. Any assistance in pointing out where the syntax error is occurring would be appreciated. Thanks, Chris B.
... View more
08-25-2014
07:58 AM
|
0
|
2
|
6237
|
POST
|
The fix was adding: import arcinfo Thanks for the tips!
... View more
05-13-2014
12:39 PM
|
0
|
0
|
601
|
POST
|
IYou need to import arcinfo first, otherwise you will start an instance of whatever license you are normally consuming. Interesting.. I only use ArcInfo or should I say "ArcGIS for Desktop Advanced" on this particular machine. Anyways, I am trying your suggestion. Will post back results soon. Michael - Sorry didn't see your post when I replied. I am running the scripts standalone (testing for a batch file). When using the software, I have always used the Advanced license. The machine is also an LM, hosting licenses for Basic and Standard as well, but Administrator is set to use Advanced. Thanks, Chris B.
... View more
05-13-2014
11:10 AM
|
0
|
0
|
601
|
POST
|
I did post in this discussion forum but felt like this was more of a Question/Answer forum post. ArcGIS for Desktop 10.2.1 Python 2.7 Receiving "Tool is not licensed" error when running this code: # Import arcpy module import arcpy from arcpy import env import os # Overwrite pre-existing files arcpy.env.overwriteOutput = True os.environ['ESRI_SOFTWARE_CLASS']='Professional' #Added based on forum suggestion arcpy.CheckOutExtension('Spatial') #Added based on forum suggestion Input = "C:\\GIS_DATA\\FGDB.gdb\\InputPolygons" Input_Layer = "Feature_Layer" Output = "C:\\GIS_DATA\\FGDB.gdb\\OutputPoints" try: arcpy.MakeFeatureLayer_management(Input, Input_Layer, "", "", "field alias VISIBLE NONE") arcpy.FeatureToPoint_management(Input_Layer, Output, "CENTROID") except: print arcpy.GetMessages() Result: Failed to execute. Parameters are not valid. ERROR 000824: The tool is not licensed. Failed to execute (FeatureToPoint). Never had this issue before. Migrating update scripts from one version of ArcGIS (10.0 SP5) to another (10.2.1). Any help appreciated.
... View more
05-13-2014
10:48 AM
|
0
|
4
|
2689
|
POST
|
EDIT: Moved post to separate forum ArcGIS for Desktop 10.2.1 Also receiving this error... # Import arcpy module
import arcpy
from arcpy import env
import os
# Overwrite pre-existing files
arcpy.env.overwriteOutput = True
os.environ['ESRI_SOFTWARE_CLASS']='Professional' #Added based on forum suggestion
arcpy.CheckOutExtension('Spatial') #Added based on forum suggestion
Input = "C:\\GIS_DATA\\FGDB.gdb\\InputPolygons"
Input_Layer = "Feature_Layer"
Output = "C:\\GIS_DATA\\FGDB.gdb\\OutputPoints"
try:
arcpy.MakeFeatureLayer_management(Input, Input_Layer, "", "", "field alias VISIBLE NONE")
arcpy.FeatureToPoint_management(Input_Layer, Output, "CENTROID")
except:
print arcpy.GetMessages()
Result: Failed to execute. Parameters are not valid.
ERROR 000824: The tool is not licensed.
Failed to execute (FeatureToPoint). Never had this issue before...
... View more
05-13-2014
08:42 AM
|
0
|
0
|
370
|
POST
|
I would like to remove default values from all fields used by all feature classes in an SDE geodatabase. I do not see a geoprocess for removing the default value, only setting it. So I am trying to set it to "". My approach is to use python to iterate through each feature dataset, then feature class, then field, and set the default value to "". Here's what I have so far: import arcpy
from arcpy import env
env.workspace = r"Database Connections\mysde.sde"
dsList = arcpy.ListDatasets("*", "Feature")
for dataset in dsList:
fcList = arcpy.ListFeatureClasses("*","",dataset)
for fc in fcList:
flds = arcpy.ListFields(fc,"*","String")
for fld in flds:
arcpy.AssignDefaultToField_management(fc, fld.name, "")
flds = arcpy.ListFields(fc,"*","Double")
for fld in flds:
arcpy.AssignDefaultToField_management(fc, fld.name, None)
flds = arcpy.ListFields(fc,"*","SmallInteger")
for fld in flds:
arcpy.AssignDefaultToField_management(fc, fld.name, None)
flds = arcpy.ListFields(fc,"*","Integer")
for fld in flds:
arcpy.AssignDefaultToField_management(fc, fld.name, None)
flds = arcpy.ListFields(fc,"*","Single")
for fld in flds:
arcpy.AssignDefaultToField_management(fc, fld.name, None) When I run the script I get an error 000735 which means a default value is required. How do I get around this (if at all possible)? Thanks!
... View more
04-25-2014
12:17 PM
|
0
|
0
|
764
|
POST
|
Well, for starters it's not the right forum. You're asking a Microsoft Excel question on an ArcGIS forum website. Secondly, no one here is going to just write out an Excel compatible expression or macro to convert Lat/Lng to a projected coordinate system. Lastly, since you ended up posting on an ArcGIS forum I have to ask, do you happen to have access to ArcGIS software. If so, the process to get what you want is not all that complicated.
... View more
02-25-2014
06:36 AM
|
0
|
0
|
331
|
POST
|
Interested also how you're "sucking in" your table. Plus this sounds like a major flaw on the DB design to store coordinates as strings. If you need the points, and are willing to do a couple of extra steps then after you "suck in" the data, create a copy of the table (perhaps storing the copy in a FGDB). Then add your x/y fields (type double), calculate the fields using the string type fields, then make your XY event layer. If this is a model, and you're not allowing overwrite of geoprocessing events, simply add a step to delete the copied table before creating a new one. I hate submitting this as a solution, so let's call it a workaround.
... View more
02-25-2014
05:49 AM
|
0
|
0
|
591
|
POST
|
Look in the arcpy library. I have been quite lucky migrating some tools to python when switching from 9.x to 10.x.
... View more
12-13-2013
11:37 AM
|
0
|
0
|
161
|
POST
|
Mel, Embedding iterators is possible but not a very easy process, considering some of the naming conventions and parameter assignments that need to be made. Inline variable substitution could be used if you happen to have rasters with similar names as the polygon clipping extents. For example, if Raster_1 needs to be clipped by Extent_1, then only one iterator is necessary and a simple model using the inline variable identifying each raster and extent could be used. Your CSV idea would work if you used python to read the CSV:
import arcpy
import csv
csvfile = open('test.csv', "rb")
reader = csv.reader(csvfile)
i = 1
for row in reader:
text = row.split(",")
inraster = text[0]
extent = text[1]
outraster = text[2]
arcpy.Clip_management(inraster, extent, outraster, "", "", "NONE")
i += 1
This is not tested, but simply put, it reads a csv file (second row since first row is probably headers), and splits the row at the commas. The first value of the row is the input raster, second is the polygon extent feature class, the third is the output raster location and name. Hopefully this gets you going in the right direction. Best, Chris B.
... View more
12-12-2013
12:50 PM
|
0
|
0
|
868
|
POST
|
Mel, Just so I understand everything correctly, and I should have asked this first but: Are you clipping each raster with the same extent polygon? Are all of the rasters in the same folder, or geodatabase? If the answer is yes to both of these, then I can walk you through setting up a very easy to use model. Just let me know. Thanks, Chris B.
... View more
12-12-2013
12:18 PM
|
0
|
0
|
868
|
POST
|
Mel, Rather than using the Clip Raster is Batch mode, have you considered creating a model to iterate through your rasters and clip them? For a better explanation on ModelBuilder and Iterators see this page. Hope this helps! Best, Chris B.
... View more
12-12-2013
11:24 AM
|
0
|
0
|
868
|
POST
|
Jamal, Can you try the following: From the services window, right-click ArcGIS Server, select Properties. Click the Log On tab of the Properties window. Make sure the appropriate account is assigned to login, and retype the password into the Password and Confirm Password inputs. Click Ok and try starting the service now. Let us know if the error still comes up. Best, Chris B.
... View more
10-14-2013
10:28 AM
|
0
|
0
|
1617
|
Title | Kudos | Posted |
---|---|---|
1 | 07-22-2013 10:30 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|