|
POST
|
Look at this post for the basic dictionary transfer code. Dictionaries are absolutely wonderful, but they rely on being able to link the correct two rows. From looking the code in the link, it doesn't seem to have anything to do with location, it's all based on the OBJECTID/FID field. You are assuming that OBJECTID 1 in the poly feature class is the polygon that overlaps OBJECTID 1 in the point feature class, which doesn't seem like a fair assumption at all. That is a nice piece of code though, and you could also simplify it a little bit:
if ObjectIDVal in valueDict:
for n in range (0,len(updateFieldsList)):
updateRow[n+1] = valueDict[ObjectIDVal]
updateRows.updateRow(updateRow)
... View more
06-12-2014
08:01 AM
|
0
|
0
|
3426
|
|
POST
|
In python... 1. Add fields for each attribute you want to transfer to the point feature class. Lets say you want to transfer two attributes from the polygon you would add those two fields to the point feature class. 2. Loop through the polygons and select each polygon 3. Save the two attributes you want to transfer to variables so they can be used later 4. Do a select by location to select all the points within the selected polygon 5. Use an update cursor to loop through the selected points and populate the two fields with the variables you created earlier Yes, this is basically what I have done many times to achieve this operation. Here's a little pseudo code:
#make feature layer for point shapefile
for row in arcpy.SearchCursor(polygon shapefile):
#get FID and use it to construct a query that would only select the row (polygon) that you're looking at
#make feature layer using that query so now you have a one-feature feature layer
value = row.getValue("name of field you want a value from")
#use this feature layer to make a select by location operation on the point layer you made above
updaterows = arcpy.UpdateCursor(point feature layer) #the cursor should only contain the selected feature(s)
for rw in updaterows:
rw.setValue("field name you want to put the value in",value)
updaterows.UpdateRow(rw)
... View more
06-11-2014
02:32 PM
|
0
|
0
|
3426
|
|
POST
|
OMG is right, that is fascinating. I was just finding that same issue, also with .7, .2, .1, and also running it as a stand alone script. Was thinking of how it's weird that it's only a problem when .1 is the last digit, and when there is only one .1 value. Was thinking we may need to turn to stack overflow... Well, nice work, and that looks like a good work-around. Cheers!
... View more
06-10-2014
01:34 PM
|
0
|
0
|
588
|
|
POST
|
Yes, that makes no sense. It's a very simple operation, so I bet it has to do with something silly. I just made three Double parameters, and the following code works perfectly:
import arcpy
a = arcpy.GetParameter(0)
b = arcpy.GetParameter(1)
c = arcpy.GetParameter(2)
total = a + b + c
arcpy.AddMessage(total)
if total == 1.0:
arcpy.AddMessage(" all good")
else:
arcpy.AddMessage(" all not good")
I think you should scale it back to something simple like that. If you set the parameters as required in the tool properties, the user will not be able to run it without entering something, and with Double parameters, if they enter something that is nonsense, like a letter, the parameter will automatically set to 0. Start from scratch and this should work fine. Be gentle on the hair.
... View more
06-10-2014
12:23 PM
|
0
|
0
|
2561
|
|
POST
|
Try out if str(Tot) == "1.0" It seems like it's just a type issue, so the best thing to do is just keep adding a bunch of messages and type-checking.
... View more
06-10-2014
11:44 AM
|
0
|
0
|
2561
|
|
POST
|
Well, to be sure you'll have to be more specific about how it doesn't work (is there an error? what error?). Though maybe you just need to have 1.0 instead of 1 I was just doing a little testing, and if you have the parameters as Double, you should be able to use GetParameter and the result will be a float object. Also, it looks like having a parameter set as Double will force it to 0 if nothing valid is entered, which would be useful.
... View more
06-10-2014
11:12 AM
|
0
|
0
|
2561
|
|
POST
|
For what you're trying to do, you may want to check out the Tool Validator class. Without too much trouble you'd be able to update the updateParameters function to throw a warning/error in the tool interface before your final script is actually run.
... View more
06-10-2014
10:34 AM
|
0
|
0
|
2563
|
|
POST
|
Hi Amalie, the first thing I'd try out is using GetParameterAsText, that way you are for sure dealing with a string. Then try casting it as a float for a new variable, and print the object type. Something like: Spring = arcpy.GetParameterAsText(3) if Spring == '#' or not Spring: Spring = 0.3 # provide a default value if unspecified Spring_float = float(Spring) arcpy.AddMessage(type(Spring)) Hopefully that'll work as a good first step.
... View more
06-10-2014
10:29 AM
|
0
|
0
|
2563
|
|
POST
|
Oh, wait, I'm not familiar with the RasterToPolyline tool, but taking a closer look I'm thinking that it throws an exception if it will result in an empty feature class. I don't see anything about that in the documentation, nor in the info that comes up with help(arcpy.conversion.RasterToPolyline) in IDLE. However, it'll make things a little easier for you. Instead of an if statement, you can just use a try/except situation: #Raster to Polyline arcpy.AddMessage("Saving Least Cost Path {0}..." .format(count + 1)) try: arcpy.RasterToPolyline_conversion(get_LCP(count), Output_polyline, "ZERO", "0", "SIMPLIFY", "") except: arcpy.AddMessage("Empty feature class") break The only thing to be careful of is that now any problem with the raster to polyline process will look like it's an empty feature class, even if it's a problem with a different parameter, so you'll have to be aware of that. EDIT: just a little more info.
... View more
06-03-2014
09:24 AM
|
0
|
0
|
1014
|
|
POST
|
If you modify lcpcount = arcpy.GetCount_management(fc) to lcpcount = int(arcpy.GetCount_management(fc).getOutput(0)) it should work fine. EDIT: I may not be understanding it correctly, but looking at this more closely it seems like if you just want it to break after you have created an empty feature class you could shorten the script like so:
count = 0
while count < 10:
Output_polyline = os.path.join(savepath + "\\Results.gdb" + "\\LCP_" + str(count))
End_Raster = os.path.join(savepath + "\\Scratch.gdb" + "\\End_Raster_" + str(count))
#Raster to Polyline
arcpy.AddMessage("Saving Least Cost Path {0}..." .format(count + 1))
arcpy.RasterToPolyline_conversion(get_LCP(count), Output_polyline, "ZERO", "0", "SIMPLIFY", "")
#check to see if the new Output_polyline is empty, and break if so:
if int(arcpy.management.GetCount(Output_polyline).getOutput(0)) == 0:
#you could also delete the empty feature class if you want
#arcpy.management.Delete(Output_polyline)
break
... View more
06-03-2014
07:23 AM
|
0
|
0
|
1014
|
|
POST
|
Hi Rami, I believe this previous question is very close to yours and you should be able to find the answer here: http://forums.arcgis.com/threads/8414-ArcGIS-10-user-python-arcpy-to-add-a-WMS-Service?p=391096#post391096
... View more
06-02-2014
08:36 AM
|
0
|
1
|
756
|
|
POST
|
May be worth adding a
if arcpy.Exists(outlayer1):
arcpy.management.Delete(outlayer1)
just before you make the feature layer. I know you have set the overwrite to true, but it's worth a shot in case something is going weird with that.
... View more
05-29-2014
02:40 PM
|
0
|
0
|
3097
|
|
POST
|
Hi there, one thing that looks fishy is the syntax around the where clauses you have. I always follow this format. For text fields
'"fieldname" = \'' + value + "'" #make sure value is a string
For integer fields (like OBJECTID)
'"fieldname" = ' + value #make sure value is a string (though a digit, of course)
What could be happening is that the first where clause is creating an empty feature layer, which in turn is an invalid input. Just guessing though...
... View more
05-29-2014
02:16 PM
|
0
|
0
|
3097
|
|
POST
|
but it failed with a "table already exists" error. Sounds like the newrastername already exists in the GDB? I would do a little inspection of the contents of the GDB, but if you need to remove something before proceeding, this is a useful construction:
if arcpy.Exists(newrastername):
arcpy.management.Delete(newrastername)
Just be sure to back everything up ahead of time!
... View more
05-29-2014
07:25 AM
|
0
|
0
|
765
|
|
POST
|
Yeah that would work. Usually I use the following format in order to reduce indentation:
for ras in arcpy.ListRasters:
if not ras.lower().endswith("_pa"):
continue
#now you are working with the correct raster, and you can do what you need
arcpy.management.Rename(ras,"PA_" + ras[:-3])
Though it may be tricky to get all of the auxiliary files if you are using os.rename(), right? I assume that it's not just "raster.tif", but also "raster.tif.xml" and "raster.tfw", or .jpg, etc. If you use the arcpy function, it'll rename all of the associated files at once. Also, if the rasters are stored in a fGDB or something, I don't there's anyway you'd be able to access them with the os module. It all depends on how/where they are stored.
... View more
05-29-2014
07:14 AM
|
0
|
0
|
765
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 04-03-2015 07:41 AM | |
| 1 | 04-02-2015 03:42 PM | |
| 3 | 08-14-2014 09:58 AM | |
| 1 | 08-12-2014 07:10 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:24 AM
|