I’ve moved the blog and associated content to http://geographika.co.uk/
Self-hosting will hopefully allow me to post some working code examples, and will allow the site to be more flexible.
I’ve moved the blog and associated content to http://geographika.co.uk/
Self-hosting will hopefully allow me to post some working code examples, and will allow the site to be more flexible.
An often used function is to get a specific layer from a current map document. The code below is for VB.NET and requires a map document and the alias name of the feature class. The first function returns all IGeoFeature layers in a map – these are layers based on vector geographic data. The second loops through these layers and compares the layer names.
Public Function GetFeatureLayers(ByRef pMap As IMap) As IEnumLayer Dim pUID As New UIDClass pUID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" 'IGeoFeatureLayer GUID If pMap.LayerCount > 0 Then GetFeatureLayers = pMap.Layers(pUID, True) Else Return Nothing End If End Function Public Function GetFeatureLayerByAliasName(ByRef pMap As IMap, _ ByVal strLayerModelName As String) As IFeatureLayer Dim pLayerEnum As IEnumLayer Dim pFLayer As IFeatureLayer pLayerEnum = GetFeatureLayers(pMap) If pLayerEnum Is Nothing Then Return Nothing End If pFLayer = DirectCast(pLayerEnum.Next, IFeatureLayer) Do Until pFLayer Is Nothing If pFLayer.Valid Then If strLayerModelName = pFLayer.FeatureClass.AliasName Then Return pFLayer End If End If pFLayer = DirectCast(pLayerEnum.Next, IFeatureLayer) Loop 'the layer was not found Return Nothing End Function
Rather than using the layer name visible in the table of contents which is easly changed by a user, I use the .AliasName of the feature class. This is automatically set to the name of the layer when added to a map. A user is much less likely to change this. There is however another name that is 100% not to change, it does however require an additional step when adding the layer shown below:
Dim pModelInfo As IModelInfo pModelInfo = CType(pFLayer.FeatureClass, IModelInfo) pModelInfo.ModelName = “AnyValueYouLike”
The code to find this layer is similar to the FindFeatureLayer, but relies on the IModelInfo interface.
Public Function GetFeatureLayerByModelName(ByRef pMap As IMap, _ ByVal strLayerModelName As String) As IFeatureLayer Dim pLayerEnum As IEnumLayer Dim pFLayer As IFeatureLayer Dim pModelInfo As IModelInfo pLayerEnum = GetFeatureLayers(pMap) If pLayerEnum Is Nothing Then Return Nothing End If pFLayer = DirectCast(pLayerEnum.Next, IFeatureLayer) Do Until pFLayer Is Nothing If pFLayer.Valid Then pModelInfo = DirectCast(pFLayer.FeatureClass, IModelInfo) If strLayerModelName = pModelInfo.ModelName Then Return pFLayer End If End If pFLayer = DirectCast(pLayerEnum.Next, IFeatureLayer) Loop 'the layer was not found Return Nothing End Function
I’ve recently been working again with Intergraph’s Geomedia WebMap 5.2. Development can be done in .NET, which seemed very advanced a few years ago when ESRI’s flagship product was ArcIMS..
However it seems that line features can only be rendered as solid lines (no dots or dashes)..a very strange oversight, especially when it appears the outlines of polygons can have linear styling!
I’m going to be installing version 6 soon to see if it has been resolved, and see if there are any new features.
The following VBA function hides all on the geodatabase tables added by ESRI into an Access database. Useful if you spatially enable your users database, and they wonder what all those GDB_ tables are for..
To unhide just change the Trues to False, or pass this in as a variable.Public Sub HideGeoDatabaseTables()
Dim strTableName As String
For i = 0 To CurrentDb.TableDefs.Count - 1
If CurrentDb.TableDefs(i).Name Like "GDB_*" Then
strTableName = CurrentDb.TableDefs(i).Name
Access.SetHiddenAttribute acTable, strTableName, True
End If
NextAccess.SetHiddenAttribute acTable, "SelectedObjects", True
Access.SetHiddenAttribute acTable, "Selections", TrueEnd Sub
To view hidden objects in Microsoft Access, go to Options and check the “Hidden Objects” box.
System.Data.OleDb.OleDbException occurred
ErrorCode=-2147467259
Message=”Could not use ”; file already in use.”
Source=”Microsoft JET Database Engine”
Access, lock files, and Visual Source Safe – an accident waiting to happen! I got the above error, after my code had been fine for weeks. Googling turned up permissions on the folder with the Access database, and closing secondary applications. The solution in the end turned out to be that the .ldb file had come under source control. Removing it from this, and deleting the fle resolved the issue.
It can be frustrating when a code sample that seems to do exactly what you want is written in C#, and your application is in VB.Net. http://www.kamalpatel.net/ConvertCSharp2VB.aspx solves this problem by converting the C# code directly into its VB.Net equivalent – all online and for free for code up to 6.15KB in size, and for larger amounts of code a tool can be downloaded for free.
It does the majority of the conversion well but I ran into a few minor problems where line breaks were not taken into account.
This tool will be even more useful when the ESRI samples, the majority of which are only available in VB6, are updated to .NET…
I recently added some Lorem Ipsum text to fill in some space on a prototype ASP.NET website I made recently, which lead to a few questions from the client (a person not a machine) such as “what language is all this text in?!” A handy generator and a history of Lorem Ipsum can be found here.
However far more amusingly is the generator at http://www.malevole.com/mv/misc/text/. There are some real classics in there…
“Mutley, you snickering, floppy eared hound. When courage is needed, you’re never around. Those medals you wear on your moth-eaten chest should be there for bungling at which you are best. So, stop that pigeon, stop that pigeon, stop that pigeon, stop that pigeon, stop that pigeon, stop that pigeon, stop that pigeon. Howwww! Nab him, jab him, tab him, grab him, stop that pigeon now.”
I know I see this error about once a year and can never remember the cause, so I’m writing it down this time!
In my case it has always been related to SQL queries and Access databases. Check the following if your SQL command produces this error when executed:
I’ve been listening recently to “.NET Rocks!” twice weekly .NET development podcasts. It is very easy to listen to, mainly due to the personalities of the presenters, and it gives a good overview of .NET develpment and related technologies. Software development as a whole is often discussed – test driven development, agile programming, management, spaghetti code…
A full archive of previous episodes is available for download (for free), and I found an epsiode that gives a good introduction to Python – it can be downloaded here. I’m still not convinced of the use of Python and ArcObjects as explaining how to run scripts with parameters to GIS users, or creating custom toolboxes, takes as much time as creating a nice UI in Visual Studio. In the show one of the presenters asks “but don’t you miss the Visual Studio environment and intellisense?”, which I couldn’t agree more with. However there is also mention of IronPython, which I knew had something to do with .NET, but it can also apparently be used within the Visual Studio environment which could make life a whole lot easier.
I’m off to download IronPython now…
Writing ArcObjects code and using an Access personal geodatabase will result sooner or later in an error along the lines of “Cannot aquire a schema lock because of an existing lock.” Spending hours going through code, making sure objects are disposed of and that all connections closed often makes very little difference. It becomes apparent some of the problems lie deeper than customised code when the same errors occur when using ArcMap or ArcCatalog without any modifications.
I have been using Unlocker, a freeware program, to solve these issues when developing with ArcObjects (or just using ArcMap..). Once installed a simple right click on an ldb or mdb file can remove any file locks, and your code is free to run again. It works with any Windows file or folder so is a useful program to have around even without geodatabases.
More reviews and an alternative download site can be found here.