• 大小: 17.51MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-10
  • 语言: C#
  • 标签: GIS  Shape  WKT  C#  ArcGIS  

资源简介

C#开发的ArCGIS格式转换WKT格式,在VS2010下编译调试成功,不需要过多处理直接转换,拿来就用,绝对值得拥有。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Shp2WKT
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string wktString;

        public string WktString
        {
            get { return wktString; }
            set { wktString = value; }
        }

        /// 
        /// 读取Shapefile shp信息
        /// 

        /// Shapefile路径
        /// shp信息
        public string ReadSHP(string path)
        {
            string strMessage = ““;

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

            if (dr == null)
            {
                MessageBox.Show(“文件不能打开,请检查“);
                return ““;
            }

            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 = ““;
            string wkt;
            string strWkt = string.Empty;
            //读取shp文件
            while ((feat = layer.GetNextFeature()) != null)
            {
                OSGeo.OGR.Geometry geometry = feat.GetGeometryRef();
                OSGeo.OGR.wkbGeometryType goetype = geometry.GetGeometryType();
                geometry.ExportToWkt(out wkt);
                strWkt += wkt + “\n“;             
            }

            strMessage += “该文件有:“ + layerCount + “层“;
            strMessage += Environment.NewLine;
            strMessage += “该文件坐标信息为:“ + coordString;
            strMessage += Environment.NewLine;
            strMessage += “几何类型:“ + layer.GetGeomType();//shp的类型
            strMessage += Environment.NewLine;
            strMessage += “该文件共有:“ + layer.GetFeatureCount(0).ToString() + “记录“;
            strMessage += Environment.NewLine;
            strMessage += strWkt;
            return strMessage;
        }

        private void btnSelect_Click(object sender EventArgs e)
        {
            using (OpenFileDialog ofg = new OpenFileDialog())
            {
                ofg.InitialDirectory = Path.GetFullPath(“../../World“);
                ofg.Filter = “Shapefile(*.shp)|*.shp“;
                if (ofg.ShowDialog() == DialogResult.OK)
                {
                    txtInput.Text = ofg.FileName;
                }
            }
        }

        private void btnConvertToWkt_Click(object sender EventArgs e)
        {
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-08-21 18:24  Shp2WKT\
     文件         863  2018-08-21 18:24  Shp2WKT.sln
     文件       32256  2016-05-04 21:15  Shp2WKT.suo
     文件       51200  2018-08-21 18:26  Shp2WKT.v11.suo
     文件         144  2016-05-04 10:10  Shp2WKT\app.config
     目录           0  2018-08-21 18:23  Shp2WKT\bin\
     目录           0  2018-08-21 18:26  Shp2WKT\bin\Debug\
     文件     1826304  2015-11-23 02:50  Shp2WKT\bin\Debug\cairo.dll
     文件     1001472  2015-11-23 02:06  Shp2WKT\bin\Debug\cfitsio.dll
     文件      118272  2015-11-23 04:32  Shp2WKT\bin\Debug\expat.dll
     文件       50688  2015-11-23 01:07  Shp2WKT\bin\Debug\freexl.dll
     文件      110592  2015-11-23 02:19  Shp2WKT\bin\Debug\fribidi.dll
     文件     9694208  2015-11-26 05:27  Shp2WKT\bin\Debug\gdal111.dll
     文件       19456  2015-11-26 05:30  Shp2WKT\bin\Debug\gdalconst_csharp.dll
     文件       12288  2015-11-26 05:30  Shp2WKT\bin\Debug\gdalconst_wrap.dll
     文件       80384  2015-11-26 05:30  Shp2WKT\bin\Debug\gdal_csharp.dll
     文件      110592  2015-11-26 05:30  Shp2WKT\bin\Debug\gdal_wrap.dll
     文件     1018880  2015-11-23 01:04  Shp2WKT\bin\Debug\geos.dll
     文件      228864  2015-11-23 01:04  Shp2WKT\bin\Debug\geos_c.dll
     文件      898048  2015-11-23 01:07  Shp2WKT\bin\Debug\iconv.dll
     文件      288256  2015-11-23 01:43  Shp2WKT\bin\Debug\libcurl.dll
     文件     1158144  2015-11-23 01:34  Shp2WKT\bin\Debug\libeay32.dll
     文件     1026560  2015-11-25 03:30  Shp2WKT\bin\Debug\libecwj2.dll
     文件       38912  2015-11-23 02:10  Shp2WKT\bin\Debug\libfcgi.dll
     文件      350208  2015-11-23 03:35  Shp2WKT\bin\Debug\libkea.dll
     文件     3871232  2015-11-23 03:53  Shp2WKT\bin\Debug\libmysql.dll
     文件      119296  2015-11-23 01:54  Shp2WKT\bin\Debug\libpq.dll
     文件      719872  2015-11-23 02:25  Shp2WKT\bin\Debug\libtiff.dll
     文件     1005056  2015-11-23 02:04  Shp2WKT\bin\Debug\libxml2.dll
     文件     3752960  2014-06-19 19:39  Shp2WKT\bin\Debug\lti_dsdk_9.1.dll
     文件      287232  2014-06-19 19:21  Shp2WKT\bin\Debug\lti_lidar_dsdk_1.1.dll
............此处省略73个文件信息

评论

共有 条评论