OGR笔记

1. 当要调用CreateLayer创建新shp图层时,要保证pODS是以Create的方式打开而非Open的方式,即pDriver->CreateDataSource。如果是用Open方式打开工作空间,要保证工作空间中已存在.shp格式的数据,否则调用CreateLayer时会报错。

2. 在完成对DataSource的操作后要销毁掉DataSource:OGRDataSource::DestroyDataSource(pODS) ,否则在ArcMap打开新创建的图层时会报错。

3. 在涉及到调用GEOS的功能,如果报下面的错误: 

错误描述:GeometryComponentFilter?.cpp:35:
virtual void geos::geom::GeometryComponentFilter::filter_ro(const geos::geom::Geometry*): Assertion `0′ failed.  
这是在调用OGRGeometry::Distance时报的错误,调用其他函数可能也会报类似错误。

解决办法:编译GEOS进行配置的时候在./configure前面加一句话 CFLAGS=”-m64″ CPPFLAGS=”-m64″ CXXFLAGS=”-m64″ LDFLAGS=”-m64″ FFLAGS=”-m64″
LDFLAGS=”-L/usr/lib64/” ./configure –prefix=/opt/geos3.3.8  然后再执行make , make install 即可。

4.对已有Shapefile文件进行编辑,更新某个属性字段的值

   (1)调用pFeature->SetField(fieldName,value);

   (2)调用pLayer->SetFeature(pFeature);

   如果至调用(1),则会发现属性表中的值仍未改变。不要担心调用(2)后会多一个Feature,因为pFeature的FID未改变,只会更新原Feature而已。

5.在调用pLayer->DeleteFeature(fid)删除某个Feature时,需调用 SQL ‘REPACK <tablename>’
,否则会发现属性表中未删除

The
OGR shapefile driver supports rewriting existing shapes in a shapefile as well as deleting shapes. Deleted shapes are marked for deletion in the .dbf file, and then ignored by OGR. To actually remove them permanently (resulting in renumbering of FIDs) invoke
the SQL ‘REPACK <tablename>’ via the datasource ExecuteSQL() method.

    如poDS->ExecuteSQL(“REPACK XJQ2”, NULL, “”);

转载自:https://blog.csdn.net/rybgis/article/details/34439435

You may also like...