Tag Info

Hot answers tagged

56

I believe that the user should clearly define their objectives before deciding which set of tools to use. ModelBuilder and Python scripting excel at different tasks. A few thoughts: ModelBuilder has no mapping capabilities, whereas arcpy.mapping does. Python can be used to optimize workflows, such as with the multiprocessing package or with parallel ...


53

Download and install comtypes, put the Snippets module from Mark Cederholm's presentation (link below) in PYTHONPATH, and you're all set. from Snippets import GetLibPath, InitStandalone from comtypes.client import GetModule, CreateObject m = GetModule(GetLibPath() + "esriGeometry.olb") InitStandalone() p = CreateObject(m.Point, interface=m.IPoint) ...


36

I compiled this list a while ago so it may be somewhat out of date. Making it community wiki so anyone can update/correct/add to it. Also see these general tips for new Python programmers in this answer. Presentations: Python Scripting for ArcGIS Getting Started with Python in ArcGIS 10 ArcGIS Geoprocessing: Python Scripting – Advanced Techniques Python ...


24

Usually Python debuggers/IDEs assume the Python script is running in the same process as itself so debugging a script running in ArcMap.exe is right out -- you need to get enough of the GP scripting environment bootstrapped in a Python script as you can to debug with. A method that's worked very well for me over the past few years is to write a simple ...


23

It seems the most common problem with these types of "flow maps" is that when many lines are included, they collide to such a great extent that it makes it difficult to discern any non-obvious pattern (when reciprocal flows are considered it happens to an even greater extent). Also the long lines tend to dominate the graphic, although it is quite possible ...


22

If an Esri well-known ID is below 32767, it corresponds to the EPSG ID. WKIDs that are 32767 or above are Esri-defined. Either the object isn't in the EPSG Geodetic Parameter Dataset yet, or it probably won't be added. If an object is later added to the EPSG Dataset, Esri will update the WKID to match the EPSG one, but the previous value will still work. ...


22

