C#读取shapefile文件

更新时间:2023-07-29 16:01:02 阅读: 评论:0

C#读取shapefile文件
C#读取shapefile文件
using System;
using System.Collections.Generic;
图表作文模板
using System.Text;
津津乐道的近义词using System.IO;
using System.Data.Odbc;  //add by hand,which is needed when load the layer attribute information
using System.Data.OleDb;学校精神文化
using System.Collections;
using System.Data;
using System.Xml;
namespace CGCL.CGFiles
年轻的教师{
public class CGShapeFileParr
{
public class ESRI_ShxHeader
{
int FileCode; //9994
int[] Unud2 = new int[5];
int FileLength;
int Version; //1000
int ShapeType; // 0- Null shape
// 1- Point
// 3-Arc
督政府// 5-Polygon
// 8-MultiPoint
double XMin;
double YMin;
double XMax;
double YMax;
int[] Unud3 = new int[8];
}
class ESRI_ShapeFile
{
int FileCode; //9994
int[] Unud = new int[5];
int FileLength;
int Version; //1000
int ShapeType; // 0- Null shape
// 1- Point
// 3-Arc
// 5-Polygon
// 8-MultiPoint
double XMin;
double YMin;
double XMax;
double YMax;
int[] Unud1 = new int[8];
}
class ESRI_RecordHeader
{
int RecNumber;
int ContentLength;
}
class ESRI_PointContent
{
int ShapeType;
double X;
double Y;
}
class ESRI_IndexRec//索引文件
{
int Offt;
int ContentLen;
}
class ESRI_ArcContent
{
int ShapeType;
double xmin;
double ymin;
double xmax;
double ymax;
int NumParts;
int NumPoints;
}
class ESRI_PolygonContent
{
int ShapeType;
double xmin;
double ymin;
double xmax;
double ymax;
int NumParts;
int NumPoints;平凡造句
}   
public bool LoadShapeFile(CGDataAdapter.CGLocalGeoDataAdapter adapter)
{
string connectionString;
OdbcConnection connection;少儿故事大全免费听故事大全
OdbcDataAdapter OdbcAdapter;
CGMap.CGGeoLayer geolayer = MasterGeoLayer();         
string shpfilepath = Path();
string shpfilename = FileName();一孔之见是什么意思
string shxfilepath = shpfilepath.Substring(0, shpfilepath.LastIndexOf("\\") + 1) + FileName() + ".shx";
//read out the layer attribute infomation
connectionString = "Dsn=Visual FoxPro Databa;sourcedb=" + shpfilepath + ";sourcetype=DBF;exclusive=No;backgroundfetch=Yes;collate=Machine";
connection = new OdbcConnection(connectionString);
connection.Open();
OdbcAdapter = new OdbcDataAdapter("lect * from " + shpfilename, connectionString);
// Create new DataTable and DataSource objects.
DataSet ds = new DataSet();
OdbcAdapter.Fill(ds);
connection.Clo();
if (geolayer == null) return fal;
try
{
//先读取.shx文件,得到文件的总字节长度
FileStream fs = new FileStream(shxfilepath, FileMode.Open, FileAccess.Read); //文件流形式 
BinaryReader BinaryFile = new BinaryReader(fs);  //二进制读取文件的对象
long BytesSum = fs.Length;  //得到文件的字节总长 
int shapecount = (int)(BytesSum - 100) / 8;  //得以总记录数目         
BinaryFile.Clo();
fs.Clo();
//打开shp文件

本文发布于:2023-07-29 16:01:02,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1100998.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:文件   故事   读取   字节
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图