Jason Bellino
  • Member for 10 years, 9 months
  • Last seen more than a week ago
  • n/a
  • Tampa, FL
Merging polygons in shapefile based on field values?
Accepted answer
31 votes

I believe the tool you are looking for is the Dissolve tool. You can specify which field you want to dissolve your feature on, so in your case you would specify "district" and it will dissolve all ...

View answer
Exporting table to XYZ ASCII file via ArcPy?
Accepted answer
31 votes

You can do this using a cursor to grab the data from your table and write to a comma-delimited text file. EDIT: I'm adding a more concise block of code to accomplish the task using the csv module of ...

View answer
Using arcpy.da.InsertCursor to insert entire row that is fetched from search cursor?
Accepted answer
21 votes

As long as your source and target FC's have the same number of fields and have the same geometry type, this should work: # Get field objects from source FC # dsc = arcpy.Describe(sourceFC) fields = ...

View answer
Why is ArcPy script slow?
Accepted answer
20 votes

If you need to create a second cursor for parcels.shp, do so outside of the loop for your first cursor. As it stands, your script is creating a new cursor object for each row in malls.shp which is ...

View answer
Reading zipped ESRI BIL files with Python
Accepted answer
9 votes

Ok, I'm sorry to post a question and then answer it myself so quickly, but I found a nice set of course slides from Utah State University that has a lecture on opening raster image data with GDAL. For ...

View answer
Listing feature classes in multiple geodatabases in folder using ArcPy?
8 votes

