Sunday, October 11, 2009

App Idea: Facebook History

I've tried on a few different occasions to see how I have previously wasted my time in the past. I scroll to the bottom of my Facebook wall, click "Older Posts" and repeat. This happens up to a half dozen times before I loose interest (I've read studies that internet users' attention span is as short as seven seconds [I would have posted links, but I don't feel like reading these articles]). This technique usually yields no more than a day or two of my Facebook history. Who cares?

I'd like a more efficient way to (possibly) quantify and (more importantly [not importantly]) reflect on just how much of my youth I have wasted. Assume each wall post can equal 10-20 seconds, each posted picture/link amounts to a bit more time, etc. Also, it'll just serve as a simple tool to navigate through a given time frame to see what you/your friends were up to at least 100 years ago.

Thursday, October 1, 2009

Calculate Lat/Long Values in ArcMap

Yet again, I had a difficult time finding sufficient information on calculating latitude and longitude values for a point shapefile. I've only encountered one or two situations in the past few years where I worked with a coverage that was missing these data, though it's still a basic and important technique that should be addressed a bit better.

It turns out that (at least) ArcMap 9.2 provides a pretty simple method to quickly calculate a number of geographic coordinates. A few things are important to consider though:

Converting Polygon to Point data:
Unless you're interested in the locations of polygon boundaries (shorelines, property boundaries, etc. - in which case you will convert the polygon boundaries to nodes), you will want to create a point coverage to represent centroids. Be sure to choose whether that center location will be the true center, or be preserved within the bounds of the polygon:

  • Show ArcToolbox in ArcMap (or ArcCatalog)
  • Open the Feature to Point tool
    (Under Data Management Tools :: Features :: Feature to Point)
  • Press Show Help to read more about the tool
  • Select a polygon or line feature to use as in input featre
  • Set an output location and name for the resulting feature class
  • Check the "Inside" check box to calculate a centroid within the boundary of a given feature (i.e. a "bent" polygon similar to the shape of Florida can have a centroid in the Gulf of Mexico if "Inside" is not selected)





There is insufficient information on the internets about this process works. There is a simple and automated calculator built into atribute table field calculations. To make this work properly in this situation (calculating geographic latitude/longitude coordinates) the coordinate system must be set to a geographic coordinate system, rather than a projected coordinate system.

Calculating Lat/Long Coordinates:

  • Add a point coverage to a project
  • Change the data frame to a geographic coordinate system
    • Right click on the data frame heading in the table of contents pane and choose Properties
    • Navigate to the Coordinate System tab
    • Expand the Predefined branch
    • Expand the Geographic Coordinate Systems branch
    • Expand the North America branch
    • Choose North American 1983 HARN and click OK
    • Choose Yes if prompted with a coordinate system warning
  • Open the layer's Attribute Table and add the following fields /types (LONG_DD is indeed string 3, not a typo)
Field Name
LATITUDE
LONGITUDE
LAT_DD
LAT_MM
LAT_SS
LONG_DD
LONG_MM
LONG_SS
DATUM
Type/Length
Text (string), 20
Text, 20
Text, 2
Text, 2
Text, 9
Text, 3
Text, 2
Text, 9
Text, 25
  • Go ahead and calculate "North American 1983 HARN" (or whatever coordinate system you used) in the DATUM field.  Whomever uses this data in the future will need to the method used to calculate the units
  • Now begin to calculate the units.  Right click the LATITUDE field and select Calculate Geometry
    • Set the Property to "Select Y Coordinate of Point" (Latitude = y, and Longitude = x)
! Note that Latitude = y and Longitude = x. Usually you'll ask for "x/y coordinates" in geometry class, however surveyors ask for "a northing and an easting" - which flips the order of the x and y values around.
    • Select "Use coordinate system of the data frame" to use the geographic coordinate system. After this, the Units will change from various length units of measure (meters, feet, etc.) to a number of DMS choices
    • Select "Packed DMS Format (+/- DDD.MMSSssssss")" and hit OK
  • Repeat this for LONGITUDE with "Select X Coordinate of Point"
  • Use the Field Calculator to populate the remaining fields using the following formulas
    • LAT_DD: left([LATITUDE], 2)
    • LAT_MM: mid([LATITUDE], 4, 2)
    • LAT_SS: right([LATITUDE], 8)/1000000
    • LONG_DD: left([LONGITUDE], 3)
    • LONG_MM: mid([LONGITUDE], 5, 2)
    • LONG_SS: right([LONGITUDE], 8)/1000000

  • Finally, be sure to Calculate Geometry again on the LATITUDE and LONGITUDE fields (Using the coordinate system of the data frame) but set the units to Decimal Degrees.  Until this is finished, the values look like decimal degrees, but if these coordinates are projected, they will be incorrect - perhaps by a long way.  A good trick is to see if any values after the decimal are greater than x.599999.  If there are any values between x.6 and x.9, those are indeed decimal degrees.
