資源簡介
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\libxm
?????文件?????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個文件信息
評論
共有 條評論