<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Markeringsbobletekst Tegn";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.MarkeringsbobletekstTegn
        {mso-style-name:"Markeringsbobletekst Tegn";
        mso-style-priority:99;
        mso-style-link:Markeringsbobletekst;
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:3.0cm 2.0cm 3.0cm 2.0cm;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=DA link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span lang=EN-US>Hi everybody<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>I just started using the GDAL/OGR CSharp
interface in Visual Studio and it works great. <o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>I am trying to append a shapefile to a
postgis table. This I can do with the following lines in ogr2ogr:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Fist import the shapefile to postgis a
table<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>ogr2ogr -f &quot;PostgreSQL&quot;
PG:&quot;dbname='postgis' host='localhost' port='5432' user='...'
password='...'&quot; -lco PRECISION=NO -lco GEOMETRY_NAME=geom -a_srs
EPSG:25832 &quot;c:\temp\testfile.shp&quot;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Then append the same shapefile (this is a
test) to the same postgis table like this<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>ogr2ogr -append -update -f
&quot;PostgreSQL&quot; PG:&quot;dbname='postgis' host='localhost' port='5432'
user='...' password='...'&quot; &quot;c:\temp\testfile.shp&quot;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>But how do I do this in the GDAL/OGR CSharp
interface or which classes and functions do I use?<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>So far what I have done is:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Open a layer from the shapefile:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>string fileShp =
@&quot;c:\temp\testfile.shp&quot;;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>DataSource InputDataSource =
Ogr.Open(fileShp, 0);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Layer inputLayer =
InputDataSource.GetLayerByIndex(0);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>FeatureDefn def =
inputLayer.GetLayerDefn();<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Open a datasource to postgis:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>OutputDriver =
Ogr.GetDriverByName(&quot;PostgreSQL&quot;);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>DataSource OutputDataSource =
OutputDriver.Open(&quot;PG:dbname='postgis' host='localhost' port='5432'
user='...' password='...'&quot;, 1);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Copy the layer to the postgis table:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Layer outputLayer =
OutputDataSource.CopyLayer(inputLayer, def.GetName(), new string[] {
&quot;GEOMETRY_NAME=geom&quot;, &quot;PRECISION=NO&quot; }); //How to add
-a_srs EPSG:25832?<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>This works to import the shapefile to a
postgis table. But what should I do when to append the same shapefile to the
postgis a table. So far I have done this:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Open a layer from the shapefile:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>string fileShp =
@&quot;c:\temp\testfile.shp&quot;;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>DataSource InputDataSource =
Ogr.Open(fileShp, 0);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Layer inputLayer =
InputDataSource.GetLayerByIndex(0);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>FeatureDefn def =
inputLayer.GetLayerDefn();<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Open a datasource to postgis:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>OutputDriver =
Ogr.GetDriverByName(&quot;PostgreSQL&quot;);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>DataSource OutputDataSource =
OutputDriver.Open(&quot;PG:dbname='postgis' host='localhost' port='5432'
user='...' password='...'&quot;, 1);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Layer outputLayer =
OutputDataSource.GetLayerByName(def.GetName());<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Feature feat;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>while ((feat = inputLayer.GetNextFeature())
!= null)<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outputLayer.CreateFeature(feat);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>The CreateFeature functions fails with a
syntax error in the INSERT command. Below is a short version of the command
with the syntax error: <o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Command: INSERT INTO &quot;testfile&quot;
(&quot;geom&quot; , &quot;ogc_fid&quot; , &quot;name&quot;) VALUES
(GeomFromEWKT('SRID=-1;POINT (701678 6152444)'::TEXT) , 0 , Test)<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>The field &quot;name&quot; is a character
varying in postgis a the command needs single quotes around 'Test'.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>How do I solve this syntax error?<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>I am also wondering how to assign an output
SRS when creating the postgis table like the ogr2ogr flag -a_srs EPSG:25832?<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Any help or comment would be appreciated.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal>Regards Esben.<o:p></o:p></p>

</div>

</body>

</html>