zigGIS and Spatial References, Part 2

Update to this post:

Another post about zigGIS. I didn’t really intend this blog to be so dominated by zigGIS but that’s certainly the way it’s been thus far. Basically, it’s just really cool and it satisfies my geek nature on a couple of fronts.

After posting about the spatial reference issue before, I couldn’t resist digging into it. I found a placeholder in the implementation of IFeatureClass. Abe G. had even left a comment there that he needed to go back and implement it. So I dove in…

In the IFeatureClass implementation of CPostGisFeatureClass the SpatialReference property was stubbed out to always return and UnknownCoordinateSystem object. The feature class wraps a CLayer object (among others). This is the object I needed to use to get the spatial reference. The loadLayer method of CLayer (in the postgis_connector project) contained the following code:

string sql = CDbHelper.createSelectSql
(CPostGisConstants.geometryColumnsTable + " as g",
"g.*,g.oid,s." + CPostGisConstants.spatialReferenceSrField,
"left join " + CPostGisConstants.spatialReferenceTable + 
" as s on g." +
CPostGisConstants.spatialReferenceIdField + "=s." +

This code queries the geometry_columns table for all of the metadata I need. So I added the following code to the CLayer class:

private int m_srid = -1;
public int srid { get { return m_srid; } }

I then added this code to the loadLayer method…

m_srid = (int)((Int32)dr["srid"]);

…in order to expose the srid for the layer. The variable dr refers to an instance of the CAutoDataReader class defined in the postgis_connector project.

Finally, i added the following code to the init method of the CPostGisFeatureClass class in the postgis_geodatabase project:

if (m_layer.srid != -1)
    ISpatialReferenceFactory2 srfact = new SpatialReferenceEnvironmentClass();
    m_spaRef = srfact.CreateSpatialReference(m_layer.srid);

With that, the layer properties dialog in ArcMap correctly reports my spatial reference and the geometry that once failed to draw now works fine. I’ve got some more clean-up to do to the code to add some error-handling and the like. I’m sure it wouldn’t take much to crash it right now.

I think the thing I like about zigGIS is that it’s got something for everyone. ArcObjects geeks will appreciate the implementation of feature classes, cursors and the like. .NET geeks will appreciate nuggets like the CAutoDataReader class which is an implementation of the IDataReader interface. All in all, it’s a nice piece of work that I find more to like about as I dig deeper.

As I mentioned before, the project has a new home in Google Code and the discussion forum is getting a little more active so maybe zigGIS will gain a little more momentum. That’s all for now…

zigGIS on Google Code

It seems this is quickly turning into the zigGIS blog. Anyway, it appears that Paolo Corti has assumed the role of project lead on zigGIS and has moved it to Google Code. I’m excited because I think this is a great project and this should keep it moving forward. There’s also a group for discussing the project.

Thanks to Abe Gillespie and Paolo for collaborating to keep zigGIS going.

zigGIS and Spatial References

I’m still playing around with zigGIS and I have noticed that it doesn’t seem to play well when I define the spatial reference of a data set in PostGIS. Any data set that has a defined spatial reference fails to draw in ArcMap. In addition, the layer properties always indicate that the coordinate system is undefined, whether on exists or not. This leads me to belienve that zigGIS is not handling the spatial references well.

As you can see, the dtl_st layer does not draw in ArcMap. I imported it into PostGIS using shp2pgsql with an SRID of 4326 (WGS84). The others layers were loaded with an SRID of -1.

As shown, the layer draws fine in QGIS. I will need to dig into the zigGIS code a little more to see about this one.

PostGIS and ArcGIS 9.1

I’ve been intrigued for some time by an open-source (GPL) project out there called zigGIS. It is a C# project that enables a direct read of PostGIS by ArcGIS. It is intriguing for a couple of reasons. First is the promise of reading directly from PostGIS and working with your data in ArcMap without the need to create intermediate shapefiles or some other ESRI-friendly data format. Second is the fact that the project is a good example of the “correct” way to extend data support in ArcGIS. That’s to say the authors built the necessary workspace, feature class, and cursor objects to behave like any other set of geodatabase objects. As an ArcObjects developer, having a working example of this, with source code, was irresistable.

I had originally downloaded it about a year ago but let it sit because it only supported ArcGIS 8.x. I recently went back to it discover an updated version but still only 8.x support. I had a little more time on my hands this time and decided to do the upgrade to 9.1 myself.

The ArcObjects upgrade was fairly painless but I’ve done that a few times now. I found the documentation to be a little thin on some of the project’s dependencies. Specifically, there are several external open-source projects that zigGIS is dependent upon: log4net, npgsql, nini. While the readme specifies these, it doesn’t mention version numbers. This created the greatest issue with npgsql due to the fact that the zigGIS developers build a custom version for zigGIS.

The install instructions indicate that you should get npgsql from the pgFoundry and then replace the DLL with custom one for zigGIS. The problem arose from the fact that npgsql has been updated and it also has a dependency on Mono.Security.dll. The latest version of npgsql.dll uses version 2.0 of Mono.Security.dll but the version used by zigGIS uses version 1.0.5 of Mono.Security.

Once I sorted this out, I used the ESRI developer tools to remove references to ESRI.ArcObjects.Core and replace them with the necessary 9.1 libraries. ZigGIS comes with a VS2005 solution but I highly recommend following the developers’ instructions and using nant to do your build. They provide their build script and it needs to be updated for 9.1 but it works great. The cursor and geodatabase projects introduce the kind of circular references that Visual Studio doesn’t like but that nant handles nicely.

POSTGIS Data in ArcMap with identify window. After I got the project to build, I was able to access data directly from PostGIS. This screen shot shows a sample data set in ArcMap. I’m running PostgreSQL 8.2 with PostGIS 1.2.0 on a Windows XP box. I loaded this data into PostGIS using the shp2pgsql utility that ships with PostGIS. The utility of zigGIS is readily apparent but its approach holds wider promise. There are numerous other data sources and open-source projects that could be integrated using the approach the zigGIS team has laid out here. MITAB is one that springs to mind.

Despite some of the issues I had with the build process, I got the project up and running in less than a day. Given the results, that seems like a worthy investment of time.