Sunday, October 19, 2008

GPS Tools for Diving

Free GPS software to manage your hand held:
easygps.com


divespots.com
A very neat web site that is a community run database of diving locations: dive site info/history, photos, reviews, maps, and the best part? Downloadable GPS data to help you find it! Pretty rad.

You might need a serial-to-USB cable to connect your GPS to your compy:

Thursday, October 16, 2008

Neat Projection Toy

This is a neat tool that lets you play around with many different projections. Pan and rotate the globe and the map projection to see which methods are better for rendering areas of a 3D surface in 2D: uff.br/mapprojections


Monday, October 6, 2008

Intro to servicing a scuba regulator

With the purchase of a BC and regulator setup, I now my own full set of scuba gear. I found some interesting articles that explains what goes into the annual maintenance of a regulator, and a neat glossary of oceanographic and diving equipment terms at dtmag.com

Thursday, September 18, 2008

Search a Collection or an Array for a value

I want to check my attribute table for a few specific fields of data (Comments, Reachcode, Waterbody_Type, etc.). If these fields are not included, I want them to be added before my custom tool set can do work on them; fields cannot be edited if they do not exist in the dataset.

This is broken down into several steps:
  • Find all of the fields in a dataset
  • Add specific fields that do not already exist
I use ListOfFields to populate a collection or an array (I used a collection since the dataset will be small, and collections are super simple) with all of the included field names, search the collection or array for values that are not present, and add a new field where the required field is missing.


Private Sub SearchCollection()

Dim fieldName As New Collection

'Fill in a few values for the collection
fieldName.Add ("FID") 'collection position 1
fieldName.Add ("Shape") 'collection position 2
fieldName.Add ("Id") 'collection position 3
fieldName.Add ("Comments")'collection position 4

Dim valueComment As Integer
Dim i As Integer

'Loops through the collection looking for "Comment"
For i = 1 To fieldName.count
If fieldName.Item(i) = "Comments" Then
valueComment = 1
Else
End If
Next i

'Check valueComment for a change
If valueComment = 1 Then
MsgBox "Totally just found That value!"
Else
MsgBox "It's not here..."
End If

End Sub


The collection will be populated automatically using ListOfFields - this is just an example.

The crux of the searching will use a For Loop to step through each item of the collection, and change valueComment to equal 1 if it finds a matching field. If the field is not included in the attribute table/collection, nothing happens (valueComment will remain equal to its default 0). Following this is an If/Then statement that checks what to do next. This will be blank when the other code is applied, since the field is indeed included. The Else message box will be replaced with the code to add the comments field.

The object valueComment type can easily be Boolean, but the double and triple negatives when discussing this out loud get a bit confusing.

Monday, September 15, 2008

One click cartographic customization

I've only been in the industry for a few years and already I have my own go-to cartographic design. It evolves slowly, though by now I've figured out which symbols and representations work well together for my stylee. Eventually it becomes annoying and redundant to have to import a shapefile / layer file and change the specific options to the saved templates and styles - yes, you too should even be above Style Manager. With a few snippets of code, one can quickly call those familiar elements that take every bloody instance of 20 seconds to set.

The only prerequisites are having a symbology for a shapefile saved as a layer file (color those county boundaries, right click on the layer in the table of contents, and click 'Save As Layer File...') and knowing where your data is saved. Bam!

First, I want to import my county layer (again, with my favorite symbology already set). Next I will want to change the background color to a light blue to represent the water. This will also fill in the holes where water is present in bays, large lakes, and streams, etc., and might not be correctly included in a layer of hydrography.

Start by creating a new button on a toolbar that will be used to trigger the events:
  • Tools :: Customize
  • Navigate to the the Commands tab in the Customize dialouge box
  • Make sure that you are working in Normal.mxt (at the bottom in "Save in:") so this button is available for all subsiquent projects
  • Scroll to the bottom of the Categories list and select "[ UIControls ]"
  • Click the New UIControl... button and choose UIButtonControl, then click Create
  • Rename the new control something like "Format" or "Format_Basic" (single click to select the control, then click one more time to edit its name)
  • Drag this onto a toolbar - from here (with the Customize dialouge still open) right click on the button and change its name, button image, and then View Source to enter code
This is the code to import a layer file:
Private Sub Format_Basic_Click()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pGxLayer As IGxLayer
Dim pGxFile As IGxFile

'Get the layer file
Set pGxLayer = New GxLayer
Set pGxFile = pGxLayer
pGxFile.Path = "C:\GIS\FL_Counties.lyr"

'Add the layer file to the active map
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap
pMap.AddLayer pGxLayer.Layer
pMxDoc.ActiveView.Refresh 'Refreshes the map view
End Sub

This is the code to change the background color to light blue:
Private Sub Format_Basic_Click()
Dim pMxDocB As IMxDocument
Dim pActiveView As IActiveView
Dim pFillSymbol As IFillSymbol
Dim pGraphicsContainer As IGraphicsContainer
Dim pFrameElement As IFrameElement

