C#通过Wkt码构建shp,记录写不进去!

  static void WriteVectorFile()
{
string strVectorFile = "E:\\";
// 注册所有的驱动
Ogr.RegisterAll();
//创建数据,这里以创建ESRI的shp文件为例
string strDriverName = "ESRI Shapefile";
Driver oDriver = Ogr.GetDriverByName(strDriverName);
if (oDriver == null)
{
Console.WriteLine("%s 驱动不可用!\n", strVectorFile);
return;
}
// 创建数据源
DataSource oDS = oDriver.CreateDataSource(strVectorFile, null);
if (oDS == null)
{
Console.WriteLine("创建矢量文件【%s】失败!\n", strVectorFile);
return;
} // 创建图层,创建一个多边形图层,这里没有指定空间参考,如果需要的话,需要在这里进行指定
Layer oLayer = oDS.CreateLayer("TestPolygon", null, wkbGeometryType.wkbPolygon, null);
if (oLayer == null)
{
Console.WriteLine("图层创建失败!\n");
return;
} // 下面创建属性表
// 先创建一个叫FieldID的整型属性
FieldDefn oFieldID = new FieldDefn("FieldID", FieldType.OFTInteger);
oLayer.CreateField(oFieldID, ); // 再创建一个叫FeatureName的字符型属性,字符长度为50
FieldDefn oFieldName = new FieldDefn("FieldName", FieldType.OFTString);
oFieldName.SetWidth();
oLayer.CreateField(oFieldName, );
FeatureDefn oDefn = oLayer.GetLayerDefn(); // 创建三角形要素
Feature oFeatureTriangle = new Feature(oDefn);
oFeatureTriangle.SetField(, );
oFeatureTriangle.SetField(, "三角形");
Geometry geomTriangle = Geometry.CreateFromWkt("POLYGON ((0 0,20 0,10 15,0 0))");
oFeatureTriangle.SetGeometry(geomTriangle);
oLayer.CreateFeature(oFeatureTriangle); // 创建矩形要素
Feature oFeatureRectangle = new Feature(oDefn);
oFeatureRectangle.SetField(, );
oFeatureRectangle.SetField(, "矩形");
Geometry geomRectangle = Geometry.CreateFromWkt("POLYGON ((30 0,60 0,60 30,30 30,30 0))");
oFeatureRectangle.SetGeometry(geomRectangle);
oLayer.CreateFeature(oFeatureRectangle); // 创建五角形要素
Feature oFeaturePentagon = new Feature(oDefn);
oFeaturePentagon.SetField(, );
oFeaturePentagon.SetField(, "五角形");
Geometry geomPentagon = Geometry.CreateFromWkt("POLYGON ((70 0,85 0,90 15,80 30,65 15,70 0))");
oFeaturePentagon.SetGeometry(geomPentagon);
oLayer.CreateFeature(oFeaturePentagon);
Console.WriteLine("\n数据集创建完成!\n");
}

通过对象构建

[GDAL]写入shp的更多相关文章

  1. C#、C++用GDAL读shp文件(转载)

    C#.C++用GDAL读shp文件 C#用GDAL读shp文件 (2012-08-14 17:09:45) 标签: 杂谈 分类: c#方面的总结 1.目前使用开发环境为VS2008+GDAL1.81 ...

  2. GDAL 生成shp文件

    附件:http://pan.baidu.com/s/1i3GPwrV(C#版GDAL接口.dll) 示例程序: http://pan.baidu.com/s/1jpIKQ  (程序是在vs2008 x ...

  3. python 利用 ogr 写入shp文件,数据格式

    python 利用 ogr 写入 shp 文件, 定义shp文件中的属性字段(field)的数据格式为: OFTInteger # 整型 OFTIntegerList # 整型list OFTReal ...

  4. 关于GDAL读写Shp乱码的问题总结

    目录 1. 正文 1.1. shp文件本身的编码的问题 1.2. 设置读取的编码方式 1.2.1. GDAL设置 1.2.2. 解码方式 1.2.3. 其他 2. 参考 1. 正文 最近在使用GDAL ...

  5. GDAL读取Shp问题解决:Unable to open EPSG support file gcs.csv

    在GIS软件的开发中,经常用到开源库GDAL读取Shp数据,当shp数据中包含投影信息时,可能会遇到“Unable to open EPSG support file gcs.csv”错误提示,该错误 ...

  6. python GDAL 读写shp文件

    gdal包用于处理栅格数据,ogr用于处理矢量数据. 1 #!C:\Program Files\pythonxy\python\python.exe 2 #-*- coding:gb2312 -*- ...

  7. python gdal 修改shp文件的属性值

    driver = ogr.GetDriverByName('ESRI Shapefile')datasource = driver.Open(shpFileName, 1)layer = dataso ...

  8. shp的基本操作

    本节将介绍如何利用python完成对shp的基本操作 1.读取shp四至 import shapefile sf = shapefile.Reader(r"E:\shp\1.shp" ...

  9. (数据科学学习手札59)从抓取数据到生成shp文件并展示

    一.简介 shp格式的文件是地理信息领域最常见的文件格式之一,很好的结合了矢量数据与对应的标量数据,而在Python中我们可以使用pyshp来完成创建shp文件的过程,本文将从如何从高德地图获取矢量信 ...

随机推荐

  1. Windows虚拟地址转物理地址(原理+源码实现,附简单小工具)

                                                                                                        ...

  2. 树莓派3b配置耳机音频输出

    耳机输出 amixer cset numid=3 1 然后,播放既可,有杂音. hdmi输出 amixer cset numid=3 2

  3. 【laravel5.6】 Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

    在进行数据迁移时候报错: 特殊字段太长报错, php artisan migrate 现在utf8mb4包括存储emojis支持.如果你运行MySQL v5.7.7或者更高版本,则不需要做任何事情. ...

  4. Delphi应用程序的调试(六)步进式代码调试

    步进式代码调试(Stepping Through Your Code) 步进式代码调试是最基本的调试操作之一,但仍要在此讲述.人们常常容易犯只见树木不见森林的错误.经常复习基本的知识有助于读者了解以前 ...

  5. 【Spring Boot && Spring Cloud系列】在spring-data-Redis中如何使用切换库

    前言 Redis默认有16个库,默认连接的是index=0的那一个.这16个库直接是相互独立的. 一.在命令行中切换 select 1; 二.在Spring中如何切换 1.在RedisConnecti ...

  6. Android studio 运行demo时一直卡在"Installing APKS"时的解决办法

    现象 一 File --- Settings 二 看图操作

  7. WORD Application.Documents.Open函数返回null的一种解决方法

    DCOM Config Setting for "Microsoft Office Word 97 - 2003 Document" 内部配置一切正常,但调用Application ...

  8. Docker关联使用的一些工具:Clip名字服务(转载)

    Clip名字服务 Clip(http://blog.puppeter.com/read.php?7)是一个名字服务C/S架构,它将传统的IP管理维度替换为名字服务即有意义可记忆的String.Clip ...

  9. [工具]Sublime 显示韩文

  10. linux上jar包的运行

    指定目录: #!/bin/bash source /etc/profile log() { echo `date +[%Y-%m-%d" "%H:%M:%S]` $1 } log ...