There are a few other formats that may be more appropriate for individual projects. Some custom utilities will require lat/long processing fields to match, so be careful with the LAT_DD/LONG_DD fields; thus DMS fields may need to be converted to another data type.  Further, field types of Double and Short Integer may be more appropriate for your database.

See also:

Angular Unit Conversion (convert between DD, DMS, and radians)
How To: Populate x, y, or z point data fields of an attribute table

How To: Calculate Latitude and Longitude values using the Field Calculator

Monday, September 28, 2009

Working With Text Files in Visual Basic

Visual Basic can be an effective medium used to track calculations in a session of work, however the variables, objects, strings of text, numbers, etc. are volatile; anything created or calculated will be lost when the program is closed. A few of the apps I developed make use of saving certain pieces of information to a small text file before the program is closed, and retrieving the information and putting those pieces back into the app when the program is loaded later.

These text file handling sessions are basically simple enough, but can get a little more complicated when specific logic is required - I'll get into that later.

First off, open Notepad or another light text editor and save a new file. I like to change the extension from .txt to something that is unique to my project - for instance .jus, or .anp, etc. The suffix can be anything; I like to change this from .txt so it is less likely that the file will be opened or its contents changed. Restructuring the contents may cause errors when it is loaded by the application. The .txt suffix can also be used as an alternative, however.

ArcNotepad.anp is the newly created text file

To save a text file with a unique suffix, change the "Save
as type" to "All files" and it may be necessary to put quotes around the file name from the Save As dialog box:


Save text to a file:

Private Sub Save_Click()

Open "C:\ArcNotepad.anp" For Output As #1
    Print #1, "1st line of the document"
    Print #1, "2nd line" 'Line 2, etc.
Close #1

End Sub



Retrieve text from a file:

Private Sub Load_Click()

Dim strLine1 As Integer
Dim strLine2 As Integer

Open "C:\ArcNotepad.anp" For Input As #2
    Line Input #2, strLine1
    Line Input #2, strLine2 'etc.
Close #2

End Sub


That's it for the basics, but let's insert some logic into this. The previous two examples will work if your formatting will be standard - that is, if the text file holds a set number of values/variables that will be updated over and over again, but the number of values will not change. An alternative situation is when lines are added or removed from the text document. The application will not know how many lines are included in the text file, and this is poses a problem. This dynamic text file requires some additional coding to be handled properly. The next time the document is accessed, there will be either:
  • lines that are overlooked (more lines in the text file exist than the previous code looks to retrieve), or
  • the program will return a "Run-time error '62': Input past end of file" error (there are too few lines available for the program to retrieve).
As an example, consider that the two lines "Another line" and "Even more" are added to the text file and saved, for a total of four lines of text. The application will need to read through the file and count how many lines there are. Next, a dynamic array will be created and populated based off of the primary count.

Private Sub Load_Click()

Dim i As Integer

Dim blank As String


'Count the number of lines in ArcNotepad.anp
Open
"C:\ArcNotepad.anp" For Input As #2
    Do While Not EOF(2)
        Line Input #2, blank
        i = i + 1
    Loop Close #2

'Break: Show number of lines in ArcNotepad.anp
MsgBox "Lines: " & i
Dim ii As Integer
'Create a dynamic array, of size i
Dim strLine() As String

ReDim
strLine(i)

'Populate the array with lines from ArcNotepad.anp
Open "C:\ArcNotepad.anp" For Input As #1
    Do While Not EOF(1)
    Line Input #1, strLine(ii)
    ii = ii + 1
    Loop Close #1

'Report the array via message box
Dim iii As Integer
Dim strMessage As String

For iii = 0 To i - 1
    strMessage = strMessage & _
    "Line " & iii + 1 & ": " & strLine(iii) & vbCrLf
Next iii

MsgBox strMessage

Thursday, September 17, 2009

VB / ArcObjects Cheat Sheet

I've been discussing code a bit, and for the non-coder it will make little sense. ArcGIS, along with many other Microsoft-based software packages can be easily customized, and a lot of really cool (nerd) tools and applications can be created with only a little bit of training.

There are many free resources on the internets that explain in great detail how to begin coding. I started learning Visual Basic last summer and have already released an ArcGIS toolset used by the Florida Department of Environmental Protection.

During that time, I saved a few bits of information that I found important to remember, so I threw together this cluttered
PDF file as an ArcObjects Cheat Sheet (VB Reference Sheet):

- Download the VB / ArcObjects Cheat Sheet -

Further Resources:

Thursday, September 3, 2009

Tetris is Aware


I am almost certain that Tetris software is not only cognizant, but I swear that it's also sentient. There are many times when sequences of pieces cannot possibly be part of any random combination
  • Every once in a while it'll throw me a bone and send a few good pieces my way when I get out of a particularly difficult situation
  • It teases me after level 12 by sending groups of I-pieces () - almost to say, "Ha! Bet you didn't expect these NOW!"
  • It knows it's time for bed and starts sending ridiculous sequences of only S and Z pieces ( ) when I've been waiting patiently for an I and there are no good locations for such pieces
