jinjinhao
论坛版主
论坛版主
  • 注册日期2004-05-19
  • 发帖数35
  • QQ
  • 铜币91枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2194回复:3

Shape 文件写/读问题

楼主#
更多 发布于:2005-08-20 14:06
在我做的一个数据转换的程序中,新建了一个Shape,然后紧接着又从这个文件中读取数据。在读取时系统仍然锁定这个文件,造成无法读取。找遍了示例也没找到关于如何释放已打开的FeatureClass。请大家不吝赐教,不胜感激。
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2005-08-20 14:13
<P>是建立shp文件,写完后,</P>
<P>然后加载吗,那应该没问题啊,可能是你操作过程出错或者没有停止编辑和写入操作了</P>
<P>最好贴出相关代码和说明</P>
举报 回复(0) 喜欢(0)     评分
jinjinhao
论坛版主
论坛版主
  • 注册日期2004-05-19
  • 发帖数35
  • QQ
  • 铜币91枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2005-08-20 15:14
        bool ConvertLaser2Shape(string laserFullPath,string shapeFullPath)<br>
        {<br>
            string shapePath,shapeFile;<br>
            try<br>
            {<br>
              
 shapePath = System.IO.Path.GetDirectoryName(shapeFullPath);<br>
            }<br>
            catch (ArgumentException ae)<br>
            {<br>
                infoText.Text = infoText.Text + "\n" + ae.Message;<br>
                return false;<br>
            }<br>
<br>
            try<br>
            {<br>
              
 shapeFile =
System.IO.Path.GetFileNameWithoutExtension(shapeFullPath) +".shp";<br>
            }<br>
            catch(ArgumentException e)<br>
            {<br>
                infoText.Text = infoText.Text + "\n" + e.Message;<br>
                return false;<br>
            }<br>
            <br>
          
 ISpatialReference pSpatialRef = new
ESRI.ArcGIS.Geometry.UnknownCoordinateSystemClass();<br>
<br>
            IFields pFields = null;<br>
          
 CreateBasicFields(esriGeometryType.esriGeometryPoint,
pSpatialRef, out pFields);<br>
<br>
            // 创建中间 shape 文件<br>
            IWorkspaceFactory pWkspFac = new ShapefileWorkspaceFactory();<br>
            IWorkspace pWksp = pWkspFac.OpenFromFile(shapePath, 0);  <br>
            if (pWksp == null)<br>
            {<br>
              
 infoText.Text = infoText.Text + "\n不能创建 Shape 文件的工作空间.转换中止...";<br>
                return false;<br>
            }<br>
            IFeatureWorkspace pFeatureWksp = (IFeatureWorkspace)pWksp;<br>
            IFeatureClass pOutFeatureClass = null;<br>
            try<br>
            {<br>
              
 pOutFeatureClass = pFeatureWksp.CreateFeatureClass(shapeFile,
pFields, null, null,esriFeatureType.esriFTSimple, "Shape", "");<br>
            }<br>
            catch(Exception e)<br>
            {<br>
//              
 infoText.Text = infoText.Text + "\n建立点要素类失败."+e.Message;<br>
                return false;<br>
            }  
             <br>
  <br>
            //将数据写入 shape 文件<br>
            IFeatureCursor pOutCursor = pOutFeatureClass.Insert(true);<br>
            IFeatureBuffer pOutBuffer = pOutFeatureClass.CreateFeatureBuffer();<br>
            IPoint pPoint = (IPoint)new ESRI.ArcGIS.Geometry.PointClass();<br>
          
 ESRI.ArcGIS.Geometry.IZAware pZAware =
(ESRI.ArcGIS.Geometry.IZAware)pPoint;<br>
            pZAware.ZAware = true;<br>
            System.IO.StreamReader sr = new System.IO.StreamReader(laserFullPath);<br>
            string line;<br>
            string []coor = new String[3];<br>
            while ((line = sr.ReadLine()) != null)<br>
            {<br>
                coor = line.Split('\t');<br>
                pPoint.X = Convert.ToDouble(coor[0]);<br>
                pPoint.Y = Convert.ToDouble(coor[1]);<br>
                pPoint.Z = Convert.ToDouble(coor[2]);<br>
                pOutBuffer.Shape = (IGeometry)pPoint;<br>
                pOutBuffer.set_Value(2,pPoint.Z);<br>
//              
 infoText.Text = infoText.Text + pOutBuffer.Fields.FieldCount;<br>
//                pOutBuffer.Fields.get_Field(2).<br>
                pOutCursor.InsertFeature(pOutBuffer);<br>
            }<br>
            infoText.Text
= infoText.Text +"\n在目录 "+shapePath+" 中成功创建 Shape 文件:"+shapeFile;<br>
<br>
<br>
            return true;<br>
        }<br>
<br>
举报 回复(0) 喜欢(0)     评分
jinjinhao
论坛版主
论坛版主
  • 注册日期2004-05-19
  • 发帖数35
  • QQ
  • 铜币91枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2005-08-20 15:17
这是生成shape文件的代码,建好以后,如果不退出程序,就不会释放shape文件,连在ArcCatalog中都无法预览,只有退出程序后,才可以.
举报 回复(0) 喜欢(0)     评分
游客

返回顶部