POST
|
The only approach I can think of is to start by getting the bounding box for your polygon layer. From that, you could create 4 polygons, one for each quadrant of the bounding box. Then you would do a spatial selection and count (using arcpy.GetCount_management) the number of polygons inside each quadrant. Then you could would start with the upper-right quadrant. If the number of polygons is to high, then you 'assign' the polygons closest to the left edge to the upper left quadrant (regardless of how many are in that quadrant) and increase the sum you got for the upper left quadrant. If there are too few (or 20), you do nothing. Now you move to the upper left quadrant. If it contains more than 1/4 of the polygons, you find the n closest polygons to its lower edge where n is however many to great the polygon count is to the lower-left polygon and increase the lower left quadrant's count. For the lower-left polygon, you again assess the count and if it is to great, you move extra polygons from the top edge into the top-right polygon. You may have to loop through this a few times, but I don't think you could possibly have to loop more than twice. Also, you would check between each step and if the count for each quadrant is what you want, then you stop immediately. I can draw it out on paper and I think this would work and get a result something like what you want, but I don't have any code to share with you. I think it should be a lot faster than looping through every possible mix of polygons to identify the ideal distribution Hope this helps, - Doug
... View more
08-08-2014
12:46 PM
|
0
|
2
|
449
|
POST
|
I'm happy to help. Thanks for pointing that out! I hadn't been able to figure it out till now.
... View more
07-31-2014
06:44 AM
|
0
|
0
|
882
|
POST
|
You shouldn't be plugging in the slopes into the function. The equation says that it takes the tangent of the slope. Also, I would doubt that slope should be in degrees if it is going into a trig function. In any case, python uses radians so you'll need to convert to radians to use the tangent function: 6 * math.exp(-3.5 * abs(math.tan(math.radians(degrees)) + 0.05))) For a sanity check, put in a values of the 5th value (0) and the 1st value: def hike(degrees): return 6 * math.exp(-3.5 * abs(math.tan(math.radians(degrees)) + 0.05)) hike(0) 5.036742124615245 hike(-1.0312126698879267) 5.3642655450021355 Both of which checks yield results around 5 km/h which is expected given the input of 0 and a near 0 slope. Hopefully this helps! Could you tell me - how is it you format code on the new forums?
... View more
07-30-2014
10:52 AM
|
0
|
5
|
882
|
POST
|
Perhaps try this?
import arcpy, sys, math, os, datetime, traceback
import arcpy.mapping as map
from arcpy import da, env
XYPointsLayer = layerMemory + os.sep + "XYPointsLayer"
#XYPointsLayerIntersect = layerMemory + os.sep + "XYPointsLayerIntersect"
#arcpy.MakeXYEventLayer_management(WorkLayerName, viewName + ".GRID_X", viewName + ".GRID_Y", XYPointsLayer)
arcpy.MakeXYEventLayer_management(fullviewName, "GRID_X", "GRID_Y", XYPointsLayer)
#### Note looks like using the view directly may work instead of the MakeQueryTable option
XYPointsLayerIntersect = arcpy.MakeTableView_management(XYPointsLayer, "Test")
#arcpy.MakeFeatureLayer_management(XYPointsLayer, XYPointsLayerIntersect)
viewName = "DWOP.DBO.VWO_MDPAG_DPA_WORK"
fullviewName = arcpy.env.workspace + os.sep + viewName
arcpy.SelectLayerByAttribute_management(XYPointsLayerIntersect,"CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management(XYPointsLayerIntersect,"NEW_SELECTION","TIMESTAMP0 = '20140613 08:59:58.063' and FK_ROADLINK_TOID = 'PEGASUS005108964' and AP_ID_ARRAY1 = '141863003'")
The only thing that I can think of is that arcpy is interpreting the string value you were setting for XYPointsLayerIntersect as a file path, not a layer name.
... View more
06-16-2014
05:54 AM
|
0
|
0
|
204
|
POST
|
The first thing I see is that your input parameters have some unclosed parenthesis. Also, I would recommend trying to print out the values of newpage and pageID as you go. It might yield some good insights on what is happening. Also since all you do with your Data Frame object (df) is create it and then delete it you can probably skip creating it all together. - Doug
... View more
04-24-2014
07:34 AM
|
0
|
0
|
220
|
POST
|
With Python, the only way to do this is to create a layer file in advance and then have your output reference that file. http://forums.arcgis.com/threads/44502-Managing-Symbology-using-Python
... View more
04-23-2014
05:08 AM
|
0
|
0
|
408
|
POST
|
IOError: [Errno 2] No such file or directory: 'C:\\Student\\PythEveryone10_1\\Creating Scripts\\BismarckUpd.txt' This is the key here. The file doesn't exist in that location. Try browsing to that file location and look for the file called BismarckUpd.txt. If it isn't there, then there is no way for python to open it. Since you are opening it in 'w' (write) mode, then I'd assume that the file path is the part that is incorrect. If the folders all existed, then python would have created an empty .txt file with the name BismarkUpd.txt in that folder. - Doug
... View more
04-18-2014
10:05 AM
|
1
|
0
|
672
|
POST
|
Hi Padmasiri, The problem is that the delete features tool removes the features from a feature class or layer (empties it). This is why the result is the name of the feature class you put into the tool. Because you want to delete the dataset completely, you want to use the delete tool:
import arcpy
from arcpy import env
env.workspace = r"J:\Gampaha\51027202\CM51027202.gdb\CM51027202"
FClass_List = ["CNT_Anno", "CNT_Anno_CD", "CNT_PT", "PCL_CT1"]
for FClass in FClass_List:
arcpy.Delete_management(FClass)
Also, if you wrap scripts in code tags when posting, it will display a bit cleaner (like the above). Hope this helps! - Doug
... View more
04-17-2014
04:41 AM
|
0
|
0
|
132
|
POST
|
Since you've numbered your questions I'll try and address them in the same way: 1. Could this be related to the way you are updating the field list in the updateParameters() method? Have you tried:
class SetValues(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Set Values"
self.description = "Sets the values for several fields to a set numeric value, for all features in the selection set"
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
params = None
param0 = arcpy.Parameter(
displayName="Choose Layer",
name="layer",
datatype="GPLayer",
parameterType="Required",
direction="Input")
param1 = arcpy.Parameter(
displayName="Choose Fields",
name="field_list",
datatype="GPString",
parameterType="Required",
direction="Input",
multiValue=True)
param1.parameterDependencies = [param0.name]
Then change updateParameters to:
def updateParameters(self, parameters):
return
I'm not sure if this will fix the problem, but it may be a simpler way of accomplishing what you've done. 2. Not sure about this one. 3. Instead of setting cursor to None, try:
del cursor
The with statement won't to delete the object you created. For example:
sample_file = 'C:\\New_Text_file.txt'
with open(sample_file, 'w') as f:
f.write('Sample Text')
f
would return: <closed file 'C:\\New_Text_file.txt', mode 'w' at 0x0000000004BAAC90> I'm not 100% on this, but I don't think that setting the cursor variable to None will delete the object you created. Hope this helps! - Doug
... View more
04-09-2014
05:12 AM
|
0
|
0
|
354
|
POST
|
for row in wtlndRow:
if row.WtlndUnitID is None:
totalArea = 0
wtlndUnitID += 1
adjWtlnd = arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd")
arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH",row.shape, "", "NEW_SELECTION")
numPolys = 1
count = 0
while numPolys != count:
numPolys = arcpy.GetCount_management(adjWtlnd)
arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH", wtlnd4Units,"", "ADD_TO_SELECTION")
count = arcpy.GetCount_management(adjWtlnd)
Cant figure out why this wont evaluate to true. Thanks! Alicia Have you tried printing the values of numPolys and count to the screen? Could provide a hint...
... View more
03-11-2014
11:44 AM
|
0
|
0
|
627
|
POST
|
Hello Alicia, I don't think you can use arcpy.MakeFeatureLayer_management like that. I think you have to refer to the feature layer using "in_memory\\adjWtlnd". Try changing: adjWtlnd = arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd") To: arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd")
adjWtlnd = "in_memory\\adjWtlnd" Just to clarify, the code as written initially adjWtlnd = arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd") should be fine, unless in memory layers work differently for some reason. This is how I always create feature layers, as it saves a line of code and you don't have to worry so much about typos. MakeFeatureLayer_management returns a string, which is the name of the created layer.
... View more
03-11-2014
11:42 AM
|
0
|
0
|
627
|
POST
|
A am making hundreds of plat maps using parcel data. Many of the maps have several parcels per map. Each parcel needs to be a seperate color and I would like to use the same colors so the maps will have a standardized look. However the parcels are always different values so label files have not worked. I tried to add a field to my data, that denotes the parcels 1 through x and assigning the numbers 1 though 10 colors through a layer file, but then I would need to change the symbol description so that the parcel number will be listed with in the legend. Once that is done I am exporting these maps to PDF. Essentially I would like to have a script that would automate the whole process from the data, and automatically export the maps. Everything seems do-able except the issue with not being able to use my own colors. Can anyone provide a solution or advice. Thanks I've been in similar situations before. Unfortunately, I have bad news... If you can create a single layer file based on the entire set of parcel maps, then you can do what you want. However the layer file must be created and saved first - your script will just reference it. If you want to create the layer colors dynamically for each map this is not possible because layer files cannot be created in arcpy and the layer symbology properties for colors etc are unavailable. See this thread : http://forums.arcgis.com/threads/44502-Managing-Symbology-using-Python And this post to ArcGIS Ideas: http://ideas.arcgis.com/ideaView?id=087300000008FolAAE Good luck, -Doug
... View more
03-11-2014
11:06 AM
|
0
|
0
|
203
|
POST
|
To your first question about comparing to a specific date:
import datetime
filedate = datetime.fromtimestamp(os.path.getmtime(rootpath + "/" + fName)) #filedate = datetime.date(2014, 1, 27)
today = datetime.now
maxdate = datetime.date(2011, 7, 2)
#Only do work if the number of days since the last change is less than the number of days since a 'too long ago' date.
if (filedate - today).days < (filedate - maxdate).days:
print('Work on this file')
else:
print('Do nothing')
When I try and test the 2nd issue you bring up, I don't see the same result as you: >>> import datetime >>> test = datetime.date(2011, 7, 2) >>> print test 2011-07-02 >>> str(test) '2011-07-02' >>> It works for me as would be expected, so I don't have a good answer for you regarding that issue. - Doug
... View more
01-30-2014
06:40 AM
|
1
|
0
|
1079
|
POST
|
Not knowing how you are getting the date that you are comparing to, for example if it is coded in the script or part of a tools input parameters, I'd say the easiest thing to do is get YYYY MM DD from the files and from your parameter. Then you could use the datetime library in python to do the comparisons. For example:
import datetime
filedate = datetime.date(2014, 1, 27)
comparedate = datetime.date(2013, 12, 31)
if (filedate - comparedate).days > 0:
print('Work on this file')
else:
print('Do nothing')
Would print
>>> Work on this file
The idea being that if you have a positive number of days between the file date and the compare date, then the file is 'new'. If the number of days is negative (or zero if the dates are the same), it is not new, so you wouldn't do anything. Hope this helps - Doug
... View more
01-28-2014
06:32 AM
|
0
|
0
|
1079
|
POST
|
Duncan, I've had similar troubles, especially when a toolbox references another script that I've written. It seems that if I... import SomeStuffIWrote ... then changes to SomeStuffIWrote are a monumental pain to make the toolbox take. Two things I usually do every time I edit: 1. Right click on the toolbox in ArcCatalog and select refresh (works 99% of the time for me). 2. Right click on the toolbox, select edit, then close the notepad etc window that pops up. This causes it to completely refresh the tool (works in 99% of the remaining cases where # 1 doesn't work). The only case where I have had trouble is a situation where the toolbox and all of the source files sit on a network location with multiple people accessing it. For some reason no matter what I have done (delete, have everyone refresh, etc etc), for some people, their machines aren't seeing the updates. - Doug
... View more
01-23-2014
07:12 AM
|
0
|
0
|
1204
|
Title | Kudos | Posted |
---|---|---|
1 | 04-18-2014 10:05 AM | |
1 | 10-11-2013 01:21 PM | |
1 | 10-14-2013 05:59 AM | |
1 | 12-23-2013 08:54 AM | |
1 | 01-30-2014 06:40 AM |
Online Status |
Offline
|
Date Last Visited |
08-16-2021
03:34 PM
|