Keep in mind that Arcpy is essentially a wrapper around ArcObjects. But if you're just trying to call some Python scripts that you don't want to have to rewrite you can spawn a process that calls the python executable with your args. var startInfo = new ProcessStartInfo() { CreateNoWindow = false, UseShellExecute = false, FileName = ...


22

I am using an example with 1 million randomly generated points inside of a filegeodatabase. Attached here. Here is some code to get us started: import time import arcpy arcpy.env.workspace = "C:\CountTest.gdb" time.sleep(5) # Let the cpu/ram calm before proceeding! """Method 1""" StartTime = time.clock() with arcpy.da.SearchCursor("RandomPoints", ...


22

You will find a number of other similar questions on this site that ask the same basic question and have very good references. The most similar (and detailed) is: What are the Python tools/modules/add-ins crucial in GIS? Others include: Python Script examples for geoprocessing shapefiles without using arcpy Pure Python Library for Geometry Operations ...


22

GDAL is the tool to use. In fact that entire call is one line for gdal_rasterize: gdal_rasterize -l mask -i -burn -9999 mask.shp elevation.tif if you knew the no data value of the dem For some python control: lyr = 'mask' shp = 'mask.shp' dem = 'elevation.tif' ndv = -9999 p = os.Popen('gdal_rasterize -l %s -i -burn %d %s %s' % (lyr,ndv,shp,dem) where ...


22

Welcome to GIS.SE! I would probably just put it in GitHub until you really know what you want to share. Even ESRI started jumping on this bandwagon after GeoIQ acquisition.


21

General python optimization techniques can save you substantial amounts of time. One really good technique for getting a lowdown of where the hold ups are in your script is using the built-in cProfile module: from cProfile import run run("code") # replace code with your code or function Testing using a small data sample will allow you to pinpoint which ...


20

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 Python New Answer using arcpy.da cursor: import arcpy,csv table =r'c:\path\to\table' outfile = r'c:\path\to\output\ascii\text\file' #--first lets make a ...


19

Yes, Mark Cederholm's presentation that Matt Wilkie mentions above is a great place to start. The recipe/code that Matt presents is certainly a slick and probably the best way to go about things. I wanted to mention, though, the rather brute force method I am using in ArcGIS 10.0. I have several automation scripts (standalone, outside the application ...


19

You can change it from the GP options dialog, just point to your executable of choice for editor/debugger.


18

It doesn't work because you haven't called the Xlrd modules to read the Excel spreadsheet. Implement it something like this: import xlrd workbook = xlrd.open_workbook('my_workbook.xls') worksheet = workbook.sheet_by_name('Sheet1') This will allow you to read an XLS file with Python. However, ArcPy will read XLS without Xlrd. You can consider the Excel ...


17

I am not aware of an ArcObjects way to get it, but you can enable the Size column in the Customize menu -> ArcCatalog Options -> Contents tab: This works on file geodatabases but not on SDE geodatabases (in that case you could use some DBMS-specific queries to determine it though). It does not work on personal geodatabases.


17

If you are working solely within the confines of ArcGIS, there are a few considerations I would consider when attempting to determine the approach to take. What are you trying to accomplish, What are your current skill sets, Will you be sharing your work with others to use, learn from, or manipulate, and Who is your intended audience. Given those ...


16

The Polyline class has a new method called "positionAlongLine" in ArcGIS 10.1. This will return a PointGeometry object with exactly one point at a specified distance from the starting end of the line, or a fraction of the distance between the start and end. To find the midpoint, you would just need to do positionAlongLine(0.5,True). To find the midpoints for ...


16

I've been using "in_memory" quite a bit recently. It can be very useful, as it has the potential to dramatically increase processing speeds for certain tasks, however if you are working with very large datasets, it might cause your program to crash. You can use "in_memory" to define process outputs... often, if I am performing a task on a feature class, ...


16

Any time you have a selection on a layer a cursor object will only return the selected rows. for row in arcpy.SearchCursor("name_of_layer_with_selection"): print row.field1, row.field2


16

I would start with these places: Codecademy offers free online coding lessons, including Python. Use this to get the feel of how python works before working on ArcPy. You'll be glad of having the basics down when you work with ArcPy. Check out the free Virtual Campus presentation on ArcPy. It's a bit dry, but it will help orient you to how ArcGIS ...


15

This routine for arcgis10 returns all fcs (standalone OR within a feature dataset) inside a gdb. Just set your arcpy.env.workspace then do a for loop def listFcsInGDB(): ''' set your arcpy.env.workspace to a gdb before calling ''' for fds in arcpy.ListDatasets('','feature') + ['']: for fc in arcpy.ListFeatureClasses('','',fds): ...


15

A good starting point would be the Geospatial Data Abstraction Library. It is actually made up oftwo libraries -- GDAL for manipulating geospatial raster data and OGR for manipulating geospatial vector data but people usually just call it GDAL. There's a geoprocessing with Python using open source GIS course at the Utah State University. You might want to ...


15

In a lot of my academic research I work with LiDAR data doing surface analysis for geomorphology. I quickly found that performing a lot of operations using arcpy was very slow, especially on large datasets. As a result I began using: pyshp to manipulate shapefiles and update attribute tables numpy to manage ASCII rasters and perform kernel-based analysis ...


15

You need to loop through your inputs. Multivalue is semicolon delimited. Split on that and loop through them. (AddMessages to show how the fcs are presented) import arcpy ins = arcpy.GetParameterAsText(0) arcpy.AddMessage(ins) for fc in ins.split(';'): arcpy.AddMessage(fc) arcpy.Clip_analysis(fc, clipfeats, out) Though I'm not entirely sure of ...


15

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 what's costing you all that processing time. ... rows = arcpy.UpdateCursor('malls.shp',"","",'ParcelID') polyrows = arcpy.SearchCursor('parcels.shp') for row in ...


15

Model Builder is a great and easy to learn visual programming language and a good entrance to GIS-programming in general. But in some things python can do more. One example is the integration of non-ESRI GIS libraries. Nearly all of the Open Source GIS can be adressed via python as well (e.g. GRASS, Sextante, QGIS, SAGA). This helped me a lot, because I ...


14

Nope, one version of Python per release of ArcGIS. The reason for this is simple: most of the magic happens in a C extension (arcgisscripting). The C APIs change from version to version, and that DLL isn't going to play nice in other versions of Python. However, every time the main Python.org site releases a security fix (2.6.X), those are binary compatible ...


13

I've got a piece of code that works. I found it here on the ESRI website. Add it as a script to a model, then connect the output of a select by attribute tool to it. It does exactly what I want. import arcpy mxd = arcpy.mapping.MapDocument('CURRENT') df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0] df.zoomToSelectedFeatures() ...



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