|
POST
|
Dan, thanks for the insight and what a treasure trove in the article you wrote! Thanks!
... View more
09-28-2016
05:25 AM
|
0
|
0
|
2876
|
|
POST
|
Dan_Patterson Thanks so much for the suggestions! I'm currently in the process of adding rotation to each line with some basic trig. Regarding your suggestions: I implemented this; was totally unaware of this. Thanks! Are you suggesting I un-nest the two cursors? Again, I'm a real hack here, so if you had an example or reference that would be great. Any harsh words/warnings regarding poor practice of the structure of cursors as they are now?
... View more
09-27-2016
01:12 PM
|
0
|
4
|
2876
|
|
POST
|
Thanks! I just stumbled across another post wherein which someone was recalling words from you Dan Patterson about setting the spatial reference...tried that and it wasn't the issue. I cleaned up the code a bit. Again, I'm totally up to suggestions, but this works! startingPt = "STARTING_POINTS" #point feature layer in MXD fields = ['SHAPE@X', 'SHAPE@Y'] #point = arcpy.Point() array = arcpy.Array() sr = arcpy.Describe(startingPt).spatialReference insert = arcpy.da.InsertCursor(r"D:\Temp\Lines.shp",['SHAPE@']) with arcpy.da.SearchCursor(startingPt, fields) as cursor: for row in cursor: startX = row[0] startY = row[1] endX = startX + 660 endY = startY + 660 array.add(arcpy.Point(startX, startY)) array.add(arcpy.Point(endX, endY)) insert = arcpy.da.InsertCursor(r"D:\Temp\Lines.shp",['SHAPE@']) polyline = arcpy.Polyline(array,sr) insert.insertRow([polyline]) array.removeAll() print "Start: {},{} End: {},{}".format(startX,startY,endX,endY) del cursor
... View more
09-27-2016
12:45 PM
|
0
|
6
|
2876
|
|
POST
|
I'll preface this by saying I'm pretty weak on cursors but trying to boot camp myself to basic proficiency. I'm trying to create a simple script that will take a point feature class and create lines from them. These points are the start point of the the line and for sake of demonstration here, the endpoints are defined mathematically from them. Simple 2-point lines. startingPt = "STARTING_POINTS" #point feature layer in MXD fields = ['SHAPE@X', 'SHAPE@Y'] point = arcpy.Point() array = arcpy.Array() featureList = [] insert = arcpy.da.InsertCursor(r"D:\Temp\Lines.shp",['SHAPE@']) with arcpy.da.SearchCursor(startingPt, fields) as cursor: for row in cursor: startX = row[0] startY = row[1] array.add(point) endX = startX + 660 endY = startY + 660 array.add(point) polyline = arcpy.Polyline(array) insert = arcpy.da.InsertCursor(r"D:\Temp\Lines.shp",['SHAPE@']) insert.insertRow([polyline]) print "Start: {},{} End: {},{}".format(startX,startY,endX,endY) del cursor The script successfully writes rows to the target, but the geometry is empty. I'm sure there is a simple (and stupid) mistake in the code. Any help is appreciated and I'm totally open to suggestions. I'd rather not have a copy features or append operation but just an insert unless my logic is totally flawed here. Thanks!
... View more
09-27-2016
12:03 PM
|
0
|
17
|
6918
|
|
POST
|
Jake, this is great and will totally get me there. To be clear, is there a way to build the sql query using a logical operator 'AND'? Here's an attempt but the query fails: def SelectRandomByCount (layer, count): import random layerCount = int (arcpy.GetCount_management (layer).getOutput (0)) if layerCount < count: print "input count is greater than layer count" return oids = [oid for oid, in arcpy.da.SearchCursor (layer, "OID@")] oidFldName = arcpy.Describe (layer).OIDFieldName delimOidFld = arcpy.AddFieldDelimiters (layer, oidFldName) TypeField = arcpy.AddFieldDelimiters (layer, "OS_TYPE") #TypeField = "OS_TYPE" Type = 'S3A' randOids = random.sample (oids, count) oidsStr = ", ".join (map (str, randOids)) sql = """ {0} IN ({1}) AND {2} = '{3}' """.format (delimOidFld, oidsStr, TypeField, Type) print sql arcpy.SelectLayerByAttribute_management (layer, "", sql) [EDIT: fixed...i just had to for I ask this because what I'm actually looking to do this for the same field to satisfy 5 different queries...say for "FIELD" = 'Value1', then "FIELD" = 'Value2'...etc. I guess that would be a loop within a loop? If this qualifies as another question altogether, I'll mark yours as correct. I'll hammer away at this, but do appreciate the insight!
... View more
09-22-2016
08:16 AM
|
1
|
2
|
1097
|
|
POST
|
Basically I'm trying to create a selection that satisfies a random criteria AND a query based on an attribute field. Here is some sample code I found on StackExchange: def SelectRandomByCount (layer, count): import random layerCount = int (arcpy.GetCount_management (layer).getOutput (0)) if layerCount < count: print "input count is greater than layer count" return oids = [oid for oid, in arcpy.da.SearchCursor (layer, "OID@")] oidFldName = arcpy.Describe (layer).OIDFieldName delimOidFld = arcpy.AddFieldDelimiters (layer, oidFldName) randOids = random.sample (oids, count) oidsStr = ", ".join (map (str, randOids)) sql = "{0} IN ({1})".format (delimOidFld, oidsStr) arcpy.SelectLayerByAttribute_management (layer, "", sql) What I need is this in conjunction with a query (from the same input later) where FIELD = Value (for a string field). I have reviewed the ESRI help document related to Specifying a query in Python, but am having difficulty understanding how to implement this.
... View more
09-22-2016
07:47 AM
|
0
|
4
|
2124
|
|
POST
|
I got it to work!!! Nice way to close out the day...for some reason the OID field needed single quotes too. If you want to modify your code I'll mark your answer as accepted. Cluster_Plot = '"{}-{}"'.format(i,'!OBJECTID!')
... View more
09-14-2016
01:03 PM
|
1
|
1
|
2509
|
|
POST
|
Hi Micah...I'm just getting a generic 'invalid syntax' error. for the first option. The second wont work because the OIDs aren't coming from the FC used to run the loop/search cursor.
... View more
09-14-2016
11:53 AM
|
0
|
3
|
2509
|
|
POST
|
OK, so I feel like I've tried just about everything here. What I'm looking to do is to concatenate a iteration value (?) from a search cursor with the object ID of a feature class to create a unique ID field. I want these two values separated by a hyphen '-'. Target field (PLOT_ID) is obviously a string. There is what I've got working so far. i = 1 ptCur = arcpy.da.SearchCursor (ptFC, fldLst) for row in ptCur: [various things happen removed for brevity] Cluster_Plot = str(i) + '!OBJECTID!' arcpy.AddMessage(Cluster_Plot) arcpy.CalculateField_management(outPointsDissolve,"PLOT_ID",Cluster_Plot,"PYTHON_9.3") things are appended to a a target FC and the target field looks like this: So it appears to be treating the expression inputs as strings. From here I've tried to get a - in between the two values with no luck....even when converting the OID to a string : 'str(!OBJECTID!)' I just can't get things to escape right i guess. Things I've tried: Cluster_Plot = str(i) + '-' + '!OBJECTID!' Here the hyphen apparently is interpreted as an operator: Cluster_Plot = str(i) + " + '-' + " + '!OBJECTID!' Cluster_Plot = str(i) + " + '-' + " + 'str(!OBJECTID!)' I dont get this because you can use the + operator in the field calculator just fine (if you format the field as a string using str) Could someone please help me out of my misery here?
... View more
09-14-2016
11:36 AM
|
0
|
5
|
4109
|
|
POST
|
I've been searching high and low for this (Stackoverflow/exchange, etc, Geonet...). Here it goes. I have a table with a number of records. I have a field called 'Rotation' I would like to populate with a repeating set of values [0,90,180,270]. So imagine the following: PT_ID ROTATION 1 0 2 90 3 180 4 270 5 0 6 90 7 180 8 270 9 0 I've tried to simplify my question as much as possible, but its literally as simple as that. Most of the searches return information related to deleting duplicate/repeated records & values.
... View more
09-09-2016
08:47 AM
|
0
|
3
|
1419
|
|
POST
|
Or, should I just be thinking about hosting my own GP service as a solution?
... View more
08-16-2016
10:19 AM
|
0
|
1
|
1015
|
|
DOC
|
David, I'm having the exact same behavior with my custom templates and using our own export web map GP service. I couldn't describe the behavior any better. However, similar to Rob's (?) observation from earlier in the thread I get the warning about trying to print a map: "You have requested a print with a scale larger than the maximum scale of the map. If you proceed, some of the layers will not be printed." Then the map display grays out. I know the GP service works fine with the included print widget so I have no reason to expect something is up there. I do wonder how much more we would need to manually edit in the print plus' config.json, however, to get the parameters correct? Not sure why we'd need to if the out of box one doesn't need any special configuration (but instead gets this info from the GP service itself...or so it seems). A big thanks to Larry Stout for this as the additional functionality will be very helpful for our users (if I can get it configured right).
... View more
12-10-2015
11:31 AM
|
0
|
0
|
9530
|
|
POST
|
Rebecca Strauch, GISP I did read that, but perhaps I misinterpreted what was said? The way I read this was that within the JSON file you'd be able to parse the output to retrieve the different data types, but that doesn't appear to be the case.
... View more
10-19-2015
05:11 AM
|
0
|
0
|
1721
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-06-2024 06:58 AM | |
| 1 | 12-16-2022 07:01 AM | |
| 1 | 08-09-2024 06:55 AM | |
| 1 | 08-13-2024 05:58 PM | |
| 1 | 07-23-2024 08:00 AM |
| Online Status |
Offline
|
| Date Last Visited |
10-24-2025
05:12 AM
|