Hi windsnow,<br><br>I am not able review the code you have sent... but i am attaching something i have written for a project to extract data from postgresql to a shapefile .. based on the extact sql query that what you want to pass.<br>
<br><br>hope you find it useful..<br><br>Rgds.<br>Abhay.<br><br><br><div class="gmail_quote">2008/4/26 <<a href="mailto:windwxc@sina.com">windwxc@sina.com</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c"> hi,every one. I need read the spatial data in postgresql and transform it to shape file and show it by axmapcontrol in my project. My code can run but when i use arcmap open the new shape file i find it cannot show any graphics and the attribute table is empty. the size of the shape isnot 0k. I run same code but only once the shape file can show graphic and can be seen the arrtibute. The following is code and i wish you can help me find where is error.<br>
public void GetGeometry(string sqltext)<br>
{<br>
// open the postgis and read data according sqltext<br>
try {<br>
<br>
try<br>
{<br>
Ogr.RegisterAll();<br>
}<br>
catch (Exception e)<br>
{ MessageBox.Show(e.Message); }<br>
try<br>
{<br>
OSGeo.OGR.DataSource pgconn = OSGeo.OGR.Ogr.Open ("PG:host=localhost dbname='stdb' user='stuser' password=123", 1);<br>
OSGeo.OGR.Layer myOGRLay = pgconn.ExecuteSQL(sqltext,null, "tt");<br>
FeatureDefn myDef = myOGRLay.GetLayerDefn();<br>
int TT = myDef.GetFieldCount();<br>
int ftcount = myOGRLay.GetFeatureCount(1);<br>
OSGeo.OGR.DataSource shpconn;<br>
OSGeo.OGR.Driver shpdriver;<br>
shpdriver=Ogr.GetDriverByName("ESRI Shapefile");<br>
string path = Application.StartupPath + "\\database\\yantian2005.shp";<br>
<br>
OSGeo.OGR.SpatialReference myspatial = new SpatialReference("");<br>
myspatial.ImportFromProj4("+proj=Transverse_Mercator +zone=48N+datum=GCS_WGS_1984");<br>
shpconn = shpdriver.CreateDataSource(path, null);<br>
OSGeo.OGR.Layer myshplay = shpconn.CreateLayer("yantian2005", null , OSGeo.OGR.wkbGeometryType.wkbPolygon, null);<br>
if (myshplay == null)<br>
{<br>
MessageBox.Show("create layer failor!");<br>
}<br>
<br>
OSGeo.OGR.Feature myOGRFeat = null;<br>
for (int i = 0; i<br>
</div></div><div class="Ih2E3d"> OSGeo.OGR.Geometry myGeom = myOGRFeat.GetGeometryRef();<br>
myOGRft.SetGeometry(myGeom);<br>
for (int i = 0; i<br>
</div><div class="Ih2E3d"> if (myFieD.GetFieldType() == OSGeo.OGR.FieldType.OFTString)<br>
{<br>
myOGRft.SetField(i, myOGRFeat.GetFieldAsString(i));<br>
}<br>
else if (myFieD.GetFieldType() == OSGeo.OGR.FieldType.OFTInteger)<br>
{<br>
myOGRft.SetField(i, myOGRFeat.GetFieldAsDouble(i));<br>
}<br>
else if (myFieD.GetFieldType() == OSGeo.OGR.FieldType.OFTInteger)<br>
{<br>
myOGRft.SetField(i, myOGRFeat.GetFieldAsInteger(i));<br>
}<br>
}<br>
myOGRft = myOGRFeat.Clone();<br>
myOGRft.SetFrom(myOGRFeat, 1);<br>
<br>
myshplay.CreateFeature(myOGRft);<br>
<br>
count = count + 1;<br>
myOGRft.Dispose();<br>
}<br>
<br>
axMapControl1.ActiveView.FocusMap.ClearLayers();<br>
axMapControl1.AddLayerFromFile(Application.StartupPath + "\\database\\yantian2005.shp",0);<br>
axMapControl1.ActiveView.Refresh();<br>
//pgconn.Dispose();<br>
}<br>
catch (Exception e)<br>
{ MessageBox.Show( e.Message);<br>
// conn.Dispose();<br>
Application.Exit();<br>
}<br>
}<br>
catch (Exception e)<br>
{<br>
MessageBox.Show( e.Message);<br>
}<br>
}<br>
i know some my code is rudundant and wish you can point out.<br>
thank you<br>
best regard.<br>
</div>ps: wish this my email is right .<br>
<div><div></div><div class="Wj3C7c"> windsnow<br>
<br>
-------------------------------------------------------------------<br>
想玩得精彩?快来惠普"我的电脑 我的舞台"( <a href="http://d1.sina.com.cn/sina/limeng3/mail_zhuiyu/2008/mail_zhuiyu_20080421.html" target="_blank">http://d1.sina.com.cn/sina/limeng3/mail_zhuiyu/2008/mail_zhuiyu_20080421.html</a> )<br>
<br>
-------------------------------------------------------------------<br>
注册新浪2G免费邮箱(<a href="http://mail.sina.com.cn/" target="_blank">http://mail.sina.com.cn/</a>)</div></div><br>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></blockquote></div><br>