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

  1. static void WriteVectorFile()
  2. {
  3. string strVectorFile = "E:\\";
  4. // 注册所有的驱动
  5. Ogr.RegisterAll();
  6. //创建数据,这里以创建ESRI的shp文件为例
  7. string strDriverName = "ESRI Shapefile";
  8. Driver oDriver = Ogr.GetDriverByName(strDriverName);
  9. if (oDriver == null)
  10. {
  11. Console.WriteLine("%s 驱动不可用!\n", strVectorFile);
  12. return;
  13. }
  14. // 创建数据源
  15. DataSource oDS = oDriver.CreateDataSource(strVectorFile, null);
  16. if (oDS == null)
  17. {
  18. Console.WriteLine("创建矢量文件【%s】失败!\n", strVectorFile);
  19. return;
  20. }
  21.  
  22. // 创建图层,创建一个多边形图层,这里没有指定空间参考,如果需要的话,需要在这里进行指定
  23. Layer oLayer = oDS.CreateLayer("TestPolygon", null, wkbGeometryType.wkbPolygon, null);
  24. if (oLayer == null)
  25. {
  26. Console.WriteLine("图层创建失败!\n");
  27. return;
  28. }
  29.  
  30. // 下面创建属性表
  31. // 先创建一个叫FieldID的整型属性
  32. FieldDefn oFieldID = new FieldDefn("FieldID", FieldType.OFTInteger);
  33. oLayer.CreateField(oFieldID, );
  34.  
  35. // 再创建一个叫FeatureName的字符型属性,字符长度为50
  36. FieldDefn oFieldName = new FieldDefn("FieldName", FieldType.OFTString);
  37. oFieldName.SetWidth();
  38. oLayer.CreateField(oFieldName, );
  39. FeatureDefn oDefn = oLayer.GetLayerDefn();
  40.  
  41. // 创建三角形要素
  42. Feature oFeatureTriangle = new Feature(oDefn);
  43. oFeatureTriangle.SetField(, );
  44. oFeatureTriangle.SetField(, "三角形");
  45. Geometry geomTriangle = Geometry.CreateFromWkt("POLYGON ((0 0,20 0,10 15,0 0))");
  46. oFeatureTriangle.SetGeometry(geomTriangle);
  47. oLayer.CreateFeature(oFeatureTriangle);
  48.  
  49. // 创建矩形要素
  50. Feature oFeatureRectangle = new Feature(oDefn);
  51. oFeatureRectangle.SetField(, );
  52. oFeatureRectangle.SetField(, "矩形");
  53. Geometry geomRectangle = Geometry.CreateFromWkt("POLYGON ((30 0,60 0,60 30,30 30,30 0))");
  54. oFeatureRectangle.SetGeometry(geomRectangle);
  55. oLayer.CreateFeature(oFeatureRectangle);
  56.  
  57. // 创建五角形要素
  58. Feature oFeaturePentagon = new Feature(oDefn);
  59. oFeaturePentagon.SetField(, );
  60. oFeaturePentagon.SetField(, "五角形");
  61. Geometry geomPentagon = Geometry.CreateFromWkt("POLYGON ((70 0,85 0,90 15,80 30,65 15,70 0))");
  62. oFeaturePentagon.SetGeometry(geomPentagon);
  63. oLayer.CreateFeature(oFeaturePentagon);
  64. Console.WriteLine("\n数据集创建完成!\n");
  65. }

通过对象构建

[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. UIImageView的contentMode属性

    UIViewContentMode 都有哪些值: typedef NS_ENUM(NSInteger, UIViewContentMode) { UIViewContentModeScaleToFil ...

  2. 《征服C指针》读书笔记

    本文同时发布在我的个人博客上,欢迎访问~ www.seekingdream.cn 在读完K&R之后,对C的认识就是指针.数组.网上的人们对指针也有些“敬而远之”的感觉.最近从同学处淘得< ...

  3. 关于array.sort(array,array)

    // 基于第一个 System.Array 中的关键字,使用每个关键字的 System.IComparable 实现,对两个一维 System.Array // 对象(一个包含关键字,另一个包含对应的 ...

  4. OGG日常运维监控的自动化脚本模板

    #!/usr/bin/ksh export ORACLE_BASE=/oracle/ export ORACLE_SID=epmln1 export ORACLE_HOSTNAME=pmlnpdb1 ...

  5. wireshark和RawCap跟踪并解决中文乱码问题

    一.问题概述 说下程序的架构. 有个后台管理系统A,在页面修改数据后,会用httpClient发http请求给系统B: 系统B做了异步机制,收到A发的请求后,将数据封装为Mq消息发给RabbitMq, ...

  6. 成员函数指针与高效C++委托 (delegate)

    下载实例源代码 - 18.5 Kb 下载开发包库文件 - 18.6 Kb 概要 很遗憾, C++ 标准中没能提供面向对象的函数指针. 面向对象的函数指针也被称为闭包(closures) 或委托(del ...

  7. Yet another way to manage your NHibernate ISessionFactory

    So here is my current UnitOfWork implementation.  This one makes use of the somewhat new current_ses ...

  8. 【CF887E】Little Brother 二分+几何

    [CF887E]Little Brother 题意:给你n个圆和一条线段,保证圆和圆.圆和线段所在直线不相交,不相切,不包含.求一个过线段两端点的圆,满足不和任何圆相交(可以相切.包含).问圆的最小半 ...

  9. 8.31前端 jQuery

    2018-8-31 19:52:09 周末吧这几天课看完 结束前端!然后进行Django!!! 越努力,越幸运! day56 2018-03-16 1. 内容回顾 1. 样式操作 1. 操作class ...

  10. nginx中location、rewrite用法总结

    一.location用法总结 location可以把不同方式的请求,定位到不同的处理方式上. 1.location的用法 location ~* /js/.*/\.js 以 = 开头,表示精确匹配:如 ...