Saturday, January 28, 2012

Group Layer and the Flex Viewer

I had a large group in my Flex Viewer application. I wanted to be able to click the group on--but not have all the sub-layers render. Easy Fix! Re-publish your map with the group layer and the sub layers turned off.











Group Layers and The Flex Viewer

Sunday, January 8, 2012

Excel 'Databases', Lat/Long, and UTM's

Any GIS Specialist worth his/her weight in salt must accommodate non-technical users of GIS information. For this reason, I'm pushing for more and more use of Microsoft Excel--where the spreadsheet holds the attribute information and I later join the spreadsheet to a Shapefile.

As a quick tutorial, here is my Excel<->Shapefile methodology.

Right now, I have two spreadsheets.
One spreadsheet holds all the attribute information for my records.

SpreadSheet1


And, in the same spreadsheet workbook I keep all of my point data.


SpreadSheet2


*Side note* I was given Lat/Long Decimal Degrees I used Oasis Photo to convert them to UTM's; I was having a hard time converting them in the GIS--but once again, a good tool for non-technical users!




In my workbook, I've named my two spreadsheets. This will make it easier for me to identify them when exporting them to a Geodatabase.


Double Click On the SpreadSheet to Change its Name.


Open the Spreadsheet in ArcCatalog, and Export it

:::#:::#::: After A couple Hour Melt-Down, I'm Back! :::#:::#:::
What I think just happened was...
1) I saved the excel as a 2007 format
2) Tried to Export it to ArcGIS Geodatabase--it failed.
3) Then I tried to open it in Excel--that failed.
4) I panic-ed, because it wouldn't open in Excel--ArcCatalog still had a lock on it.
5) Cleaned up all the headers--so there's no special characters, spaces, or so its not too long. Characters like: (,),(`),(!),(.),([]), Leading space, Non-printable characters. (Use Find/Replace to work your data over)
6) Resaved as an Excel 2003-2007 workbook--that worked.
7) Made points out of the xy data--some of them looked wrong!
8) Sweat and Sweat because I couldn't figure out what the projection problem was--there wasn't one (or at least nothing I did).
9) Figured out that the xy coordinates in the attribute table were wrong--but the points were still good (Always, double check your Attribute Geometry!)


Also, Use the function len(#cellNumber#) to find out how long the cell is, keep it under 255 ;)



Anyways...
The main goal for this database schema is to separate the 'Spatial/Spatially Derived-Data' from the other 'Nominal/Ordinal Data'.
So, the only data that I have in my feature layer is the basics:


In the feature-layer-attributes, only keep the bare-minimum of attributes. Keep 'Id' and 'Name' and other spatial information like 'xy coordinates' or spatially joined/derived data like 'Township/Range' and 'ManagementUnit'.

Saturday, December 10, 2011

Thunderhead Explorer: Map Layer From Local Shapefile

Thunderhead Explorer: Map Layer From Local Shapefile: In this post, I will demo how to load a local shapefile from your hard drive, and overlay it on an map whose base layer is derived from a r...

Wednesday, November 16, 2011

Using ESRI arcpy GetParameter, instead of python sys.argv

There are two options for passing parameters to your python script in ArcMap.
1) Using the python sys library.
2) Using ESRI arcpy library.
grasslandSelect = sys.argv[1]
grasslandSelect = arcpy.GetParameter(0)

There are some obvious differences. Python uses the argv[0] to pass the argument of the actual python script, so the first argument entered in the command line is argv[1].
ESRI GetParameter(0) is the first parameter passed when calling the script from a Toolbox.

For the case of Boolean arguments, it is worth mentioning that sys.argv will return ,with a lower case, 'true' or 'false' while arcpy.GetParameter will return, with a capital, 'True' or 'False'. Though I had not problems complementing either(not True, not true), I did have some unidentified issues using the lower case 'true/false'

Display ArcMap Dialog Messages During Script

Easy to-do! You must, however, cast numbers with str().
arcpy.AddMessage("Total number of features: " + str(count))

Monday, November 14, 2011

Update: Arcmap Toolbox with Python Script

An initial step to publishing an ArcServer geoprocessing tool is adding the script to an ArcMap toolbox, setting the parameters for the script, and then publishing the tool.
The tool I'm developing allows for non-technical users to perform technical queries by the push of a button.
Currently, I have the tool added to a Toolbox in ArcMap. The tool takes 12 arguments from the user. 9 arguments are check-boxes, 2 arguments are values between 0 and 1, and the final argument is a feature-set(a polygon). The check-boxes allow the user to select attributes from the data-set, in a 'on/off' sort of way. To select a range of juniper density, the two arguments that take decimal numbers specify the low and high values of density. And the final argument,the feature set, allows the user to first draw a polygon around a specific area; from this specific area, all the other arguments are then used to refine the query.

For example, the screenshot below is building a query that will select: Low and High producing grassland and savanna, that are in private land, that have juniper tree density less than 25%--all within the specified polygon.

The resulting feature set selection for this query is below.


Another example, here is the result of the query (High and Low Producing Grassland, that is State Trust, with 0 to 25% juniper density--in the specified polygon).


The most unique and easily repeatable part of this tool is finding a 'range' of data. This tool could easily be applied to the whole state with respect to answering questions about slope, distance to water catchments, and possibly other density questions--like animal population density.

Wednesday, November 9, 2011

Rendering Feature Sets in ArcMap from Python

If your creating a python script that will run inside ArcMap, and the feature sets that are generated from the script must be then displayed, the basic script code is below.
Read further to see how to setup your script in an ArcToolbox.


import arcpy
from arcpy import env
import sys

#The set that I will query, it has two polygons. I will select one and then render it.
queryFset = r'C:\Development\2Test_QueryPolygon.shp'

arcpy.env.overwriteOutput = True # So the script can be repeated
arcpy.env.workspace = "in_memory" # Faster have your environment in_memory
result = "in_memory/featureSetOut" # Faster to have your result in_memory

try:
selectPoly = sys.argv[1] # Argument 1, not 0, 0 is the program itself
except:
print "\nNo arguments" # Incase your testing in the command line
selectPoly = 1

arcpy.MakeFeatureLayer_management(queryFset, "lyr") # Feature layer to do work on
queryStringAll = '\"Id\" =' + str(selectPoly) # Query String with dynamic variable
print queryStringAll
selectionOption = "NEW_SELECTION" # Select by attribute option
arcpy.SelectLayerByAttribute_management("lyr", selectionOption,queryStringAll) # The actual select by attribute method

arcpy.CopyFeatures_management("lyr", result) # Put the layer in memory (see above declaration)
featSet = arcpy.FeatureSet ("featureSet") # Geoprocessing record set object arcobject.Featureset
featSet.load(result) # Put whats it memory into the feature set

arcpy.SetParameter(1,featSet) # This is confusing, its works with '1'
# Even though 1 is the sys.argv[1]
print "exited"
print arcpy.GetMessages()