Hot answers tagged

16

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


16

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


13

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

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

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


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

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


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


9

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


9

This will do it import arcpy arcpy.env.workspace = r'c:\temp\x' fcs = arcpy.ListFeatureClasses() for fc in fcs: arcpy.AddField_management(fc, 'shpname','text') arcpy.CalculateField_management(fc, 'shpname', '"'+fc+'"') arcpy.Merge_management(fcs, 'out.shp')


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

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


9

The below code worked for me QGis 1.8.0 You might modify this to accomodate multiple files with some loop.. from qgis.analysis import QgsZonalStatistics #specify polygon shapefile vector polygonLayer = QgsVectorLayer('F:/temp/zonalstat/zonePoly.shp', 'zonepolygons', "ogr") # specify raster filename rasterFilePath = 'F:/temp/zonalstat/raster1.tif' # ...


9

Finally found the proper way of running processing algorithms in PyQGIS standalone scripts. This answer is based on answers to Problem with import qgis.core when writing a stand-alone Python script that uses QGIS and to Error: Algorithm not found, which is in turn based on a Qgis-dev mailing-list discussion. I suggest you to follow the work flow given in ...


8

I haven't written stand-alone scripts based on QGIS API yet, but the PyQGIS cookbook uses the following initialization: First of all you have to import qgis module, set QGIS path where to search for resources — database of projections, providers etc. When you set prefix path with second argument set as True, QGIS will initialize all paths with standard ...


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


7

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


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

I think you want the arcpy.Exists function: >>> import arcpy >>> arcpy.env.workspace = r"D:\temp" >>> if arcpy.Exists("Cameron.shp"): ... print "Exists" ... Exists >>>


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

how about... provider = vector.dataProvider() feat = QgsFeature() allAttrs = provider.attributeIndexes() provider.select(allAttrs) while provider.nextFeature(feat): geom = feat.geometry() rect = geom.boundingBox() #get bounding box as QgsRectangle


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.


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


6

Not documentation, but a colleague just passed this along.


6

You already have your answer; you have your start X/Y and finish X/Y, so you have a range and the distance between the points Calculate the amount of points you will create per axis xRange = maxX - minX yRange= maxY - minY xloop = int(xRange /0.125)+1 yloop = int(yRange /0.125)+1 Create your point variables pointGeometryList = [] point = arcpy.Point(...


6

os.sep is the (or a most common) pathname separator ('/' or ':' or '\')



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