[mapserver-users] geomfromtext (POSTGIS) in C# or other language...
Hello Guys... I´d like to add a point in a Postgis layer... I´m able to do this using geomfromtext function (postgis)... I´d like to do that in C# ... Is that possible? Thankz ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] geomfromtext (POSTGIS) in C# or other language...
Paul, You could probably use the GDAL C# bindings and the Geometry.CreateFromWkt function for this purpose. For more information see the createdata.cs example in the gdal source tree. Best regards, Tamas 2008/9/18 Paul james [EMAIL PROTECTED]: Hello Guys... I´d like to add a point in a Postgis layer... I´m able to do this using geomfromtext function (postgis)... I´d like to do that in C# ... Is that possible? Thankz ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] geomfromtext (POSTGIS) in C# or other language...
Thanks Thamas... Thats sounds great... But, after I used Geometry.CreateFromWkt function to convert my geometry, how can I add it to the PostGis Layer? On Thu, Sep 18, 2008 at 12:06 PM, Tamas Szekeres [EMAIL PROTECTED]wrote: Paul, You could probably use the GDAL C# bindings and the Geometry.CreateFromWkt function for this purpose. For more information see the createdata.cs example in the gdal source tree. Best regards, Tamas 2008/9/18 Paul james [EMAIL PROTECTED]: Hello Guys... I´d like to add a point in a Postgis layer... I´m able to do this using geomfromtext function (postgis)... I´d like to do that in C# ... Is that possible? Thankz ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] geomfromtext (POSTGIS) in C# or other language...
Paul, You should probably do the following steps when creating a new layer from scratch: // Register OGR Ogr.RegisterAll(); // Get the postgis driver Driver drv = Ogr.GetDriverByName(PostgreSQL); // Create the datasource DataSource ds = drv.CreateDataSource( [data source name], new string[] {} ); // Create the layer Layer layer = ds.CreateLayer( [layer name], null, wkbGeometryType.wkbPoint, new string[] {} ); // Adding attribute fields to the layers if needed FieldDefn fdefn = new FieldDefn( Name, FieldType.OFTString ); fdefn.SetWidth(32); layer.CreateField( fdefn, 1 ) ; // Adding features to the layer Feature feature = new Feature( layer.GetLayerDefn() ); feature.SetField( Name, value ); Geometry geom = Geometry.CreateFromWkt(POINT(47.0 19.2)); feature.SetGeometry( geom ); layer.CreateFeature( feature ); Best regards, Tamas 2008/9/18 Paul james [EMAIL PROTECTED]: Thanks Thamas... Thats sounds great... But, after I used Geometry.CreateFromWkt function to convert my geometry, how can I add it to the PostGis Layer? On Thu, Sep 18, 2008 at 12:06 PM, Tamas Szekeres [EMAIL PROTECTED] wrote: Paul, You could probably use the GDAL C# bindings and the Geometry.CreateFromWkt function for this purpose. For more information see the createdata.cs example in the gdal source tree. Best regards, Tamas 2008/9/18 Paul james [EMAIL PROTECTED]: Hello Guys... I´d like to add a point in a Postgis layer... I´m able to do this using geomfromtext function (postgis)... I´d like to do that in C# ... Is that possible? Thankz ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] geomfromtext (POSTGIS) in C# or other language...
2008/9/18 Paul james [EMAIL PROTECTED]: I got a point from postgis in this format : 01010059405940 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 ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users