用gdal实现将shp文件中的shape字段转成wkt

public List<string> ShptoWkt(string path)
        {
            List<string> list = new List<string>();
            string wkt = "";

            OSGeo.OGR.Ogr.RegisterAll();
            OSGeo.OGR.Driver dr = OSGeo.OGR.Ogr.GetDriverByName("ESRI shapefile");

            if (dr == null)
            {
                return list;
            }

            OSGeo.OGR.DataSource ds = dr.Open(path, 0);
            int layerCount = ds.GetLayerCount();

            OSGeo.OGR.Layer layer = ds.GetLayerByIndex(0);

            //投影信息
            OSGeo.OSR.SpatialReference coord = layer.GetSpatialRef();
            string coordString;
            coord.ExportToWkt(out coordString);

            OSGeo.OGR.Feature feat;
            //string contentString = "";
            //读取shp文件
            while ((feat = layer.GetNextFeature()) != null)
            {
                OSGeo.OGR.Geometry geometry = feat.GetGeometryRef();
                OSGeo.OGR.wkbGeometryType goetype = geometry.GetGeometryType();
                geometry.ExportToWkt(out wkt);
                list.Add(wkt);
            }
            return list;
        }

猜你喜欢

转载自blog.csdn.net/baidu_23263735/article/details/82946304