数加载问题
1加载数库
数库保存Access中数库加载方式两种:通名字通属性加载(许两种AE中实现功种方式)
A通设置属性加载数库
首先通IPropertySet接口 定义连接数库相关属性数库中数库路径例:
IPropertySet Propset new PropertySetClass()
PropsetSetProperty(DATABASE@D\test\Ao\data\sh\Mapdatamdb)
定义完属性设置属性进行开数库操作ArcEngine开发中存IWorkspaceFactory IFeatureWorkspace IFeatureClass IFeatureLayer等常开操作数空间物接口IWorkspaceFactory 创建开工作空间接口抽象接口具体应时应工作空间实例化
IWorkspaceFactory Fact new AccessWorkspaceFactoryClass () 果开SDE 数库 SdeWorkspaceFactoryClass 实例化Fact完成工作空间实例化根边设置属性开应Access 数库开方式:
IFeatureWorkspace Workspace FactOpen( Propset0) as IFeatureWorkspace
开Access 工作空间接事情做什简单找应物类赋相应层通MapControl 控件添加应层然刷新图添加某层代码:
IFeatureClass Fcls WorkspaceOpenFeatureClass(District)找应物类
IFeatureLayer Fly new FeatureLayerClass()建立新图层
FlyFeatureClass Fcls 物赋相应层
MapCtrMapAddLayer (Fly)添加层
MapCtrActiveViewRefresh()刷新图
中District 物类名字MapCtr AE中MapControl 象边通属性设置加载数空间方式SDE 数库SDE 数库加载时会介绍
通设置属性加载Access 数库完整C#代码:
public void AddAccessDBByPro()
{
IPropertySet Propset new PropertySetClass()
PropsetSetProperty(DATABASE@D\test\Ao\data\sh\MapDatamdb )
IWorkspaceFactory Fact new AccessWorkspaceFactoryClass ()
IFeatureWorkspace Workspace FactOpen(Propset0) as IFeatureWorkspace
IFeatureClass Fcls WorkspaceOpenFeatureClass (District)
IFeatureLayer Fly new FeatureLayerClass()
FlyFeatureClass Fcls
MapCtrMapAddLayer(Fly)
MapCtrActiveViewRefresh()
}
B通数库名字加载数库
public void AddAccessDBByName()
{
IworkspaceName pWorkspaceName new WorkspaceNameClass()
pWorkspaceNameWorkspaceFactoryProgID esriDataSourcesGDBAccessWorkspaceFactory
pWorkspaceNamePathName @D\test\Ao\data\sh\MapDatamdb
IName npWorkspaceName as IName
IFeatureWorkspace Workspace nOpen() as IFeatureWorkspace
IFeatureClass Fcls WorkspaceOpenFeatureClass (District)
IFeatureLayer Fly new FeatureLayerClass()
FlyFeatureClass Fcls
MapCtrMapAddLayer(Fly)
MapCtrActiveViewRefresh()
}
首先创建数库工作空间名指定工作空间名ProgID确定开什类型工作空间例开Access数库时面代码
IworkspaceName pWorkspaceName new WorkspaceNameClass()
pWorkspaceNameWorkspaceFactoryProgID esriDataSourcesGDBAccessWorkspaceFactory
pWorkspaceNamePathName @D\test\Ao\data\sh\MapDatamdb
属性WorkspaceFactoryProgID确保工作空间AccessWorkspaceFactory数库时指定开数库路径开数库开工作空间必须IName接口(思考没办法)接着定义IName象工作空间名转换成IName类型赋值IName象然通IName象open方法开相应工作空间代码:
IName npWorkspaceName as IName
IFeatureWorkspace Workspace nOpen() as IFeatureWorkspace
2AE开发编辑功
数编辑问题
1 需解概念
长事务 短事务 编辑空间 抽象类类组件象类
2基添加点线面功
添加点(方法种基思路样少量接口变化)
通FeatureClassCreatFeature函数添加物
public void AddPointByStore()
{
添加物图层
IFeatureLayer lMapCtrMapget_Layer(0) as IFeatureLayer
定义物类编辑图层转化定义物类
IFeatureClass fc lFeatureClass
先定义编辑工作空间然转化数集转化编辑工作空间
IWorkspaceEdit w(fc as IDataset)Workspace as IWorkspaceEdit
IFeature f
IPoint p
开始事务操作
wStartEditing(false)
开始编辑
wStartEditOperation()
for(int i0i<100i++)
{
创建物
ffcCreateFeature()
pnew PointClass()
设置点坐标
pPutCoord(ii)
确定图形类型
fShapep
保存物
fStore()
}
结束编辑
wStopEditOperation()
结束事务操作
wStopEditing(true)
}
二添加线
方法添加点样物类型样已
AE中类库介绍
1 问题:什UI组件?
2 类库介绍
空间拓扑运算
1高级象:点(point)点(multipoint)线(polyline)面(polygon)multipatch等(multipatch:片三维形图中图符号包括点状符号线状符号面状符号体状符号片(MultiPatch)符号等)
2拓扑:空间拓扑描述事然界理象空间位置关系相邻重合连通等素集素类间关系集合参拓扑素类必须素集(具空间参考)样进行拓扑检查精确
3素集拓扑素类参拓扑拓扑中定义规理象空间属性部分目前ESRI提供数存储方式中CoverageGeoDatabase够建立拓扑Shape格式数建立拓扑
4 esriTRTAny———— 拓扑规查询拓扑时候(ESRI提供拓扑关系)
5AE中提供ITopologicalOperator接口拓扑运算ITopologicalOperator接口通已存象做空间拓扑运算产生新集合象ITopologicalOperator接口GIS开发中非常广泛通常GIS系统中缓区分析裁剪图形图形差分操作图形合操作等需接口
Boundary 方法图形象边界Polygon象Boundary组成Polyline象Polyline象Boundary组成顶点Point象Point象Boundary空象
Buffer 集合象缓区分析拓扑操作该方法高级象产生缓区PolygonPolylinePoint缓区具面积象
Clip 象进行裁剪空间拓扑操作Clip方法Envelope象象进行裁剪结果象Envelope象包围部分
ConstructUion枚举象单象合单象
ConvexHull 构建象凸边形ConvexHull方法产生图形边框凸边形(没凹面包含图形边形)
Cut 切割象支持GeometryBags象指定条切割曲线图形切割运算图形分左右两部分左右两部分相曲线方言点点分割PolylinePolygon切割曲线相交时执行Cut方法
Difference 图形中减图形相交部分产生两象差集
Intersection方法两纬度象交集部分
Simplify象拓扑致
SymmetricDifference称差分两图形集部分减两图形交集部分
开发实例
鹰眼功实现:
分析:鹰眼图操作动作控件中移动幅图时候控件中图发生变化控件中重新加载幅图时候外控件图发生相应变化时鸟瞰控件中加入红色边框注意实面填充颜色透明已通分析知道添加两MapControl控件名字分axMapControl1axMapControl2中axMapControl1图axMapControl2鸟瞰图
方法:步骤:名称axMapControl1MapControl控件需axMapControl1OnExtentUpdatedOnMapReplaced中分添加代码:
private void axMapControl1_OnExtentUpdated(object sender IMapControlEvents2_OnExtentUpdatedEvent e)
{
新范围
IEnvelope pEnvelope (IEnvelope)enewEnvelope
IGraphicsContainer pGraphicsContainer axMapControl2Map as IGraphicsContainer
IActiveView pActiveView pGraphicsContainer as IActiveView
绘制前清axMapControl2中图形元素
pGraphicsContainerDeleteAllElements()
IRectangleElement pRectangleEle new RectangleElementClass()
IElement pElement pRectangleEle as IElement
pElementGeometry pEnvelope
设置鹰眼图中红线框
IRgbColor pColor new RgbColorClass()
pColorRed 255
pColorGreen 0
pColorBlue 0
pColorTransparency 255
产生线符号象
ILineSymbol pOutline new SimpleLineSymbolClass()
pOutlineWidth 3
属性
IFillSymbol pFillSymbol new SimpleFillSymbolClass()
pFillSymbolColor pColor
pFillSymbolOutline pOutline
IFillShapeElement pFillShapeEle pElement as IFillShapeElement
pFillShapeEleSymbol pFillSymbol
pGraphicsContainerAddElement((IElement)pFillShapeEle 0)
pActiveViewPartialRefresh(esriViewDrawPhaseesriViewGraphics null null)
}
private void axMapControl1_OnMapReplaced(object sender IMapControlEvents2_OnMapReplacedEvent e)
{
if (axMapControl1LayerCount > 0)
{
axMapControl2Map new MapClass()
for (int i 0 i < axMapControl1MapLayerCount 1 i++)
{
axMapControl2AddLayer(axMapControl1get_Layer(i))
}
axMapControl2Extent axMapControl1Extent
axMapControl2Refresh()
}
}
步骤二:名称axMapControl2MapControl控件需axMapControl2OnMouseMoveOnMouseDown中分添加代码:
private void axMapControl2_OnMouseMove(object sender IMapControlEvents2_OnMouseMoveEvent e)
{
if (ebutton 1)
{
IPoint pPoint new PointClass()
pPointPutCoords(emapX emapY)
axMapControl1CenterAt(pPoint)
axMapControl1ActiveViewPartialRefresh(esriViewDrawPhaseesriViewGeography null null)
}
}
private void axMapControl2_OnMouseDown(object sender IMapControlEvents2_OnMouseDownEvent e)
{
if (axMapControl2MapLayerCount > 0)
{
if (ebutton 1)
{
IPoint pPoint new PointClass()
pPointPutCoords(emapX emapY)
axMapControl1CenterAt(pPoint)
axMapControl1ActiveViewPartialRefresh(esriViewDrawPhaseesriViewGeography null null)
}
else if (ebutton 2)
{
IEnvelope pEnv axMapControl2TrackRectangle()
axMapControl1Extent pEnv
axMapControl1ActiveViewPartialRefresh(esriViewDrawPhaseesriViewGeography null null)
}
}
}
二 显示属性表信息
知道ArcMap中Table of Contents功图:
ArcGIS Engine提供TOCControl控件没提供需开发里做显示属性表功
分析:显示某图层属性表首先图层选中然外Form中选中图层属性信息进行显示
方法:添加文菜单添加新Form窗体新窗体添加GridView控件TOCControl控件OnMouseDown事件添加代码(pGlobalFeatureLayer定义全局变量):
private void axTOCControl1_OnMouseDown(object sender ESRIArcGISControlsITOCControlEvents_OnMouseDownEvent e)
{
if (axMapControl1LayerCount > 0)
{
esriTOCControlItem pItem new esriTOCControlItem()
pGlobalFeatureLayer new FeatureLayerClass()
IBasicMap pBasicMap new MapClass()
object pOther new object()
object pIndex new object()
axTOCControl1HitTest(ex ey ref pItem ref pBasicMap ref pGlobalFeatureLayer ref pOther ref pIndex)
}
if (ebutton 2)
{
contextShow(axTOCControl1 ex ey)
}
}
文菜单开属性表Click事件中添加代码:
private void 开属性表ToolStripMenuItem_Click(object sender EventArgs e)
{
FormTable Ft new FormTable(pGlobalFeatureLayer as IFeatureLayer)
FtShow()
}
新窗体中添加属性表显示GridView控件中函数:
public void Itable2Dtable()
{
IFields pFields
pFields pFeatureLayerFeatureClassFields
dtGridViewColumnCount pFieldsFieldCount
for (int i 0 i < pFieldsFieldCounti++ )
{
string fldName pFieldsget_Field(i)Name
dtGridViewColumns[i]Name fldName
dtGridViewColumns[i]ValueType SystemTypeGetType(ParseFieldType(pFieldsget_Field(i)Type))
}
IFeatureCursor pFeatureCursor
pFeatureCursor pFeatureLayerFeatureClassSearch(null false)
IFeature pFeature
pFeature pFeatureCursorNextFeature()
while (pFeature null)
{
string[] fldValue new string[pFieldsFieldCount]
for (int i 0 i < pFieldsFieldCount i++)
{
string fldName
fldName pFieldsget_Field(i)Name
if (fldNamepFeatureLayer FeatureClass ShapeFieldName)
{
fldValue[i] ConvertToString(pFeatureShapeGeometryType)
}
else
fldValue[i] ConvertToString(pFeatureget_Value(i))
}
dtGridViewRowsAdd(fldValue)
pFeature pFeatureCursorNextFeature()
}
}
数库知识:
DB2InformixPostgreSQL
数库开方式方法:
1 开数库:
public IWorkspace GetMDBWorkspace(String _pGDBName)
{
IWorkspaceFactory pWsFac new AccessWorkspaceFactoryClass()
IWorkspace pWs pWsFacOpenFromFile(_pGDBName0)
return pWs
}
2 开文件数库:
public IWorkspace GetFGDBWorkspace(String _pGDBName)
{
IWorkspaceFactory pWsFac new FileGDBWorkspaceFactoryClass()
IWorkspace pWs pWsFacOpenFromFile(_pGDBName 0)
return pWs
}
3 开SDE数库:
开SDE数库Open方法方法IPropertySet象设置开SDE数库获取SDE数库服务器址数库实例数库户密码等参数IPropertySetKeyValue象帮组设置然传Open方法中
public IWorkspace GetSDEWorkspace(String _pServerIP String _pInstance String _pUser String _pPassword String _pDatabase String _pVersion)
{
ESRIArcGISesriSystemIPropertySet pPropertySet new ESRIArcGISesriSystemPropertySetClass()
pPropertySetSetProperty(SERVER _pServerIP)
pPropertySetSetProperty(INSTANCE _pInstance)
pPropertySetSetProperty(DATABASE _pDatabase)
pPropertySetSetProperty(USER _pUser)
pPropertySetSetProperty(PASSWORD _pPassword)
pPropertySetSetProperty(VERSION _pVersion)
ESRIArcGISGeodatabaseIWorkspaceFactory2 workspaceFactory
workspaceFactory (ESRIArcGISGeodatabaseIWorkspaceFactory2)new ESRIArcGISDataSourcesGDBSdeWorkspaceFactoryClass()
return workspaceFactoryOpen(pPropertySet 0)
}
注意开SDE数库需ArcGIS Engine运行时企业级许(时License需特设置——ArcEngineLisence应企业数库类型From1_Load事件中初始化lisencelisence控件设置否提示没许lisence)
具体解决代码:
private void From1_Load(object senderEventArg e)
{
IAoInitialize paonew AoInitializeClass()
paoInitialize(esriLisenceProductCodeesriLisenceProductCodeEngineGeoDB)
}
442 获取数库中素类
ArcGIS Engine中某类首获取工作空间然进入工作空间相应东西两步骤:
l 获取工作空间
l 获取相应素类
定义函数获取数库路径
public string WsPath()
{
string WsFileName
OpenFileDialog OpenFile new OpenFileDialog()
OpenFileFilter 数库(MDB)|*mdb
DialogResult DialogR OpenFileShowDialog()
if (DialogR DialogResultCancel)
{
}
else
{
WsFileName OpenFileFileName
}
return WsFileName
}
获取素类首先获取工作空间然工作空间中素类进行遍历代码:
private void button2_Click(object sender EventArgs e)
{
string WsName WsPath()
if (WsName )
{
IWorkspaceFactory pWsFt new AccessWorkspaceFactoryClass()
IWorkspace pWs pWsFtOpenFromFile(WsName 0)
IEnumDataset pEDataset pWsget_Datasets(esriDatasetTypeesriDTAny)
IDataset pDataset pEDatasetNext()
while (pDataset null)
{
if (pDatasetType esriDatasetTypeesriDTFeatureClass)
{
FeatureClassBoxItemsAdd(pDatasetName)
}
果数集
else if (pDatasetType esriDatasetTypeesriDTFeatureDataset)
{
IEnumDataset pESubDataset pDatasetSubsets
IDataset pSubDataset pESubDatasetNext()
while (pSubDataset null)
{
FeatureClassBoxItemsAdd(pSubDatasetName) 里???
pSubDataset pESubDatasetNext()
}
}
pDataset pEDatasetNext()
}
}
FeatureClassBoxText FeatureClassBoxItems[0]ToString()
}
判断素否编辑:
ArcGIS Engine 提供IDatasetEdit接口判断数否处编辑状态该接口方法:
示例代码:
public bool ISEdit (IFeatureClass pFeatureClass)
{
IDatasetEdit pDataEdit pFeatureClass as IDatasetEdit
return pDataEditIsBeingEdited()
}
删素类:
IFeatureWorkspace接口理基矢量数表素类素数集等
想删素类必须先开名称PointTest素类需OpenFeatureClass中传入素类名称代码:
IWorkspaceFactory pWsFt new AccessWorkspaceFactoryClass()
IWorkspace pWs pWsFtOpenFromFile(WsName 0)
IFeatureWorkspace pFWs pWs as IFeatureWorkspace
IFeatureClass pFClass pFWsOpenFeatureClass(PointTest)
果ArcMap中会切换Catalog中然进入相应数库然删相应素类种操作会想FeatureClas象会提供删方法实然删方法定义Dataset象中
private void button1_Click(object sender EventArgs e)
{
string WsName WsPath()
if( WsName )
{
IWorkspaceFactory pWsFt new AccessWorkspaceFactoryClass()
IWorkspace pWs pWsFtOpenFromFile(WsName 0)
IFeatureWorkspace pFWs pWs as IFeatureWorkspace
IFeatureClass pFClass pFWsOpenFeatureClass(PointTest)
IDataset pDatset pFClass as IDataset
pDatsetDelete()
}
}
删前:
删:
创建素类
创建素类IFeatureWorkspaceCreateFeatureClass方法
需接口:IFieldIFieldEditIFieldsIFieldsEditIGeometryDefIGeometryDefEdit接口
(注意 NET中会遇_2结尾属性属性写)
定义字段类型点类型
ISpatialReference pSpatialReference axMapControl1ActiveViewFocusMapSpatialReference
IGeometryDefEdit pGeoDef new GeometryDefClass()
IGeometryDefEdit pGeoDefEdit pGeoDef as IGeometryDefEdit
pGeoDefEditGeometryType_2 esriGeometryTypeesriGeometryPoint
pGeoDefEditSpatialReference_2 pSpatialReference
定义字段集合象
IFields pFields new FieldsClass()
IFieldsEdit pFieldsEdit (IFieldsEdit)pFields
定义单字段
IField pField new FieldClass()
IFieldEdit pFieldEdit (IFieldEdit)pField
pFieldEditName_2 SHAPE
pFieldEditType_2 esriFieldTypeesriFieldTypeGeometry
pFieldsEditAddField(pField)
pFieldEditGeometryDef_2 pGeoDef
定义单字段添加字段集合中
pField new FieldClass()
pFieldEdit (IFieldEdit)pField
pFieldEditName_2 STCD
pFieldEditType_2 esriFieldTypeesriFieldTypeString
pFieldsEditAddField(pField)
定义单字段添加字段集合中
pField new FieldClass()
pFieldEdit (IFieldEdit)pField
pFieldEditName_2 SLM10
pFieldEditType_2 esriFieldTypeesriFieldTypeString
pFieldsEditAddField(pField)
定义单字段添加字段集合中
pField new FieldClass()
pFieldEdit (IFieldEdit)pField
pFieldEditName_2 SLM20
pFieldEditType_2 esriFieldTypeesriFieldTypeString
pFieldsEditAddField(pField)
定义单字段添加字段集合中
pField new FieldClass()
pFieldEdit (IFieldEdit)pField
pFieldEditName_2 SLM40
pFieldEditType_2 esriFieldTypeesriFieldTypeString
pFieldsEditAddField(pField)
IWorkspaceFactory pFtWsFct new AccessWorkspaceFactory()
IFeatureWorkspace pWs pFtWsFctOpenFromFile(@E\arcgis\Engine\smdb 0) as IFeatureWorkspace
IFeatureClass pFtClass pWsCreateFeatureClass(Test pFields null null esriFeatureTypeesriFTSimple SHAPE null)——————
改变字段名?
public void ChangeFieldAliasName(ITable pTable string pOriFieldName string pDesFieldName)
{
IClassSchemaEdit pClassSchemaEdit (IClassSchemaEdit)pTable
象加锁
ISchemaLock pSchemaLock (ISchemaLock)pTable
pSchemaLockChangeSchemaLock(esriSchemaLockesriExclusiveSchemaLock)
if (pTableFindField(pOriFieldName) 1)
{
pClassSchemaEditAlterFieldAliasName(pOriFieldName pDesFieldName)
pSchemaLockChangeSchemaLock(esriSchemaLockesriSharedSchemaLock)
IFeatureSelection接口高亮显示
介绍IMap接口节IMapIMapSelectFeature方法实现查询素高亮显示现IFeatureSelection接口实现查询高亮显示
IMap pMap axMapControl1Map
IFeatureLayer pFeaturelayer GetLayer(pMap Roads) as IFeatureLayer
IFeatureSelection pFeatureSelection pFeaturelayer as IFeatureSelection
IQueryFilter pQuery new QueryFilterClass()
pQueryWhereClause TYPE +'paved'
pFeatureSelectionSelectFeatures(pQueryesriSelectionResultEnumesriSelectionResultNewfalse)
axMapControl1ActiveViewRefresh()
中GetLayer函数写根图层名称获取图层方法代码
private ILayer GetLayer(IMap pMap string LayerName)
{
IEnumLayer pEnunLayer
pEnunLayer pMapget_Layers(null false)
pEnunLayerReset()
ILayer pRetureLayer
pRetureLayer pEnunLayerNext()
while (pRetureLayer null)
{
if (pRetureLayerName LayerName)
{
break
}
pRetureLayer pEnunLayerNext()
}
return pRetureLayer
}
提问:三种方式区里?
axMapControl1Refresh(esriViewDrawPhaseesriViewGeoSelection null null)
axMapControl1ActiveViewRefresh()
axMapControl1Refresh()
创建符合求表:
public ITable CreateTable(string _TablePath string _TableName)
{
IWorkspaceFactory pWks new ShapefileWorkspaceFactoryClass()
IFeatureWorkspace pFwk pWksOpenFromFile(_TablePath 0) as IFeatureWorkspace
记录面中ID
IField pFieldID new FieldClass()
IFieldEdit pFieldIID pFieldID as IFieldEdit
pFieldIIDType_2 esriFieldTypeesriFieldTypeInteger
pFieldIIDName_2 面ID
记录数
IField pFieldCount new FieldClass()
IFieldEdit pFieldICount pFieldCount as IFieldEdit
pFieldICountType_2 esriFieldTypeesriFieldTypeInteger
pFieldICountName_2 数
添加表中必字段
ESRIArcGISGeodatabaseIObjectClassDescription objectClassDescription new ESRIArcGISGeodatabaseObjectClassDescriptionClass()
IFields pTableFields objectClassDescriptionRequiredFields
IFieldsEdit pTableFieldsEdit pTableFields as IFieldsEdit
pTableFieldsEditAddField(pFieldID)
pTableFieldsEditAddField(pFieldCount)
ITable pTable pFwkCreateTable(_TableName pTableFields null null )
return pTable
}
统计需数:
第参数面数第二参数点数第三输出表
public void StatisticPointCount(IFeatureClass _pPolygonFClass IFeatureClass _pPointFClass ITable _pTable)
{
IFeatureCursor pPolyCursor _pPolygonFClassSearch(null false)
IFeature pPolyFeature pPolyCursorNextFeature()
while (pPolyFeature null)
{
IGeometry pPolGeo pPolyFeatureShape
int Count 0
ISpatialFilter spatialFilter new SpatialFilterClass()
spatialFilterGeometry pPolGeo
spatialFilterSpatialRel esriSpatialRelEnumesriSpatialRelContains
IFeatureCursor pPointCur _pPointFClassSearch(spatialFilter false)
if (pPointCur null)
{
IFeature pPointFeature pPointCurNextFeature()
while (pPointFeature null)
{
pPointFeature pPointCurNextFeature()
Count++
}
}
if (Count 0)
{
IRow pRow _pTableCreateRow()
pRowset_Value(1 pPolyFeatureget_Value(0))
pRowset_Value(2 Count)
pRowStore()
}
pPolyFeature pPolyCursorNextFeature()
}
}
效果:
面例子空间滤没属性滤面代码稍微改动加句代码
结果:
查询图层快速浏览
步骤执行QueryLayer
1) 获取SqlWorkspaceFactory
2) 获取SqlWorkspace
3) 构造查询语句
4) 执行查询
5) 获取结果
public IFeatureLayer OracleQueryLayer()
{
创建SqlWorkspaceFactory象
Type pFactoryType TypeGetTypeFromProgID(esriDataSourcesGDBSqlWorkspaceFactory)
IWorkspaceFactory pWorkspaceFactory (IWorkspaceFactory)ActivatorCreateInstance(pFactoryType)
构造连接数库参数
IPropertySet pConnectionProps new PropertySetClass()
pConnectionPropsSetProperty(dbclient Oracle11g)
pConnectionPropsSetProperty(serverinstance esri)
pConnectionPropsSetProperty(authentication_mode DBMS)
pConnectionPropsSetProperty(user scott)
pConnectionPropsSetProperty(password arcgis)
开工作空间
IWorkspace workspace pWorkspaceFactoryOpen(pConnectionProps 0)
ISqlWorkspace pSQLWorkspace workspace as ISqlWorkspace
获取数库中表名称
IStringArray pStringArray pSQLWorkspaceGetTables()
for (int i 0 i < pStringArrayCount i++)
{
MessageBoxShow(pStringArrayget_Element(i))
}
构造滤条件 SELECT * FROM PointQueryLayer
IQueryDescription queryDescription pSQLWorkspaceGetQueryDescription(SELECT * FROM PointQueryLayer)
ITable pTable pSQLWorkspaceOpenQueryClass(QueryLayerTest queryDescription)
IFeatureLayer pFeatureLayer new FeatureLayerClass()
pFeatureLayerFeatureClass pTable as IFeatureClass
return pFeatureLayer
}
点象:
Point0维图形具XY坐标值选属性:高程值(Z值)度量值(M值) M属性线性参考动态分段中常ID号点象描述精确定位象时点象ZM两选属性代码演示创建Point象
获取点
private IPoint ConstructPoint(double x double y)
{
IPoint pPoint new PointClass()
pPointPutCoords(x y)
return pPoint
}
MultiPoint象系列序点群集点具相属性信息例点集表示整城市天然气调压站图示:Multipoint象8Point象组成
代码片段演示构建Multipoint象
private object pMissing TypeMissing
public IGeometry GetMultipointGeometry()
{
const double MultipointPointCount 25
IPointCollection pPointCollection new MultipointClass()
for (int i 0 i < MultipointPointCount i++)
{
pPointCollectionAddPoint(GetPoint() ref pMissing ref pMissing)
}
return pPointCollection as IGeometry
}
private IPoint GetPoint()
{
const double Min 10
const double Max 10
Random pRandom new Random()
double x Min + (Max Min) * pRandomNextDouble()
double y Min + (Max Min) * pRandomNextDouble()
return ConstructPoint(x y)
}
Segment象
Segment象起点终点线说Segement两点两点间线直曲需余参数定义Segment起点终点参数三方面决定Segment4子类4子类(直线圆弧椭圆弧贝赛尔曲线)
ISegment两方法图:
两方法该Segment进行分割成Segement
Path象
Path连续Segment集合路径第SegmentSegment外余Segment起始点前Segment终止点Path象中Segment出现分离Path意数Segment子类组合
该Path象常方法滑曲线曲线抽稀等操作
Ring象
Ring封闭Path起始终止点相坐标值部外部属性
Polyline象
Polyline象相连者相连path象序集合通常代表线状物道路河流线等等该象ArcGIS Engine中模型图:
意味着户必须种层次构造polyline实际Point集合直接构成Polyline组成Polyline路径连续连续
Polyline序path组成集合拥MZID属性值Polyline象IPointCollection接口包含节点信息IGeometryCollection接口获取polylinepathsISegmentCollection接口获取 polylinesegments
Polyline象必须满足准:
1组成Polyline象Path象必须效
2组成Polyline象Path象重合相交相交
3组成Polyline象Path象连接某点分离
4Path象长度0
IPolylinePolyline类接口IPolylineReshape方法Path象Polyline象整形IPolylineSimplifyNetwork方法简化网络
Polyline象IGeometryCollection接口添加Path象方法创建该接口需注意情况:
1Path象必须效IPathSimplify方法效
2PolylinePath象序集合添加Path象时必须注意序方
3保证Polyline效创建完Polyline象ITopologicalOperator接口Simplify方法
面代码片段演示Polyline构成:
private object pMissing TypeMissing
public IGeometry GetPolylineGeometry()
{
const double PathCount 3
const double PathVertexCount 3
IGeometryCollection pGeometryCollection new PolylineClass()
for (int i 0 i < PathCount i++)
{
IPointCollection pPointCollection new PathClass()
for (int j 0 j < PathVertexCount j++)
{
pPointCollectionAddPoint(GetPoint() ref pMissing ref pMissing)
}
pGeometryCollectionAddGeometry(pPointCollection as IGeometry ref pMissing ref pMissing)
}
return pGeometryCollection as IGeometry
}
private IPoint GetPoint()
{
const double Min 10
const double Max 10
Random random new Random()
double x Min + (Max Min) * randomNextDouble()
double y Min + (Max Min) * randomNextDouble()
return ConstructPoint(x y)
}
SegmentPathRingPolyline区
四者中Segment单位具体构成路线分两条:
SegmentPathRing(封闭Path)
SegmentPathPolyline
样说SegmentPathPathSegment组成Ring种Path起点终点重合PathPolyline明显区图出:
Polygon象
Polylgon象Ring象序集合单Ring 象构成Ring组成Polygon通常代表面积边形矢量象行政区建筑物等Polygon组成结构图:
图出 PolygonRings构成RingSegment构成意味着户必须种层次构造Polygon实际Point集合构成Polygon
通点构造面
public IPolygon CreatePolygonByPoints(IPointCollection pPointCollection)
{
IGeometryBridge2 pGeometryBridge2 new GeometryEnvironmentClass()
IPointCollection4 pPolygon new PolygonClass()
WKSPoint[] pWKSPoint new WKSPoint[pPointCollectionPointCount]
for (int i 0 i < pPointCollectionPointCount i++)
{
pWKSPoint[i]X pPointCollectionget_Point(i)X
pWKSPoint[i]Y pPointCollectionget_Point(i)Y
}
pGeometryBridge2SetWKSPoints(pPolygon ref pWKSPoint)
IPolygon pPoly pPolygon as IPolygon
pPolyclose()
return pPoly
}
组成PolygonRing中Ring分Outer Ring(外环)Inner Ring(环)分外环环方区外环方时针环方逆时针
Polygon象实现接口IArea该接口Poylgon中心重心面积进行访问面片段获取Polygoe面积:
IArea pArea pPolygon as IArea
Double S pArea Area
IGeometryCollection接口
通IGeometryCollection创建Polygon象代码片段:
private IPolygon ConstructorPolygon(List
{
try
{
IGeometryCollection pGCollection new PolygonClass()
object o TypeMissing
for (int i 0 i < pRingListCount i++)
{
通IGeometryCollection接口AddGeometry方法Polygon象中添加Ring子象
pGCollectionAddGeometry(pRingList[i] ref o ref o)
}
QIITopologicalOperator
ITopologicalOperator pTopological pGCollection as ITopologicalOperator
执行Simplify操作
pTopologicalSimplify()
IPolygon pPolygon pGCollection as IPolygon
返回Polygon象
return pPolygon
}
catch (Exception Err)
{
return null
}
}
private IPolygon MergePolygons(IPolygon firstPolygon IPolygon SecondPolygon)
{
try
{
创建Polygon象
IGeometryCollection pGCollection1 new PolygonClass()
IGeometryCollection pGCollection2 firstPolygon as IGeometryCollection
IGeometryCollection pGCollection3 SecondPolygon as IGeometryCollection
添加firstPolygon
pGCollection1AddGeometryCollection(pGCollection2)
添加SecondPolygon
pGCollection1AddGeometryCollection(pGCollection3)
QIITopologicalOperator
ITopologicalOperator pTopological pGCollection1 as ITopologicalOperator
执行Simplify操作
pTopologicalSimplify()
IPolygon pPolygon pGCollection1 as IPolygon
返回Polygon象
return pPolygon
}
catch (Exception Err)
{
return null
}
}
唯值渲染代码:
public UniqueValueRender(AxMapControl pMapcontrol IFeatureLayer pFtLayerint pCount string pFieldName)
{
IGeoFeatureLayer pGeoFeaturelayer pFtLayer as IGeoFeatureLayer
IUniqueValueRenderer pUnique new UniqueValueRendererClass()
pUniqueFieldCount 1
pUniqueset_Field(0 pFieldName)
ISimpleFillSymbol pSimFill new SimpleFillSymbolClass()
颜色
IFeatureCursor pFtCursor pFtLayerFeatureClassSearch(null false)
IFeature pFt pFtCursorNextFeature()
IFillSymbol pFillSymbol1
添加第符号
pFillSymbol1 new SimpleFillSymbolClass()
pFillSymbol1Color GetRGBColor(103 252 179) as IColor
添加第二符号
IFillSymbol pFillSymbol2 new SimpleFillSymbolClass()
pFillSymbol2Color GetRGBColor(125 155 251) as IColor
创建设置机色谱面图出值定义种颜色创建色谱色谱参数
IRandomColorRamp pColorRamp new RandomColorRampClass()
pColorRampStartHue 0
pColorRampMinValue 20
pColorRampMinSaturation 15
pColorRampEndHue 360
pColorRampMaxValue 100
pColorRampMaxSaturation 30
pColorRampSize pCount
pColorRampSize pUniqueValueRendererValueCount
bool ok true
pColorRampCreateRamp(out ok)
IEnumColors pEnumRamp pColorRampColors
IColor pColor pEnumRampNext()
int pIndex pFtFieldsFindField(pFieldName)
24条记录改变会超255者负数求余
int i 0
while (pFt null)
{
IColor pColor pEnumRampNext()
if(pColor null)
{
pEnumRampReset()
pColor pEnumRampNext()
}
注释代码定义两种颜色 果机颜色采样
if (i 2 0)
{
pUniqueAddValue(ConvertToString(pFtget_Value(pIndex)) pFieldName pFillSymbol1 as ISymbol)
}
else
{
pUniqueAddValue(ConvertToString(pFtget_Value(pIndex)) pFieldName pFillSymbol2 as ISymbol)
}
i++
pFillSymbol1 new SimpleFillSymbolClass()
pFillSymbol1Color pColor
pUniqueAddValue(ConvertToString(pFtget_Value(pIndex)) pFieldName pFillSymbol1 as ISymbol)
pFt pFtCursorNextFeature()
pColor pEnumRampNext()
}
pGeoFeaturelayerRenderer pUnique as IFeatureRenderer
pMapcontrolActiveViewPartialRefresh(esriViewDrawPhaseesriViewGeography null null)
}
private IRgbColor GetRGBColor(int R int G int B)子类赋父类
{
IRgbColor pRGB
pRGB new RgbColorClass()
pRGBRed R
pRGBGreen G
pRGBGreen B
return pRGB
}
}
第二部分 AO GIS应开发
1 ArcViewAecEditArcInfo软件名称桌面版GIS种版代码三种版软件系统ArcMapArcCatalogArcScene等单软件组成包含GIS功样中ArcInfo功强
2 GIS服务器通网络发布理信息包括ArcGIS ServerArcIMSArcSDE三种软件ArcGIS Server通常建构企业级互联网GIS应
ArcIMS定制扩展够网络发布理信息网络图发布系统ArcSDE空间数引擎理关系数库实现理数海量存储等高级特性
文档香网(httpswwwxiangdangnet)户传
《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
该内容是文档的文本内容,更好的格式请下载文档