Tag Info

Hot answers tagged

5

I can crush this down to 3 lines of code, no cursors required! import arcpy arcpy.SpatialJoin_analysis("Site", "points","in_memory/points_SpatialJoin", "JOIN_ONE_TO_MANY", "KEEP_ALL", "", "INTERSECT") arcpy.Statistics_analysis("points_SpatialJoin", "in_memory/stats", "Join_Count SUM","Id") Then simply sort the table to find the polygon with most points.


5

The following approach uses a Search Cursor and Python dictionary to perform the following workflow: Select points within each polygon feature Update dictionary with key (OID) and value (point count) for each iteration Find max point value and corresponding OID and write to a text file import arcpy, os points = r'C:\temp\mytest\points.shp' polys = ...


5

You have to insert a list, you're inserting a single value. for uv in uniqueList: cursor.insertRow(uv) should be for uv in uniqueList: cursor.insertRow([uv])


4

The error is due to the fact that you're using a tuple (returned from your cursor) as your input for your MakeFeatureLayer_management. This function requires a feature class or layer as its input. If you're wanting to know where your layers lie in relationship to a polygon, I suggest using a spatial join as opposed to a cursor. It is faster, and a good ...


4

You are trying to put a string into the insertRow method, but that method expects a list or tuple. The insertrow method first counts the items in the list or tuple to see if the item count matches the row field count, but since a string item count is most likely 0 it always fails to match up with the field count of the row (i.e., 1). So instead try ...


3

The problem is that you don't close the stream and flush the buffer to disk. No problem with Arcpy part. Just change you code like this: #open it up, the w means we will write to it f = open(outfile_path, 'wb') writer = csv.writer(f) ... f.close() import arcpy arcpy.TableToTable_conversion(outfile_path, "C:\dev_folder\orginalDev.gdb", "jsoncsv2")


3

In the requester's mxd, if you go to the Customize drop-down and then select Customize Mode (This is in 10.1. I can't remember if 9.3 was exactly the same, but either way look for Customize Mode somewhere), and then right-click on the button in the toolbar do you get the option to View Source? At 9.3 you could make buttons that fired VBA which in turn fired ...


3

Not very elegant but this should work: output = Dir + "\\" + (fc[:2]+"_"+fc.split("_")[1][:-4])[:13] By the way, not sure if there was an indentation issue when you pasted the code in GIS.SE, but the for loop should be something like: # Loop for fc in fcList: output = Dir + "\\" + (fc[:2]+"_"+fc.split("_")[1][:-4])[:13] # Process: Polygon to ...


3

You have to get the mxd parameter in the Python code as a string first and then create an ArcMap document object. In the script tool properties, you can still use the parameters data type you've specified, but you cannot pass directly this object to the arcpy code. mxd = arcpy.GetParameterAsText(0) mxd_doc = arcpy.mapping.MapDocument(mxd) #create an ...


2

I would use below code-- If you have access to "Data Access Module" import arcpy,os,sys pattern = 'fish_46.shp' folder = 'C:\Users\USER_NAME\Desktop\delete'## root folder field = 'Id' ## your field where calculation to be applied files_process = [] for root,dirs,files in os.walk('C:\Users\USER_NAME\Desktop\delete'): for filenames in files: if ...


2

The trick to doing this is to first create a legend style item either in your user style file or in a custom style file. For the sake of simplicity, I'll show you how to do it using your user style. In ArcMap, go to Customize > Style Manager You should see a folder in the Style Manager which references the user style file ArcGIS auto-creates to store all ...


2

As of 10.3, there are new attributes on the Extension object that may be of use to you: the Extension.currentLayer and Extension.editSelection properties.


2

You should use the "Group Analysis" tool to achieve your goal. This tools is a great tool from "spatial statistics" toolbox as @phloem pointed to. However you should fine tune the tool to adapt to your data and problem. I created a similar scenario like the one you posted and got the response close to your goal. Hint: Using ArcGIS 10.2, when I ran the tool, ...


2

Original set: Create pseudo-copy (CNTRL-drag in TOC) of it and make spatial join one to many with clone. In this case I used distance 500m. Output table: Remove records from this table where PAR_ID = PAR_ID_1 - easy. Iterate through table and remove records where (PAR_ID,PAR_ID_1 )=(PAR_ID_1, PAR_ID) of any record above it. Not so easy, use acrpy. ...


