[mapserver-users] geomfromtext (POSTGIS) in C# or other language...

Tamas Szekeres szekerest at gmail.com
Thu Sep 18 17:44:44 EDT 2008


2008/9/18 Paul james <pauljame at gmail.com>:

> I got a point from postgis in this format :
> 010100000000000000000059400000000000005940

It smells like a wkt geometry representation in hexstring format. You
should convert this into a binary array and then use
Geometry.CreateFromWkb, something like (untested):

// allocate byte array based on half of string length
byte[] bytes = new byte[(strInput.Length) / 2];
// loop through the string - 2 bytes at a time converting it to
decimal equivalent and store in byte array
int i = 0, x= 0;
while (strInput.Length > i + 1)
{
    long lngDecimal = Convert.ToInt32(strInput.Substring(i, 2), 16);
    bytes[x] = Convert.ToByte(lngDecimal);
    i = i + 2;
    ++x;
}
Geometry geom = Geometry.CreateFromWkb(bytes);


I wonder if there is some support to this kind of string conversion in
the .NET FW class library (something like the BitConverter class) that
I'm not aware of. Let me know if you can do it easier.

Best regards,

Tamas


More information about the mapserver-users mailing list