|
POST
|
I can make a record set from a feature class in catalog, but cant seem to use the RecordSet class in python. The help for the class says that the load property can "Import a feature class into the RecordSet object." Trying to do this in python returns the error "Cannot load a feature class into a RecordSet." Any ideas? I have tried: recordset=arcpy.RecordSet(r'\\Bay-gis\GIS Staff\Parcel_Processor.gdb\Target_Data\parcels_loaded') and recordset=arcpy.RecordSet() recordset.load(r'\\Bay-gis\GIS Staff\Parcel_Processor.gdb\Target_Data\parcels_loaded')
... View more
12-16-2010
04:00 AM
|
0
|
2
|
1253
|
|
POST
|
Well you would create two layer objects with arcpy.mapping and then iterate over them changing the definition queries using the definitionQuery attribute of the layer. Create_Layers for layer in layers: layer.definitionQuery='[pid] = 4' http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/
... View more
12-15-2010
09:48 AM
|
0
|
0
|
599
|
|
POST
|
For this method just make a list of those fields and iterate over them to make your rows. So the variable "header" would be ["ID", "x_1", "y_2", "i", "r", "height"]. I have found a flaw with this though. Using the csv library is great if you are reading and writing a csv, but if you are only writing as is the case here, it is actually better to use the built in file object instead because the csv library cant write non-ascii text. This isnt always an issue but occasionally you may get some odd unicode character in on accident. The benefit of using the csv library is that you dont have to worry about putting in your \n or joining the list into a string. The library does that for you. Here I used describe to list the fields and iterate over that. You can take that out if you would like and only put in a list of the fields you want to use.
outfile=open(YOUR CSV.csv'w') #Open a new file to write
FeatureClass=arcpy.Describe(YOUR FEATURE CLASS)
fields=FeatureClass.Fields #Use arcpy.Describe to get the field names from the export of parce_test
header=[] #An empty list that will be populated with the field names
for field in fields: #For a field in the list fields,
header.append(field.name) #append the name to the header list
outfile.write('%s\n' % ','.join(header[2:]))#Write the header list to the TXT. The list the sliced using [2:] to drop the first two list items which are OID and Shape because I dont want them
cursor=arcpy.SearchCursor(YOUR FEATURE CLASS)
for row in cursor
try:
line=[]#Empty list to hold the data for the each row
for field in fields:#Same deal as before. For a field in the list fields,
line.append(row.GetValue(field.Name))#add that to the end of the list "line" and repeat till out of fields
outfile.write('%s\n' % ','.join(line[2:]))#Write the list to the TXT, again dropping the first two fields
except:
print 'Borked row: %s' % row.OID #If a line has a problem print the OID and move on.
del cursor #Delete the cursor object because this is what is holding a schema lock
outfile.close()#Close the TXT so that a lock is dropped from it as well.
Yours could be:
outfile=open(YOUR CSV.csv'w') #Open a new file to write
header=["ID", "x_1", "y_2", "i", "r", "height"]
outfile.write('%s\n' % ','.join(header))#Write the header list to the TXT.
cursor=arcpy.SearchCursor(YOUR LIDAR)
for row in cursor
try:
line=[]
for field in header:
line.append(row.GetValue(field))
outfile.write('%s\n' % ','.join(line))
except:
print 'Borked row: %s' % row.OID
del cursor
outfile.close()
... View more
12-15-2010
05:42 AM
|
0
|
0
|
1456
|
|
POST
|
Two reasons why you should switch to arcpy: 1. You can use a for loop to iterate cursors in arcpy which is better than while loops. 2. arcpy.mapping lets you edit mxds programatically. Case sensitivity is irritating though. getValue() not getvalue() or GetValue()
... View more
12-15-2010
05:15 AM
|
0
|
0
|
1358
|
|
POST
|
well you are telling the line to replace " " with "N". Try "" instead of " ". This is replacing an empty string instead of a string that contains only a space character.
... View more
12-15-2010
05:07 AM
|
0
|
0
|
6226
|
|
POST
|
Why make them in memory? Try writing to disk and see if that helps. It may be slower but it also may complete.
... View more
12-14-2010
04:55 AM
|
0
|
0
|
2569
|
|
POST
|
Using the polygon.centroid gives you the true centroid, your red x, if it is inside the polygon. It if falls outside the polygon you are given the label point which is always inside by default. You can use the polygon.trueCentroid method to get the actual centroid regardless of its placement.
... View more
12-13-2010
08:44 AM
|
0
|
0
|
1157
|
|
POST
|
You can save arcpy.Geometry objects to a dictionary. If you create the object instead of just reading it out from the cursor. Using an arcpy.array (I havnt tried using a normal python array) to store points to use with arcpy.Polygon will make an object you can save to and use from a dictionary. Populating a dictionary with the geometry objects taht way works and doesnt take very long even for a large FC. I used it successfully to compare the centroids of one FC to the polygons of another. I just used the example from the Reading Geometries page to populate the arrays.
... View more
12-13-2010
05:16 AM
|
0
|
0
|
1157
|
|
POST
|
Have you tried swearing instead of cursing? Sorry i had to get that out. Have you tried editing the fc in arcmap? Print the results of gp.listfeatureclasses() and see if there is an error there. It could be the returned value has a problem.
... View more
12-09-2010
09:31 AM
|
0
|
0
|
1081
|
|
POST
|
Its something about copying the whole shape field value and not an issue with the polygon class its self. If you the points of a polygon and add them to an array you can store sucessfully the polygon they create or just the array and make the polygon sucessfully on the fly. Making them on the fly however is rather slow. Making the polys from array and storing those takes a couple minutes for a large number of polys but not too long. Comparing a large number of geometries to another large group of geometries is rather slow however using this method.
... View more
12-08-2010
11:38 AM
|
0
|
0
|
1157
|
|
POST
|
Well it isnt that it is locked. Thats the whole point of the SDE, a central database that handles data reconciliation from multiple editors. Have you tried accessing the data from outside the for loop? Try arcpy.SearchCursor with the path hard coded in and see what happens. And try it from the python windo in arcmap.
... View more
12-08-2010
10:07 AM
|
0
|
0
|
1081
|
|
POST
|
Nope. We don get one this time around. A lot have asked for it but esri has been pretty firm on not making one.
... View more
12-06-2010
04:46 AM
|
0
|
0
|
765
|
|
POST
|
Ah ok. Well you need only to know which field holds the subtype values.
for FC in listofFC:
s_cursor=arcpy.SearchCursor(FC)
subtypes=[]
for row in s_cursor:
subtypes.append(row.getValue(subtypefield))
subtypes=set(subtypes)
for i in subtypes:
do the stuff you need to for each subtype
Getting the list of values and then making them a set will take [a,a,a,b,c,v,v,c,b] and make it [a,b,c,v].
... View more
12-06-2010
04:32 AM
|
0
|
0
|
962
|
|
POST
|
I can see what you mean about corrupting the geometry. I can write it all out to a dictionary, but trying to use the geometry object crashes python. I first tried comparing it in the normal manner and that didnt work so I tried making it a polygon object with arcpy.Polygon but that crashed as well. I think im going to try writing out the vertex array as a value in teh dictionary and creating the polygon objects on the fly from those. Sorry if this post has turned into a place to deposit my thoughts. I hope to actually post something that not only works but isnt wildly ineffiecient.
... View more
12-03-2010
11:03 AM
|
0
|
0
|
1482
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-03-2015 11:33 AM | |
| 1 | 09-23-2015 10:50 AM | |
| 1 | 12-14-2015 10:42 AM | |
| 1 | 12-14-2015 01:10 PM | |
| 1 | 12-04-2015 08:19 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|