Tag Info

Hot answers tagged

21

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


21

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


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


14

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


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

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


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

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


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

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

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


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

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


7

Just use os.path.join(), noting the caveat for Windows at http://docs.python.org/dev/library/os.path.html. It takes care of the os.sep for you and makes your code more portable (not that ArcPy is portable, but in general). for fc in fcList: arcpy.Copy_management( fc, os.path.join("d:/base/output.gdb", fc.rstrip(".shp")))


7

Instead of using while statements, I'd go with your idea of using a prevX var. The key is that you declare the variable after you know the value of X is for each turn through the loop. By declaring prevX in each of your control structures (if or elif statement), you know what the value of X was in that loop. This is just a nested conditional (you could ...


7

You can select some rows and right-click the field you want to populate and click Calculate Field. For a small to medium number of features/rows, I would suggest doing this within an edit session so that you can undo/redo. Then enter an expression (in either VBScript or Python syntax) and click OK. More here: Making simple field calculations.


7

Since step three is a manual editing of features based on looking at the NDVI image I would recommend creating two separate scripts. For doing what you've done already and also adds the NDVI image into ArcMap (part of step 1) and creates the feature class (step 2) That runs after you are done with your third step.


7

I think the short answer is NO. In arcpy you would typically "Describe" an object to get a handle on its properties. It appears there is no way within arcpy to find out the version the toolbox was saved in. If anyone knows of a way then please shoot me down in flames so I can learn from your wisdom! But you could fudge it this way: In ArcCatalog right ...


6

As I understand your question there is no need for cursors. This is a very common and simple task to do with simple sql. If we call your two tables roadsegments and adresspoints with fields like this: roadsegments gid the_geom min_address max_address adresspoints streetname housenumber Then you can first create the column for the roadid in the ...


6

Units are always tied to your coordinate system. Assuming we're talking about a projected coordinate system, the units are in the units used by the spatial reference of your dataset. If you're dataset is in meters, your area will be in square meters. You should be able to get this info from your dataset's spatial reference. You can get your dataset's spatial ...



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