public void AddPolygonByWrite(AxMapControl axMapControl1, IFeatureLayer l, double x, double y) { ESRI.ArcGIS.Geometry.esriGeometryType featype = l.FeatureClass.ShapeType; if (featype == esriGeometryType.esriGeometryPolygon)//判断层是否为线层 { //IFeatureLayer l = MapCtr.Map.get_Layer(0) as IFeatureLayer; IFeatureClass fc = l.FeatureClass; IFeatureClassWrite fr = fc as IFeatureClassWrite; IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit; IFeature f; //可选参数的设置 object Missing = Type.Missing; IPoint p = new PointClass(); w.StartEditing(true); w.StartEditOperation(); f = fc.CreateFeature(); //定义一个多义线对象 IRgbColor color = new RgbColor(); // 设置颜色属性 color.Red = 255; color.Transparency = 255; IGeometry iGeom = axMapControl1.TrackPolygon(); AddRegion(axMapControl1, iGeom); f.Shape = iGeom; fr.WriteFeature(f); w.StopEditOperation(); w.StopEditing(true); } }
public void AddPointByWrite(IFeatureLayer l, double x, double y) { ESRI.ArcGIS.Geometry.esriGeometryType featype = l.FeatureClass.ShapeType; if (featype == esriGeometryType.esriGeometryPoint)//判断层是否为点层 { // IFeatureLayer l = MapCtr.Map.get_Layer(0) as IFeatureLayer; IFeatureClass fc = l.FeatureClass; IFeatureClassWrite fr = fc as IFeatureClassWrite; IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit; IFeature f; IPoint p; w.StartEditing(true); w.StartEditOperation(); f = fc.CreateFeature(); p = new PointClass(); p.PutCoords(x, y); f.Shape = p; fr.WriteFeature(f); w.StopEditOperation(); w.StopEditing(true); } }
public void AddPointByStore(AxMapControl axMapControl1, IFeatureLayer l, double x, double y) { ESRI.ArcGIS.Geometry.esriGeometryType featype = l.FeatureClass.ShapeType; if (featype == esriGeometryType.esriGeometryPoint)//判断层是否为点层 { //得到要添加地物的图层 //IFeatureLayer l = MapCtr.Map.get_Layer(0) as IFeatureLayer; //定义一个地物类,把要编辑的图层转化为定义的地物类 IFeatureClass fc = l.FeatureClass; //先定义一个编辑的工作空间,然后把转化为数据集,最后转化为编辑工作空间, IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit; IFeature f; IPoint p; //开始事务操作 w.StartEditing(false); //开始编辑 w.StartEditOperation(); //创建一个地物 f = fc.CreateFeature(); p = new PointClass(); //设置点的坐标 p.PutCoords(x, y); ////确定图形类型 f.Shape = p; //保存地物 f.Store(); //结束编辑 w.StopEditOperation(); //结束事务操作 w.StopEditing(true); AddPoint(axMapControl1, x, y); //UniqueValueRenderFlyr(axMapControl1, l); //axMapControl1.Refresh(); } }
public void AddLineByWrite(AxMapControl axMapControl1, IFeatureLayer l, double x, double y) { ESRI.ArcGIS.Geometry.esriGeometryType featype = l.FeatureClass.ShapeType; if (featype == esriGeometryType.esriGeometryPolyline)//判断层是否为线层 { //IFeatureLayer l = MapCtr.Map.get_Layer(0) as IFeatureLayer; IFeatureClass fc = l.FeatureClass; IFeatureClassWrite fr = fc as IFeatureClassWrite; IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit; IFeature f; //可选参数的设置 object Missing = Type.Missing; IPoint p = new PointClass(); w.StartEditing(true); w.StartEditOperation(); f = fc.CreateFeature(); //定义一个多义线对象 IRgbColor color = new RgbColor(); // 设置颜色属性 color.Red = 255; color.Transparency = 255; //ISimpleLineSymbol PlyLine = new SimpleLineSymbolClass(); //PlyLine.Color = color; //PlyLine.Style = esriSimpleLineStyle.esriSLSInsideFrame; //PlyLine.Width = 1; IGeometry iGeom = axMapControl1.TrackLine(); AddLine(axMapControl1, iGeom); f.Shape = iGeom; fr.WriteFeature(f); w.StopEditOperation(); w.StopEditing(true); } }
public static void map_fields(OSGeo.OGR.Layer ogr_layer, out System.Collections.Hashtable outFieldMap, out ESRI.ArcGIS.Geodatabase.IFields outFields, out ESRI.ArcGIS.Geodatabase.esriDatasetType outDatasetType, out ESRI.ArcGIS.Geometry.esriGeometryType outGeometryType, out int outShapeIndex, out int outOIDFieldIndex, out ISpatialReference outSpatialReference) { outSpatialReference = null; outFields = null; outDatasetType = ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable; // start assuming it is a table outGeometryType = esriGeometryType.esriGeometryNull; //don't know what it is outOIDFieldIndex = -1; outShapeIndex = -1; outFieldMap = new System.Collections.Hashtable(); System.Collections.ArrayList fieldArray = new System.Collections.ArrayList(); OSGeo.OGR.FeatureDefn featDef = ogr_layer.GetLayerDefn(); int fieldsInserted = 0; // OIDs and Geometries can be pseudo fields in GDAL and are thus *may* not included in the OGR FieldDef // To account for that add those first (if they exist) and keep a mapping of fields using // fieldsInserted ////////////////////////////// // // handle oid field pseudo column // ESRI.ArcGIS.Geodatabase.IFieldEdit2 oidFieldEdit = new ESRI.ArcGIS.Geodatabase.FieldClass(); if (ogr_layer.GetFIDColumn().Length > 0) { oidFieldEdit.Name_2 = ogr_layer.GetFIDColumn(); oidFieldEdit.AliasName_2 = ogr_layer.GetFIDColumn(); } else { oidFieldEdit.Name_2 = "FID"; oidFieldEdit.AliasName_2 = "FID"; } oidFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeOID; fieldArray.Add(oidFieldEdit); outOIDFieldIndex = fieldsInserted; fieldsInserted++; ////////////////////////////////////// // // handle (optional) geometry field pseudo column // if (!(ogr_layer.GetGeomType() == OSGeo.OGR.wkbGeometryType.wkbNone || ogr_layer.GetGeomType() == OSGeo.OGR.wkbGeometryType.wkbUnknown)) { ESRI.ArcGIS.Geodatabase.IFieldEdit2 geomFieldEdit = new ESRI.ArcGIS.Geodatabase.FieldClass(); if (ogr_layer.GetGeometryColumn().Length > 0) { geomFieldEdit.Name_2 = ogr_layer.GetGeometryColumn(); geomFieldEdit.AliasName_2 = ogr_layer.GetGeometryColumn(); } else { geomFieldEdit.Name_2 = "Shape"; geomFieldEdit.AliasName_2 = "Shape"; } geomFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry; // add geometry def ESRI.ArcGIS.Geometry.esriGeometryType gdbType; bool hasZ; ogr_geo_type_to_esri_geo_type(ogr_layer.GetGeomType(), out gdbType, out hasZ); ESRI.ArcGIS.Geodatabase.IGeometryDefEdit geomDef = new ESRI.ArcGIS.Geodatabase.GeometryDefClass(); geomDef.GeometryType_2 = gdbType; geomDef.HasM_2 = false; //no M support on OGR geomDef.HasZ_2 = hasZ; geomDef.SpatialReference_2 = outSpatialReference = ogr_utils.get_spatialReference(ogr_layer.GetSpatialRef()); geomFieldEdit.GeometryDef_2 = geomDef; fieldArray.Add(geomFieldEdit); outDatasetType = ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass; // upgrade to featureclass outGeometryType = gdbType; outShapeIndex = fieldsInserted; fieldsInserted++; } int fieldCount = featDef.GetFieldCount(); for (int i = 0; i < fieldCount; i++) { // map OGR field to ArcObjects OSGeo.OGR.FieldDefn fieldDef = featDef.GetFieldDefn(i); ESRI.ArcGIS.Geodatabase.IFieldEdit2 fieldEdit = new ESRI.ArcGIS.Geodatabase.FieldClass(); fieldEdit.Name_2 = fieldDef.GetName(); fieldEdit.AliasName_2 = fieldDef.GetName(); // map type OSGeo.OGR.FieldType ogrFieldType = fieldDef.GetFieldType(); ESRI.ArcGIS.Geodatabase.esriFieldType mappedType; switch (ogrFieldType) { case OSGeo.OGR.FieldType.OFTInteger: mappedType = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeInteger; break; case OSGeo.OGR.FieldType.OFTReal: mappedType = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble; break; case OSGeo.OGR.FieldType.OFTString: mappedType = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString; break; case OSGeo.OGR.FieldType.OFTBinary: mappedType = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeBlob; break; case OSGeo.OGR.FieldType.OFTDateTime: mappedType = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDate; break; default: mappedType = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString; break; } fieldEdit.Type_2 = mappedType; outFieldMap.Add(fieldsInserted, i); fieldArray.Add(fieldEdit); fieldsInserted++; } // Add all the fields from the array to an ESRI fields class object. The reason that we do that // here is that we need to know the count in advance ESRI.ArcGIS.Geodatabase.IFieldsEdit fields = new ESRI.ArcGIS.Geodatabase.FieldsClass(); fields.FieldCount_2 = fieldArray.Count; for (int i = 0; i < fieldArray.Count; i++) { fields.set_Field(i, fieldArray[i] as ESRI.ArcGIS.Geodatabase.IField); } outFields = fields; }