A C# Program to Fix Broken Layer Files

We are currently working through an ArcGIS v9.3 to ArcGIS v10.1 migration of our Regulatory GIS Support System (RegGSS) and have run into a problem when applying a layer file to a data set.

There are two approaches in applying a layer file to a data set either load the layer file directly or load the data set first and then apply the layer file to the data set. In the past, we had run into problems loading the layer files directly where some properties would not get set (especially label properties) so we decided to go with the second option where we would load a data set and apply a layer file. The main difference is that in the first case the layer file cannot have any broken links while the second method does not care about broken links.

At ArcGIS 10.1 however, this approach stopped working. RegGSS uses close to 800 layers files and checking/fixing each one by hand would have been a monumental task in both effort and time. Our solution was to created a C# script to check every layer file for broken links and repair those that were broken or flag them as not-repairable so they could be repaired manually. The general logic is as follows:

  • Cycle through all layer files used by RegGSS one at a time and check if the layer file is valid or not by using the Valid property on the ILayer interface of ArcObjects
  • If layer file is not valid, read the SDE server name, reset the connection parameters and re-save the layer file.
  • Re-check the validity of the re-saved layer file and if it still has a broken link, write out the layer file name to a text file so it can be fixed manually.

You can check out the main procedures here on GitHub.

Carlos Piccirillo, Senior Geographer, Regulation GIS, SFWMD
Juan Tobar, Supervising Geographer, Regulation GIS, SFWMD


Migrating GRIDS and Shapefiles to FGDB Using Python

Sunset 3
The Drawdown tool within RegGSS can be used to create a hydrologic drawdown models (grids) in a non-leaky aquifer for single or multiple well systems. The tool is also a library of over 2,500 grids that allows for storage and retrieval of the created drawdown grids and contours.


Drawdown creates a directory named the same as the permit application number, for example 080410-22. The individual grids are stored within this directory and are named “application number – version”, for example 080410-22-1. Each grid can also have contours and those are named “contour – version”, so the contours for 080410-22-1 is just contours-1.

We did extensive testing on our test environment and thought we had figured it all out. But how often does your test environment faithfully duplicate production? Especially, in a Windows XP to Windows 7, ArcGIS v9.3 to 10.1 migration?

Here are the problems as we migrate to ArcGIS v10.1:

  • ArcGIS v10.1 wants everything in a geodatabase (will use a file geodatabase)
  • Geodatabases do not like grids that begin with numbers (will prefix grids with a “g”)
  • Geodatabses do not like grids or contours that have dashes “-” in the name (will use underscore “_”)
  • Prior to ArcGIS v9.2 grids were stored with auxiliary files, for example 080410-22-1.aux which stored statistical information about the grid. At ArcGIS v9.2 in addition to aux files ESRI added aux.xml files, for example 080410-22-1.aux.xml. ArcGIS v10.1 does not recognize the older format with the aux file alone. (we will generate aux.xml files).

The image below is a look at the output of Drawdown for a single well system.
Drawdown Grid

You can take a look at the python code on GitHub.

Juan Tobar, Supervisor – Geographers, Regulation GIS, SFWMD

ArcSDE Replication

Sunset 4SFWMD Regulation GIS has a staging and production ArcSDE 9.3.1 sp2 servers used to store geospatial data. Most of the features on staging do not change very often so they are moved manually to production as the need arises. Those features which are edited daily on staging are replicated to production and synchronized hourly.

We are currently undergoing a simultaneous Windows XP to Windows 7 and ArcGIS v9.3 to ArcGIS 10.1 upgrade. Once our desktops were upgraded to 10.1 our 9.3 python script to automatically re-create the replica failed. We tried the 10.1 tool CreateReplica but were getting the following error:Problem

It turns out that CreateReplica will give an error if the feature class was created and registered as versioned in the earlier 9.3 version.