2

This is a known issue. The current version of scipy (actually numpy) is not compatible with python distribution that comes with ArcGIS, although theoretically they should. The core reason is that scipy is not pure Python (for speed) and hence it matters which API against which things have been compiled. I had that issue and I never found a compatible ...


2

I think your code doesn't work because MakeFeatureLayer_management() creates a layer (in memory) , not a layer file (.lyr). Just replace your TablesView variable, e.g. TablesView = "TablesView" and you shouldn't get that error anymore.


2

Here's how to find all the mxds in a directory tree using the os module: import os for root, dirs, files in os.walk('C:/junk'): for file in files: if os.path.splitext(file)[1] == '.mxd': print 'It is an MXD!'


2

Python add-ins are new to 10.1. So your 9.3 user won't be able to use one. If he decides to migrate to 10.1 or higher (wouldn't be a bad thing after all, 9.3 is not supported for a while): Add-ins are stored in your user's profile (...\My Documents\ArcGIS\AddIns). I don't think you can use/find the add-in if you didn't install it on your machine. But if ...


1

Instead of: for fields in arcpy.Listfields(Feature): print fields try: for field in arcpy.Listfields(Feature): print field.name My changing of fields to field is not important but I think it makes the code read better. However, what is important is that ListFields returns a list of field objects and so you need to examine the name property of each ...


1

The Try/except does work - the problem here is GP Services have defined inputs and outputs. When you publish it and go look at the REST end point of the service, you'll see how these items are defined. Your service expects an output of a certain type. When your service "fails", it doesn't return whats expected of it and you get that error. If you don't want ...


1

My favorite shortcut for this is to run the Append tool once using the standard toolbox tool and set up my field mappings using the graphic interface. Then when the tool is done running, open the results window, right click on the information about the operation you just ran and click "Copy as Python Snippet". Then you can paste the code into your ...


1

Below code works for me. I do two types of filtering (firstly select all features name start with "One" and then those features from these selected features which have word "domain" in the name) to select features and run merge operation on that features. import arcpy arcpy.env.overwriteOutput = True arcpy.env.workspace = ...


1

As per this question I think you (or your IT staff) need to run the autorun.exe application, it will launch the startup window (otherwise known as the Quick Start Guide) of the 10.2 installation for Desktop. From here you can install the 64-bit BGP. I realize that this refers to 10.2 not 10.2.2 but I think it is the same process. Just a side ...


1

After doing a bit of forum research, it appears you might be bumping into a few things. Restart the machine (worth a shot) Turn off background geoprocessing (You've done this) Check the name of any output/input files for any tools I would maybe put a print statement after the assignment of the "outfile" variable print outfile Take a look at the ...


1

Presumably these are text elements so you should be able to go into Layout or Data View of ArcMap and use the Select tool from the Draw toolbar to click on them, and then hit the Delete key to remove them. If this works, but next time you run your ArcPy script they come back, then you will need to try and debug your script.


1

Instead of using: where_clause = '"COMPANY" = \'company_query\'' I think the simplest (of many) ways is to use: where_clause = '"COMPANY" = ' + "'" + company_query + "'" Around company_query I have double-single-double quotes and before COMPANY there is a single-double quote.


1

Hi there i had a similar issue as this before , so i had given it some though , never got another started with , it but just on the thoery side i was thinking INPUT SHAPE i was thinking you could create a fishnet on the input shape fishnet with an intersect of you input shape would then You can then calculate the area of these parcels inside the ...


1

basically you want an equal size clustering method, so you could search with this key words on the web. For me, there is a good answer on stats.SE with a Python implementation in one of the answers. If you are familiar with arcpy you should be able to use it with your data. You first need to compute the X and Y of your polygons' centroids, then you can ...


1

You are receiving that error because you are not providing one of the supported data types to Merge_management: Input datasets can be point, line, or polygon feature classes or tables. You can create a Layer object from a shapefile and save the Layer as a Layer file. However, you need to be aware that the spatial data is not saved as part of the ...


1

Closing ArcMap solved the problem. I thought the problem will be because of the rapid field adding and I found a lot of articles on the web speaking about the problem. Well, it has been solved.



Only top voted, non community-wiki answers of a minimum length are eligible