This script will deal with any existing feature datasets (at least in theory - I haven't tested it). Same general idea though, if there are feature datasets, you need to set your working directory to ...

View answer
Does anyone know of a good unaffiliated review of Rockworks?
Accepted answer
8 votes

I've had a bit of experience with Rockworks (ver. 14.0) and am not incredibly impressed with it. While it's fairly easy to get data into the system, generating any kind of presentation quality (let ...

View answer
Error handling with python script in ArcGIS 10
7 votes

First thing to do is bring the top of your for loop outside the try statement. You want to get into your iteration before you give the try statement a chance to kill your operation. Next you'll want ...

View answer
Select by attribute expression invalid in python
7 votes

You need to use string formatting when inserting your counter, i, into the SQL query: '\"FID\" = {}'.format(i) As it stands now, your script is asking Arc to find an object with FID = i, and that ...

View answer
Autoincrement field when New Feature added
7 votes

Here is a basic example of how you can add a new feature to a feature class with an incremental unique ID based on the last feature in said feature class: import arcpy gdb_full_path = r'c:\full\path\...

View answer
ERROR 000212: Cannot create XY event source Failed to execute (MakeXYEventLayer)?
Accepted answer
7 votes

Ths may be a bit more complicated, but if my two-cents are worth anything (and if you're using MS Office products), I'd recommend importing your .csv into an MS Access .mdb database as a table. (Note: ...

View answer
Trouble importing Feature Classes into Feature Datasets
Accepted answer
7 votes

I've had problems importing features into a feature dataset if there is another feature anywhere else in the geodatabase with the same name, even if it's not in the same dataset. I don't remember the ...

View answer
Sorting table on multiple fields using ArcPy?
Accepted answer
6 votes

You could create a new empty table and use cursors to sort your data and insert the rows into the new table (this code has not been tested): import arcpy,os inTable = r'c:\workspace\path\in_table....

View answer
Count number of attributes for unique field values in ArcGIS for Desktop?
Accepted answer
6 votes

If you are using ArcGIS I would think an easy way to do this, without creating any intermediary products, would be to select each state in your states polygon (assuming you have multipart features) ...

View answer
Pull Data from Specific Excel Cell into ArcPy
Accepted answer
6 votes

You'll need to use the xlrd module to read Microsoft Excel files (I think it's limited to .xls files only). To open your spreadsheet and read cell A2, you would use the following: import xlrd book = ...

View answer
ArcPy Insert Cursor not inserting all rows?
Accepted answer
6 votes

I had initially neglected to delete my irow object at the end of the script; after updating my code the insert cursor appears to be adding all rows (even the last one!) the way it should be. Here is ...

View answer
Loop through records
6 votes

The logic behind what you're doing is somewhat unclear, but it sounds like you're trying to sort a bunch of records on a few different fields and then go through them one at a time trying to compare ...

View answer
how do you do a buffer analysis of a geographical location?
Accepted answer
6 votes

Forgive me if I'm missing something, but it seems that all you need here is your point shapefile and the buffer tool which is located at: Analysis Tools -> Proximity -> Buffer Specify your input ...

View answer
Creating feature class in file geodatabase in ArcGIS Desktop with arcgisscripting?
Accepted answer
6 votes

I think your first problem is that you're appending ".shp" to your output geodatabase featureclass. Remove this and your problem may be solved. ... .... shpFile = "file_%s" % number #--removed "...

View answer
Running Viewshed on one feature at time in shapefile?
Accepted answer
5 votes

I've never used the viewshed tool so I can't speak to the specifics of using that tool, however in regards to your suggestion in this question I will add an answer here to build on KHibma's solution. ...

View answer
Moving all shapefiles (SHP) in MXD to new File Geodatabase (*. gdb) using ArcGIS Desktop?
Accepted answer
5 votes

I re-wrote your script to add the bit where you convert your shapefiles with unknown spatial reference into feature classes in your geodatabase. Set the variable outCS to the path of the projection ...

View answer
Failing to Delete Vector File from Personal Geodatabase?
Accepted answer
5 votes

Try opening the database using Access and deleting the geometry there. It's easy to miss a table here and there if you are deleting things by hand; that particular error message has gotten me on a ...

View answer
Using arcpy.UpdateCursor to delete rows does not delete based on counter?
5 votes

Following up with some of the comments to your post, I've cleaned up your script a bit. There are some unnecessary variables and the logic is a bit cumbersome. I obviously don't have the shapefile ...

View answer
Python Search cursor: Error handling
Accepted answer
4 votes

Since you are using Arc 10.1, use the data access module to create your search cursors. As @Paul mentions, they are much better at releasing file locks, especially when using with/as: fields = ["...

View answer
Insert Cursor fails to write results to table
Accepted answer
4 votes

First thing I would do is to create your insert cursor outside of your for loop iterating on your search cursor; you are unnecessarily creating your insert cursor for each feature in InFGDB. And with ...

View answer
selection by attributes with python
4 votes

To help debug this I would suggest cleaning up the code a bit: import arcpy from arcpy import env arcpy.env.workspace= r"E:\cities" # added raw string indicator `r` Mi= r"E:\cities\rivers.shp" # ...

View answer
Collapsing multi-row output of one-to-many spatial join to single-row in ArcPy?
Accepted answer
4 votes

Here is a bit of totally untested code that might work for you: import arcpy feat1 = 'finished_feature_class' feat2 = 'spatially_joined_feature_class' with arcpy.SearchCursor(feat2,['...

View answer
How to get a string from a Double with a fixed number of decimals?
Accepted answer
4 votes

You should be able to use string formatting: '{0:.3f}'.format(your_floating_point_value) Example: >>> '{0:.3f}'.format(34.78902345) '34.789' Here is the Python string formatting cookbook ...

View answer
Arcpy Calculate Field Formatting Syntax
Accepted answer
3 votes

You can use the built-in int() function of python to convert what appears to be a float value in the PID field to an integer: qry = '"139-{}".format(int(!PID!))' This should return PIN = 139-...

View answer
How to use Field Value from arcpy.GetParameterAsText()?
Accepted answer
3 votes

The help article for the AddField_management function states that it "Returns a delimited field name." See the example code in the document for proper usage. Essentially what you are specifying as ...

View answer