Tag Info

Hot answers tagged

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 ...


16

Get the shape object in your cursor and access its extent property. See ArcGIS Help Working with geometry in Python: shapeName = arcpy.Describe(inFeatures).shapeFieldName for row in rows: feat = row.getValue(shapeName) extent = feat.extent print extent.XMin,extent.YMin,extent.XMax,extent.YMax


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 ...


13

The Delete tool should accept the name of a feature layer to remove it from the TOC.


13

First of all, I see you made your way here from reddit... I thought I recognized this script. Welcome! How you get your inputs depends 100% on who the end user will be, but you're right, you won't be able to use raw_input in ArcMap at all. If you are going to be the only one using the script, there's nothing wrong with getting your inputs through ...


12

From ArcPy examples, it seems like sys.exit() is the correct way to terminate a script early. The Python documentation notes that sys.exit(): is implemented by raising the SystemExit exception, so cleanup actions specified by finally clauses of try statements are honored, and it is possible to intercept the exit attempt at an outer level. The easy ...


12

Check out the replace function in the calculate field examples. Something like this should do it: NewString = Replace([comments], "&", "and")


12

For people using ESRI I think GRASS would be a very similar environment with a GUI python environment and organized in separate 'toolkits' for different tasks (raster, vector, solar toolkits etc.). The scripting has other options besides Python but that is how I use it. Definitely check out this great link which is up-to-date (I believe): ...


12

This is a Programmers Competency Matrix. As far as I know there are no such standardized rating systems for GIS scripting, but I might suggest modifying this one - the Programming heading/matrix would be the most relevant and needs little modification to make it relevant to GIS as most of the same principles apply. The nice thing about a matrix like this is ...


12

The principle is simple if you have R installed and is usable in command line. You can create and/or execute a R Script from QGIS using Processing in QGIS version 2.0 or Sextante in version 1.8): see: Setting “R Folder” Path in QGIS Sextante Port your R scripts to QGIS using SEXTANTE QGIS with R: Working with the SEXTANTE plugin and others


11

I am afraid I disagree with you. I think the ArcGIS help/forums/blogs/vids/etc give a great perspective on what you can achieve with the ArcGIS range of products. Your not limited to Python to manipulate your spatial data. You can still use VBA at 931 and 10 to access the ArcObjects library, or you could take it a step further and use .NET to do all sorts ...


11

You are on the right track with your script. It looks like your problem lies in how you are comparing the Layer object, to the Name of the Layer in the Table of Contents. When you use the ListLayers function, what is returned is a Layer object. You cannot then compare this to a text string to see if they are equal, you need to access the Name of the Layer ...


10

If you are convenient with Python then writing script for this task is preferred. Take a look at these key things: Get a list of featureclasses/shapefiles in gdb/folder - ListFeatureClasses. In the bottom of this help article there is also an example "Copy shapefiles to a geodatabase" which you can use to start writing script. Check for existence of ...


10

I think the answers given so far cover basically all package out there worth mentioning (espically GDAL, OGR, pyshp, NumPy) But there is also the GIS and Python Software Laboratory, that hosts a couple of interesting modules. They are: Fiona: OGR's neater API Rtree: spatial index for Python GIS Shapely: Python package for manipulation and analysis of ...


10

Since you are using v10.2 it is looking for the path of the Spatial Analyst toolbox which has changed directory locations slightly from v9: To update, open the ruggedness.py file using Notepad or some other text editor and change line 20 path to something like this: C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Toolboxes\Spatial Analyst Tools.tbx


9

You can use a Python script to do the heavy work for ya: Check this out and adapt it to your needs. Needless to say, this is not tested, and don't use it on production data WITHOUT MAKING A BACKUP FIRST. import arcgisscripting gp = arcgisscripting.create(9.3) gp.Workspace = "path_to_your_geodatabase" # you can use absolute path to this function ...


9

Here is a list of references I have started to put together for myself: ArcGIS 10 and Python


9

In a global dataset you will have cases where a point is close to the equator, or Greenwich meridian. At these points a sign change could leave your location in the same country, but at the wrong location. An alternative approach is to geocode the locations based on the city, county, and country fields. Create a field measuring the distance from the ...


9

In addition to @egdetti's great suggestions, you can greatly simplify your script by making some assumptions instead of writing if/else logic for every little condition. For example: Instead of checking whether each item exists beforehand, just assume it does and overwrite it by setting arcpy.env.overwriteOutput = True. Now you may have some reason why ...


9

If the intent of your application is to provide the user a simplified view when identifying features then I would suggest just turn off all the other fields within the layer properties that you do not want to show. When the user identifies a feature, they will only see info for the two that are turned on. This can be done by: Right click layer in the ...


8

I never understand why people even try to mess with CalculateField_management within a Python script instead of just doing their updates within an UpdateCursor. Not only do you not have to worry about escaping characters and writing Python functions within Python strings (shudder), you can update multiple fields at once. It's very easy with the newer arcpy ...


8

I know your question is Python-centric, but R has a wealth of value statistical analysis methods, some of which can be used for spatial analysis. @Whuber has a good answer here illustrating how to clip a raster to a box in two lines.


8

I have simplified your code and corrected the error by using the da module introduced in 10.1. It greatly streamlines the reading of data using cursors, and used in conjunction with the with command this code should be more stable than if it used the the older method of file access. It works by making a list of all the fields and then removing the fields ...


8

Try this using a combination of Add Field, Calculate Field, and Delete Field arcpy tools: if fieldInfo.getFieldName(index)=="status": # Process: Add Field arcpy.AddField_management(layer, "stat", "TEXT", "", "", "50", "", "NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field ...


8

Remember that all of ArcGIS' Python stuff dealing with strings starting in 9.3 uses Unicode objects, which will make your life quite a bit easier because encoding becomes less of a big deal in the data. You'll still need to think about it in your scripts, but if you use UTF-8 in any Python source you write outside of dialogs in Arc*.exe ArcGIS will handle it ...


8

You can call the GP tools in two ways: arcpy.%toolbox%.%toolname% or arcpy.%toolname%_%toolbox% Both are calling the same function, so there is no difference. It is a matter of taste; I always call functions in the arcpy.Buffer_analysis format because I seem to read the name tool faster in this way (I see first the toolname, and often seeing the ...



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