I am also beginning to suffer from the Tetris Effect - where one begins to see shapes and attempt to solve lines, away from the game. The first time I had this happen was when I played a lot of competitive The Next Tetris with some friends back in high school.

Saturday, August 22, 2009

Masters Research using Google

Why do I not own stock in Google? The bubble has not burst yet so it seems pretty solid; with GOOG-411, the forthcoming Google Voice, and Google Wave, etc. Let's go holidays!
Update: RIP Goog-411, hello Android voice-to-text

Speaking of celebration, I just finished my masters research. I was assisting with (and thanks to the shortcomings of ArcMap, I am continuing to finish) research at Florida State University which is continuing to investigate spatial patterns of cloud-to-ground lightning flashes across various landscapes. My contribution primarily aimed to build a geoprocessing model to assist with the preliminary data preparation for future iterations of similar research. Some other bricka-brack followed.

I decided to write it using Google Docs because I knew I would be working at home, in my office at DEP, and on campus and versioning is a pain in the ass. This is the 90's... nobody needs to save separate/new copies to a flash drive or send via e-mail anymore. This allowed me to edit a standard copy from various locations on demand. Very clean. Of course I formatted and submitted the final versions with Word (2003), though this MS Dependency is becoming increasingly antiquated with the assistance of LaTeX (a very good formating and publishing medium).

Although I didn't really need to use this feature, it is easy to set permissions and invite other users to view or edit any text document, spreadsheet, form, or presentation thuswise:


I strongly recommend reading the Survey of Literature / Background and ignoring the rest of it. It "briefly" introduces what a thunderstorm is and how they are created.

There are around 40 references in total (each document basically composes the final report) - to which I would like to give many thanks to Google Scholar and Google Books.

Scholar is aided by a proxy connection to FSU's library which has subscriptions to many of the journals that are returned in a search. Books doesn't have every book, nor does it allow users to see every page of all available books, however I was able to serach thousands of books for a single word or phrase, and the results are not only higlighted, but each page is presented with separate previews and links to the specific page of the book.

I can't imagine a world (I'm looking at you, the 20th centrury) that did not have the luxary of these efficient tools. Walking to the library and reading through hundreds of pages of books and journals absolutely has its benefits (learning vast amounts of supplementary information and providing a more comprehensive overview of the topics of interest), but it's for suckas.

Tips for Digital Audio Recording & Increasing Computer Speed

My computer is a few years old now (got Lappy Tappy for Hanukkah, 2005), and it's filled to the brim with all sorts of (mostly) high end software for spatial modeling & image processing (ArcMap, Erdas Imagine, IDRISI Andes, R, NetLogo, and some GPS utilities) and music production (Cubase, Fruity Loops, Ableton Live, Reason, Audacity, Guitar Pro, NoteWorthy Composer, and some other mixer and MIDI interface tools).

Wow, didn't realize how bad it really was. It takes forever (a good five minutes) to load Mozilla - which encompasses 90% of my workload on here. It seems silly to bog it down with all that software. Rock Machine is significantly more powerful, however I rarely use it because it's in the recording cart (still upcoming post) and it's just easier to use Lappy Tappy for every day communication in front of the tele.

Anyway, I came across some tips for speeding up a computer. Enjoy.

Tips and tricks for music and computers
Optimizing Your Computer Recording System
http://alesis.com/tipsnov08


A few good starting points of my own:
  • Clear off the desktop. Put all of those random folders, mp3's, images, shortcuts, etc. in My Documents or somewhere else. Consolidate into a single "Desktop Junk" folder.
  • Empty your recycling bin
  • Clear out C:\temp
  • Clear internet browser history, temporary internet files, cookies, etc.
  • Remove programs from Start :: Programs :: Startup
  • Disable startup programs
    • Go to Start :: Run
    • Type msconfig and hit OK
    • In the Services tab, check 'Hide All Microsoft Services' and then uncheck anything that looks unnecessary (i.e. Google / iPod updates, etc)
    • In the Startup tab, uncheck anything that seems unnecessary. Expand the Command field to look for updates, media launchers, peripheral (printers, cameras, etc) management, etc. Use a search engine to investigate unknown items
    • Hit OK and restart the computer
  • Run a Virus Scan (AVG is free and light)
  • Run Ad-Aware free adware removal software
  • Run Malwarebytes free malware removal software
  • Move Pictures, videos, music, homework, old files, etc. to a portable hard drive (I suggest a hard drive that is powered by USB and does not need to plug into the wall, for instance the Western Digital Passport)
  • Uninstall uselesss/unused programs or games from Control Panel :: Add or Remove Programs. Often you can save data or save files and remove the game that isn't played
  • Clean your registry. There are a few good utilities out there to do this. If you don't know what it is then don't bother, so I won't post links.
  • Finally, defrag your hard drive overnight and restart in the morning
  • I've never used it, but it would be wise to set a system restore point (Start :: Programs :: Accessories :: System Tools :: Backup)