[postgis-users] RC6 + ArcObjects

Abe Gillespie abe.gillespie at gmail.com
Tue Apr 12 09:06:05 PDT 2005


I'm dabbling in connecting / using PostGIS in ESRI ArcObjects.  I'm
experiencing intermittent problems though.  I've included the code I'm
using below.  I realize there are three different technologies
entering the mix here: Npgsql, PostGIS, and ArcObjects.  However, I'm
led to believe the problem is with PostGIS and not the others; this
use to fail *every* time in earlier PostGIS releases.

The thing to notice is different runs produce different outputs.  The
output being the IDs of the records throwing exceptions.

I've attached the sql script of the problematic data.  I'd appreciate
it if anyone could look into this but also realize this problems spans
multiple areas of expertise.

Thansk.
-Abe

// begin code -->
using System;
using ESRI.ArcObjects.Core;
using Npgsql;

namespace WKB
{
    class Program
    {
        static void Main(string[] args)
        {
            // Connect to PostGIS and query.
            NpgsqlConnection con = new NpgsqlConnection(connectionString);
            con.Open();
            NpgsqlCommand cmd = con.CreateCommand();
            cmd.CommandText = "select asbinary(the_geom) as shape,gid
from roads;";
            NpgsqlDataReader dr = cmd.ExecuteReader();

            // Setup objects and ArcObjects.
            object bin;
            IGeometry geo;
            int byteCnt;
            GeometryEnvironmentClass geoEnv = new GeometryEnvironmentClass();

            while (dr.Read())
            {
                bin = null;
                geo = null;
                byteCnt = 0;

                bin = dr["shape"];
                try
                {
                    // Try to convert raw data into an ArcObject.
                    geoEnv.CreateGeometryFromWkbVariant(bin, out geo,
out byteCnt);
                }
                catch
                {
                    // There was a failure.
                    // The exception always has a generic description.
                    Console.WriteLine(dr["gid"].ToString());
                    continue;
                }
            }
        }

        static private string connectionString { get { return
"your_con_str_here"; } }
    }
} 
// <-- end code.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: roads.zip
Type: application/zip
Size: 1363645 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20050412/b6ef0756/attachment.zip>


More information about the postgis-users mailing list