The problem was solved when the feature classes were deleted from both staging and production and then re-created in 10.1 from scratch from a file geodatabase archive. The new feature classes were then assigned privileges,  Global IDs were generated, and then Registered as Versioned.  Once this was done it was noticed that feature tables views (“VW” suffix) were being created. We originally did not understand this but quickly learned that this is a default behavior of ArcGIS 10.1 when registering feature classes as versioned.

We like to use Model Builder as a prototyping environment.
Model Builder

Once done prototyping we migrate our models to python scrips. You can take a view replication.py on GitHub.

Shakir Ahmed, Geographer 3, Regulation GIS, SFWMD
Juan Tobar, Supervisor – Geographers, Regulation GIS, SFWMD

Map Logic Layout Manager Tip

Sunset 2
When you set MapLogic’s Layout Manager to index a particular boundary, in this case hydrologic basins, the software does a god job zooming you in to different basins when you select different maps but you always see the boundaries of adjacent basins. The following procedure and code will allow you to create a definition query to display only the boundary being indexed on a particular map.

To set up the map series to select one feature, we need to add a macro to the Visual Basic Editor:

1. Right click on the Map Series name in the TOC.
2. Select Properties
3. Navigate to the Data Frame Properties → Map Series → Custom Code tab
4. Complete the section titled: BEFORE (runs macros before activating the next page in series) as shown
5. Double click on Module1 to view the current code Replace the existing code with: (see Screen shot below)

Map Logic Data Frame Properties

Dim mxDoc As IMxDocument
Set mxDoc = ThisDocument
Dim featureName As String

‘ identify the feature the map series is zooming to
‘ in this case, the (1) represents the first field in the layer being selected against…change as needed
‘ note: The fields are zero based. Normally, the objectID is field number 0.
featureName = pFeature.Value(1)
Dim fLayerDefinition As IFeatureLayerDefinition
Set fLayerDefinition = pIndexLayer

‘determine what the field name is.
‘in this case, the field name is BASIN…change as needed
fLayerDefinition.DefinitionExpression = “BASIN = ‘” & featureName & “‘”

Microsoft Visual Basic Map Logic Code


Juan Tobar, Supervisor Geographers, Regulation GIS, SFWMD
Linda McCafferty, Geographer 3, Regulation GIS, SFWMD

Keyword Searches in a Geospatial Data Library (with Video)

This is the 3rd post on building a geospatial data library. Other posts on this topic:

1. Structured Searches in a Geospatial Data Library (with Video)
2. Keyword Searches in a Geospatial Data Library (with Video)

In this video I showcase the keyword search functions of the Geospatial Data Library. As with structured searches keyword searches are extremely fast because we are loading a verbose text string with all the pertinent information directly into memory. We can search using the name of the geographic feature, geography, sources, dates, and other discriminators.

In future posts I will be building a MS Access database to support the loading and discovery of geospatial data.

Structured Searches in a Geospatial Data Library (with Video)

This is the 2nd post on building a geospatial data library. Other posts on this topic:

1. Structured Searches in a Geospatial Data Library (with Video)
2. Keyword Searches in a Geospatial Data Library (with Video)

So to recap…

We run into problems when we try to implement any naming conventions on source data:

  • More than likely you will run into system imposed limits on the length of the name. For example SDE Feature Classes in ORACLE can be no longer than 38 characters including the instance name.
  • Usually, source names are not user friendly and trying to find a particular one from a list of 800 or more can test anyones patience especially if you are not a GIS professional.
  • Once a source has been named it is very difficult to rename. Customers will quickly link applications and maps thus modifying a source name become a destabilizing event.

The solution to these issues is to implement standards in a look-up table rather than directly on the source data. In principal, such a system would consist of a parent table containing source information (SDE, services, layers, shapes, covers, etc…) and a daughter table containing your classification schema. A graphical user interface would then provide users with access to the information in the daughter table while a backend uses the parent table to retrieve the data.

The image below is of a geospatial data library my unit implemented at SFWMD. The system was written in C# as an extension to ArcMap. In the video the structured searches are occuring through the daughter table.