经纬度生成点图层
更新时间:2024-03-17 12:08:01 阅读量: 综合文库 文档下载
经纬度生成点图层
private IFeatureClass CreateShapefile(string folderPath, DatabaseRecordset model,string strFeatureClassName, int GeometryType) {
IWorkspaceFactory pFeatWorkspaceFac = new ShapefileWorkspaceFactory();
IFeatureWorkspace pFeatWorkspace =
pFeatWorkspaceFac.OpenFromFile(folderPath, 0) as IFeatureWorkspace; if (pFeatWorkspace == null) return null; ESRI.ArcGIS.Geodatabase.IField oField = new ESRI.ArcGIS.Geodatabase.FieldClass();
ESRI.ArcGIS.Geodatabase.IFields oFields = new ESRI.ArcGIS.Geodatabase.FieldsClass(); IFieldsEdit oFieldsEdit = null; IFieldEdit oFieldEdit = null;
IFeatureClass oFeatureClass = null; long FCount = model.GetFieldCount(); try {
oFieldsEdit = oFields as ESRI.ArcGIS.Geodatabase.IFieldsEdit; oFieldEdit = oField as ESRI.ArcGIS.Geodatabase.IFieldEdit; oFieldEdit.Name_2 = \
oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; IGeometryDef pGeo = new GeometryDefClass(); IGeometryDefEdit pGeoEdit = (IGeometryDefEdit)pGeo; if (GeometryType == 0) {
pGeoEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; }
else if (GeometryType == 1) {
pGeoEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
} else {
pGeoEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; }
//依据GeometryType创建相应几何类型的要素类
string ProjPath = Application.StartupPath + \\\\\xian1980 gk zone 18.prj\
ISpatialReferenceFactory2 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
ISpatialReference2 spatialReference =
spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(ProjPath) as ISpatialReference2;
pGeoEdit.SpatialReference_2 = spatialReference; //新要素类的空间参考依据投影文件xian1980 gk zone 18.prj pGeoEdit.SpatialReference.SetDomain(-450359962737.05, 450359962737.05, -450359962737.05, 450359962737.05); oFieldEdit.GeometryDef_2 = pGeo; oFieldsEdit.AddField(oField);
oField = new ESRI.ArcGIS.Geodatabase.FieldClass(); oFieldEdit = oField as ESRI.ArcGIS.Geodatabase.IFieldEdit; oFieldEdit.Name_2 = \
oFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; oFieldsEdit.AddField(oField); for (int k = 0; k < FCount; k++) {
oField = new FieldClass(); oFieldEdit = oField as IFieldEdit;
oFieldEdit.Name_2 = model.GetFieldName(k); switch (model.GetFieldType(k)) {
case ADODB.DataTypeEnum.adBigInt: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; break;
case ADODB.DataTypeEnum.adBoolean: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger; break;
case ADODB.DataTypeEnum.adBSTR: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; break;
case ADODB.DataTypeEnum.adChar: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; break;
case ADODB.DataTypeEnum.adCurrency: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; break;
case ADODB.DataTypeEnum.adDate: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate; break;
case ADODB.DataTypeEnum.adDBDate: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate; break;
case ADODB.DataTypeEnum.adDBTime: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate; break;
case ADODB.DataTypeEnum.adDBTimeStamp: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate; break;
case ADODB.DataTypeEnum.adDecimal: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; break;
case ADODB.DataTypeEnum.adDouble: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; break;
case ADODB.DataTypeEnum.adInteger: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; break;
case ADODB.DataTypeEnum.adLongVarChar: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; break; case ADODB.DataTypeEnum.adLongVarWChar: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; break;
case ADODB.DataTypeEnum.adNumeric: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; break;
case ADODB.DataTypeEnum.adSingle: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSingle; break;
case ADODB.DataTypeEnum.adSmallInt: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; break;
case ADODB.DataTypeEnum.adTinyInt: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; break;
case ADODB.DataTypeEnum.adUnsignedBigInt: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; break; case ADODB.DataTypeEnum.adUnsignedInt: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; break; case ADODB.DataTypeEnum.adUnsignedSmallInt: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; break; case ADODB.DataTypeEnum.adUnsignedTinyInt: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; break;
case ADODB.DataTypeEnum.adVarChar: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; break;
case ADODB.DataTypeEnum.adVarWChar: oFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; break; }
//以上实现从ADO的字段类型到ArcGIS的字段类型
oFieldEdit.Length_2 = model.GetFieldPrecision(k); oFieldEdit.Precision_2 = model.GetFieldPrecision(k); oFieldEdit.Scale_2 = model.GetFieldNumericScale(k); oFieldsEdit.AddField(oField); }
//if(File.Exists(folderPath+\\\\\\\ //{
// IFeatureClass fea = pFeatWorkspace.OpenFeatureClass(strFeatureClassName);
// if (fea != null) DeleteSDELayer(fea); // oFeatureClass = null; //}
if (File.Exists(folderPath + \+ strFeatureClassName + \
File.Delete(folderPath + \+ strFeatureClassName + \
if (File.Exists(folderPath + \+ strFeatureClassName + \ File.Delete(folderPath + \+ strFeatureClassName + \
if (File.Exists(folderPath + \+ strFeatureClassName + \ File.Delete(folderPath + \+ strFeatureClassName + \
if (File.Exists(folderPath + \+ strFeatureClassName + \ File.Delete(folderPath + \+ strFeatureClassName + \
if (File.Exists(folderPath + \+ strFeatureClassName + \ File.Delete(folderPath + \+ strFeatureClassName + \
if (File.Exists(folderPath + \+ strFeatureClassName + \ File.Delete(folderPath + \+ strFeatureClassName + \
oFeatureClass = pFeatWorkspace.CreateFeatureClass(strFeatureClassName, oFields, null, null, esriFeatureType.esriFTSimple, \\ }
catch(Exception e) { } finally { try {
System.Runtime.InteropServices.Marshal.ReleaseComObject(oField);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oF
ields);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldsEdit);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldEdit); }
catch { } GC.Collect(); }
return oFeatureClass; }
public bool CreateValidGISStation(string foderPath,string strFeatureClassName)
//该方法实现创建合法站点 {
DatabaseRecordset pRecordset = new DatabaseRecordset(); if (!ConnectToDatabase(pRecordset)) return false;//依据连接参数paras,自动初始化DatabaseRecordset的连接对象
if (!pRecordset.OpenTable(paras.GetValidStationName())) return false;//打开合法站点属性表
IFeatureClass pfc = CreateShapefile(foderPath, pRecordset, strFeatureClassName, 0);
if (pfc == null) return false;
IWorkspaceFactory pFeatWorkspaceFac = new ShapefileWorkspaceFactory();
IFeatureWorkspace pFeatWorkspace = pFeatWorkspaceFac.OpenFromFile(foderPath, 0) as IFeatureWorkspace; if (pFeatWorkspace == null) return false;
int Lon = pRecordset.GetFiledIndex(\经度字段的索引 int Lat = pRecordset.GetFiledIndex(\纬度字段的索引 if (Lon == -1) return false; if (Lat == -1) return false;
IWorkspaceEdit pEdit = (IWorkspaceEdit)pFeatWorkspace; pEdit.StartEditing(false);
long Count = pRecordset.GetRecordCount();//记录数 long FCount = pRecordset.GetFieldCount();//字段数
ISpatialReferenceFactory2 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
ISpatialReference2 FromSp = spatialReferenceFactory.CreateGeographicCoordinateSystem(4610) as ISpatialReference2;
string ProjPath = Application.StartupPath + \\\\\xian1980 gk zone 18.prj\
ISpatialReference2 ToSp = spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(ProjPath) as ISpatialReference2; IPoint pt = new PointClass(); for (long k = 0; k < Count; k++) {
List
object[] os = vs.ToArray(); if (os[Lon] is DBNull) {
pRecordset.MoveNext(); continue; }
if (os[Lat] is DBNull) {
pRecordset.MoveNext(); continue; }
double x = Convert.ToDouble(os[Lon]);//经度 double y = Convert.ToDouble(os[Lat]);//纬度 if (x <= 0 || y <= 0) {
pRecordset.MoveNext(); continue; }
pt.X = x; pt.Y = y;
pt.SpatialReference = FromSp;
pt.Project(ToSp);//转换点的经纬度坐标为西安80坐标系投影坐标
IFeature pFeature = pfc.CreateFeature(); pFeature.Shape = (IGeometry)pt; for (int j = 0; j < FCount; j++) {
//string fName=pFeature.Fields.get_Field(j).Name.ToUpper(); if (os[j] is DBNull) continue;
//MessageBox.Show(Convert.ToString(os[j]));
pFeature.set_Value(j+2 , Convert.ToString(os[j]));//依据合法站点表的字段值为SDE合法站点相应字段赋值
}
pFeature.Store(); pRecordset.MoveNext(); }
pEdit.StopEditing(true); return true; }
正在阅读:
经纬度生成点图层03-17
陪着你慢慢地走11-03
少林五拳04-13
小学生三年级关于我想变成魔术师的作文06-12
25海上气象员11-03
活动策划方案(优秀6篇)03-26
心理学上的四种气质类型07-30
关于校园的美演讲稿08-17
电力技术工作总结(精选多篇)09-28
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 经纬度
- 生成
- 铁路行车组织(二)课程设计
- 辽宁省信用托管行业企业名录145家
- 《规则在我心中》遵守规则主题班会
- 计算机等级C语言上机考试填空题和改错题技巧
- 贵州省安顺市平坝第一高级中学2016-2017学年高二3月月考地理试题
- 走向高考政治一轮复习教师用书:必修1 第7课 doc
- 中国汽车零部件生产行业的市场研究
- 2019年八年级的数学试卷分析-word范文模板(5页)
- 真正的爱是什么
- 苏科版《欧姆定律》教案 - 图文
- 2019七年级上学期语文寒假作业答案(110页)语文
- 华南理工大学2012年免试攻读学术性硕士研究生名单
- 部编语文二年级(上册)期末整理和复习资料全
- 2019村级党支部讲党课讲稿范文精选
- 20XX年社区妇联工作总结范文 - 0
- 续班体系
- 3500英语词汇语境记忆第012期
- 2018-2019学年第一学期九年级物理实验教学计划(附实验安排表)
- 西北师大附小五年级趣味数学试题
- 人教版高中历史必修二知识点总结