This section provides a venue for sharing GIS-related programming code and custom scripts in a variety of languages. Posts can be viewed by category or as a whole in blog format (below).
Occasionally, after editing a feature class the spatial extent (a.k.a. bounding rectangle) associated with the feature class is not updated. This means that if you had a feature class of Utah National Parks and when you loaded the data initially, you accidently included Yosemite NP in California as a feature, a Zoom to Layer command would zoom to a much bigger geographic area, even after you deleted the Yosemite Park feature. Here's how to use it:
Paste this script (below) into ArcCatalog's VBA editor (Tools --> Macros --> VBA Editor)
Back in ArCatalog, select the feature class in the Contents tab view (not in the left hand tree view)
Back in VBA Editor, click your mouse anywhere in this new script and hit the run button (blue triangle)
Do you ever need to display the temporal aspect of features? We have traffic studies all over the city, and it's nice to color code them based on their age. There isn't an "age" renderer that you can use, but you can calculate a new field as a number representing the number of days since some abrbitrary point in the distant past and then use one of the Quantity renderers like Graduated Colors to symbolize old features and new on color ramp!
I have an ASP application I'm working with in Visual Studio 2008 where one of the requirements is to assign contacts to a facility. There is a dialog where you can define contacts so you have ListBox1 with your previously defined contacts and ListBox2 with the contacts you want to assign. So there is a << and >> button to add and remove contacts.
In updating this application to 9.3 we changed the architecture to be less GISsentric and more business oriented. This meant for this portion of the application could now use updatepanels and server side logic rather than a boat load of javascript.
I figured this would be easy, put the listbox's inside an updatepanel along with the buttons, write some code to remove one and add it to the other. I wrote the code first to work outside the updatepanel and then I would add it in when I was satisfied it was working.
The first problem was me being forgetful. When I was selecting my listitem to move and clicking the button the selectedIndex was always -1. Well the ASP page lifecycle goes through page_load and was rebinding my control through the LINQ to SQL code I wrote. Therefore there is no selected item since the items are all new. Quick fix, put the LINQ code inside a if (!Page.IsPostBack){} statement so it doesn't get run.
Second problem arouse when I got an error saying, "Cannot have multiple items selected when the SelectionMode is Single." This was happening since the item being added to the Listbox was selected to be moved over. The error only comes up the second time you add a new ListItem since both items are selected. Easy fix again, set the listitem.selected property to false before adding it.
The weirdness happened when I tried putting the ASP xml markup inside the updatepanel's content template. In firefox I was getting duplicate rendering. So I'd end up with 4 buttons and 4 ListBox's. Not ideal. I decided to put each listbox in it's own update panel and now everything works like a charm.
This script creates a comma-seperated value (.csv) file that lists a record for each numeric style street names that is used as aliases by traditionally named streets within the same city.
Simple example:
If the streets database looks like this:
City
Street
Alias
Salt Lake
Broadway
300 S
Salt Lake
300 S
Salt Lake
MLK Drive
600 S
Salt Lake
Stockton Dr
300 W
Salt Lake
Stockton Dr
300 W
Moab
Slick Rock Wy
300 W
Salt Lake
300 W
Salt Lake
600 S
Salt Lake
Highway 999
600 S
Salt Lake
600 N
Moab
300 W
The output looks like this:
Moab, 300 W, Slick Rock Wy Salt Lake, 300 S, Broadway Salt Lake, 300 W, Stockton Dr Salt Lake, 600 S, Highway 999 Salt Lake, 600 S, MLK Dr
Word of warning. The processing time for this script is exponential, so it will take a large amount of time to operate on a large record set (3700 records took 8 minutes, 80000 records currently takes about 480 minutes).
To use:
Paste the code into the ArcMap VBA Editor.
Set the parameters at the top of the script (look for the ***'s).