Monday, September 29, 2008

More ArcScene Stuff

So, I spent all that time setting up the repair data source code, and then discovered that by right-clicking on the layer, going to Data --> Repair Data Source, ArcWhatever fixes all the ones that were in the same folder. Same problem with the base heights though.

Now I'm exporting ArcScene scenes to 2d images. I had originally done this on my laptop and got everything setup on there. There were problems exporting the image with background vector data (roads and coastline). The coastline was a polygon and came out with extra lines cutting across the 3d. So my work around was to export the vector and 3d as separate images and then make them as layers in PhotoShop Elements. This works pretty well. Now I'm working on the desktop and discovered that the images don't export the same size. The reason for this is the monitor size and resolution as the export dimensions are determined by this. You can also change the export dimensions by changing the height and width of ArcScene. This is a pain to duplicate, but at least now I know what the problem is.

Repair Datasource

I had a number of ArcScene documents (sxd) with several layers (>20) with a broken source, and I didn't really feel like manually going through each one and repairing it, so I poked around trying to find an example to do it in VBA. Most of the examples were for feature layers, whereas these were all raster layers, and none were for ArcScene. I found one that worked for rasters, but then I lost the renderer and layer name which were both important in the file.

This is the mesh that I came up with. Probably a good idea to save your sxd as something else before running the code. I also needed to close out and open back up before the settings took effect. The base heights disappeared and I'm not sure why this happened but I already had a bit of code to set the base height to the layer because I'm lazy and didn't want to go layer by layer setting the base heights.

Here is the code to set the source:

Private Sub SetSource()
Dim pDoc As ISxDocument: Set pDoc = ThisDocument
Dim pScene As IScene: Set pScene = pDoc.Scene
Dim pSG As ISceneGraph: Set pSG = pScene.SceneGraph
Dim pSV As ISceneViewer: Set pSV = pSG.ActiveViewer
Dim il As Integer
Dim pNewWorkspaceName As IWorkspaceName
Set pNewWorkspaceName = New WorkspaceName
With pNewWorkspaceName
.PathName = "D:\gamblingout"
.WorkspaceFactoryProgID = "esriDataSourcesRaster.RasterWorkspaceFactory.1"
End With

For il = 1 To pScene.layerCount - 1
Dim pLayer As ILayer: Set pLayer = pScene.Layer(il)
Dim pRLayer As IRasterLayer: Set pRLayer = pLayer
Dim pDataLayer2 As IDataLayer2: Set pDataLayer2 = pRLayer
Dim pDatasetName As IDatasetName
Set pDatasetName = pDataLayer2.DataSourceName
Set pDatasetName.WorkspaceName = pNewWorkspaceName
pDataLayer2.DataSourceName = pDatasetName
End Sub

You will probably need to change the start layer, as I had it set as 1 instead of 0.

Here is the code for the base heights.

Public Sub Set3d()
Dim pDoc As ISxDocument: Set pDoc = ThisDocument
Dim pScene As IScene: Set pScene = pDoc.Scene

Dim il As Integer
For il = 1 To pScene.layerCount

Dim pLayer As ILayer: Set pLayer = pScene.Layer(il)
Dim pLayerExt As ILayerExtensions: Set pLayerExt = pLayer
Dim p3dProps As I3DProperties

Dim i As Integer

' look for 3D properties of layer:
For i = 0 To pLayerExt.ExtensionCount - 1
If TypeOf pLayerExt.Extension(i) Is I3DProperties Then
Set p3dProps = pLayerExt.Extension(i)
Exit For
End If
Dim pSurf As IRasterSurface
Dim pBands As IRasterBandCollection
Dim pRasterLayer As IRasterLayer
Set pRasterLayer = pLayer
p3dProps.BaseOption = esriBaseSurface
Set pSurf = New RasterSurface
Set pBands = pRasterLayer.Raster
pSurf.RasterBand = pBands.Item(0)
Set p3dProps.BaseSurface = pSurf
p3dProps.Apply3DProperties pLayer

End Sub

There are no checks to make sure the layer is raster and not a feature layer. This is one area that could be expanded. Since it is for a fairly custom file, I know which layers are what type.

Wednesday, September 17, 2008

Flow Mapping

Getting a head start on a new project that is more cartographic. It will involve mapping migration/flows from Australia to the Northern Territory (probably smaller geographic units than states). I like making maps, and so I'm excited to do some cartography beyond standard ArcGIS layouts. There are different possibilities on how to map this. Initially, I think I will use something like this that creates a more trunk/branch flow map instead of the typical straight line between places (Tobler's Flowmapper). The project lead doesn't like this style too much, but thought the trunk/branch style might work. We might pursue other mapping techniques, which would be cool to try and apply different map techniques to this area...

The Flow Map Layout tool that comes with the article is actually pretty slick, at least when using the supplied examples. Instructions are lacking unfortunately, so I'm not sure how to use multiple root points. The output is nice, and allows for export to an eps file. That could be brought into Adobe Illustrator and edited. Ad ambitious as I can be, I'm thinking of creating something similar for ArcGIS but using a shapefile. This would give a lot of control over the final product. In their tool, you can move things around too...Anyway, there are limits and I'm a control freak.

Camel project finished up as much as that type of project can finish. It's one of those projects that you can keep adding to and making it more sophisticated. It was part of a larger part, but it sounds like this will also be produced as a separate GIS/Model report. See how that goes. It was an interesting and fun project to work on. Good people too.

Tuesday, September 16, 2008

Great Application

I've been traveling a broad, and two days after returning I caught a cold, so I haven't felt much like posting. But, this was too cool to pass up.

You can look at Mercator's Atlas :).