Dim pRgbColor As IRgbColor
Dim pSymbolBackground As ISymbolBackground

'Get a reference to the layout's graphics container
Set pMxDocB = Application.Document
Set pGraphicsContainer = pMxDocB.PageLayout

'Find the map frame associated with the focus map
Set pFrameElement = pGraphicsContainer.FindFrame(pMxDoc.FocusMap)
If pFrameElement Is Nothing Then Exit Sub

'Associate a SymbolBackground with the frame
Set pSymbolBackground = pFrameElement.Background
If pSymbolBackground Is Nothing Then
Set pSymbolBackground = New SymbolBackground
End If
Set pFillSymbol = New SimpleFillSymbol

'Create a color object
Dim pBackColor As IRgbColor
Set pBackColor = New RgbColor
pBackColor.RGB = RGB(237, 249, 255)

'Apply color
pFillSymbol.Color = pBackColor
pSymbolBackground.FillSymbol = pFillSymbol
pFrameElement.Background = pSymbolBackground

'Refresh map
pMxDocB.ActiveView.Refresh
End Sub

To combine these two functions in the same button click event, you will have to change the object name of pMxDoc in the second part of the code (I'll use the background color as the second part of the code) to something else, like pMxDocB (it's mentioned 3 more times after the Dim statement). This is because the two functions use different parts of IMxDocument and the code will blow up when you reset the object. Also, go ahead and comment out or remove the first refresh statement (pMxDoc.ActiveView.Refresh). Here's the combined code:
Private Sub Format_Basic_Click()
'Part 1:
'Import Florida Counties layer file

Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pGxLayer As IGxLayer
Dim pGxFile As IGxFile

'Get the layer file
Set pGxLayer = New GxLayer
Set pGxFile = pGxLayer
pGxFile.Path = "C:\GIS\FL_Counties.lyr"

'Add the layer file to the active map
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap
pMap.AddLayer pGxLayer.Layer
'pMxDoc.ActiveView.Refresh

'Part 2:
'Change background color to blue

Dim pMxDocB As IMxDocument
Dim pActiveView As IActiveView
Dim pFillSymbol As IFillSymbol
Dim pGraphicsContainer As IGraphicsContainer
Dim pFrameElement As IFrameElement

Dim pRgbColor As IRgbColor
Dim pSymbolBackground As ISymbolBackground

'Get a reference to the layout's graphics container
Set pMxDocB = Application.Document
Set pGraphicsContainer = pMxDocB.PageLayout

'Find the map frame associated with the focus map
Set pFrameElement = pGraphicsContainer.FindFrame(pMxDoc.FocusMap)
If pFrameElement Is Nothing Then Exit Sub

'Associate a SymbolBackground with the frame
Set pSymbolBackground = pFrameElement.Background
If pSymbolBackground Is Nothing Then
Set pSymbolBackground = New SymbolBackground
End If
Set pFillSymbol = New SimpleFillSymbol

'Create a color object
Dim pBackColor As IRgbColor
Set pBackColor = New RgbColor
pBackColor.RGB = RGB(237, 249, 255)

'Apply color
pFillSymbol.Color = pBackColor
pSymbolBackground.FillSymbol = pFillSymbol
pFrameElement.Background = pSymbolBackground

'Refresh map
pMxDocB.ActiveView.Refresh
End Sub
One might ask, "Well why don't you just make a template, or set Normal.mxt to this look as a default?" My answers are, "Why not / why should I have to?" What about the other 50%
of the time when I do not want this layout? This way I can add certain elements, and even add additional buttons to add other layers or elements such as transportation or hydrography on the fly.

Reference key phrases:
How to change the data frame background color
Add layers using ArcObjects

Tuesday, August 19, 2008

NYC Public Transportation + GIS = One Happy Kid

I'm planning to fly into La Guardia and end up at West 47th and 8th Ave in Manhattan. Lauren and I have all the time in the world and are in no hurry so lets see what Google and the MTA have to offer:

MTA Bus Maps - I need to get to the west end of the airport to jump on the #47 bus which should take me to the Jackson Heights - Roosevelt Ave - 74th St - Broadway Statoin. I'm almost clueless, but it's a deffinate maybe. Getting on the E train to the 50th St - 8th Ave station. Now I just need to wake up on time, catch my connecting flight in Atlanta. Yikes!

onnyturf.com/subway - a mashup of Google Maps with overlays and information of all of the train and ferry lines in the city.

Google maps has all the bus and metro stations available if you zoom in enough. Very cool (yeah, I'm still a tourist - whateves).


View Larger Map


Status: Traveling

Friday, August 15, 2008

Chart Wizard is important

Visualization of raw data is an important skill. Check out these gangsta examples:
jamphat.com/rap