mrjiou
路人甲
路人甲
  • 注册日期2004-07-03
  • 发帖数78
  • QQ
  • 铜币474枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:5373回复:10

人气太差,传代码!

楼主#
更多 发布于:2006-12-01 13:03
<P>随便写写,实现文本生成Tin(边界控制),生成等值线,切取断面功能,继续写遇到了问题,想做个剔除狭长三角形优化等值线的功能,思路有了,就是得不到FeatureClass的个数,是我的问题还是软件问题?已发有帖子。其实用ArcEngine编程是个享受,接口转来转去,好玩!!!(这是Delphi版本程序)</P>
喜欢0 评分0
mrjiou
路人甲
路人甲
  • 注册日期2004-07-03
  • 发帖数78
  • QQ
  • 铜币474枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2006-12-01 13:06
<P>也,代码呢?怎么发附件啊?这样吧,免的说我骗贴!!</P>
<P>unit Unit1;</P>
<P>interface</P>
<P>uses<BR>  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<BR>  Dialogs, OleCtrls,  ImgList, ActnList, ComCtrls, ToolWin, RzStatus, RzPanel,<BR>  ExtCtrls, RzTabs, RzSplit, esriSystem_TLB, StdCtrls,RzButton,<BR>  esriCarto_TLB, esriGeoDatabase_TLB, esriDataSourcesFile_TLB,<BR>  esriGeometry_TLB, esriSystemUI_TLB, esriDisplay_TLB, esriMapControl_TLB,<BR>  esriTOCControl_TLB, esriToolbarControl_TLB, Math;</P>
<P>type<BR>  TForm1 = class(TForm)<BR>    RzSplitter1: TRzSplitter;<BR>    RzPageControl1: TRzPageControl;<BR>    TabSheet1: TRzTabSheet;<BR>    TabSheet2: TRzTabSheet;<BR>    RzStatusBar1: TRzStatusBar;<BR>    RzStatusPane1: TRzStatusPane;<BR>    CoolBar1: TCoolBar;<BR>    ToolBar1: TToolBar;<BR>    ToolButton1: TToolButton;</P>
<P>    RzProgressStatus1: TRzProgressStatus;<BR>    OpenDialog1: TOpenDialog;<BR>    ActionList1: TActionList;<BR>    ImageList1: TImageList;<BR>    acCreateTinFromFile: TAction;<BR>    Panel1: TPanel;<BR>    ToolButton3: TToolButton;<BR>    ToolButton2: TToolButton;<BR>    ToolButton4: TToolButton;<BR>    ToolButton5: TToolButton;<BR>    procedure FormClose(Sender: TObject; var Action: TCloseAction);<BR>    procedure FormCreate(Sender: TObject);<BR>    procedure acCreateTinFromFileExecute(Sender: TObject);<BR>    procedure ToolButton3Click(Sender: TObject);<BR>    procedure ToolButton2Click(Sender: TObject);<BR>    procedure ToolButton4Click(Sender: TObject);<BR>    procedure ToolButton5Click(Sender: TObject);<BR>  private<BR>    { Private declarations }<BR>  public<BR>    { Public declarations }<BR>    MapControl1: TMapControl;<BR>    TOCControl1: TTOCControl;<BR>    ToolbarControl1: TToolbarControl;<BR>    function CreateTinFromDataFile(DataFile, TinName, TinPath: string;<BR>      MaxEdgeLen: Double; IsEdgeModify: Boolean): ITin;<BR>    procedure ModifyTinEdge(ipTin: ITin;MaxEdgeLen: Double);<BR>  end;</P>
<P>var<BR>  Form1: TForm1;</P>
<P>implementation</P>
<P>uses Unit2, Unit3, Unit4;</P>
<P>{$R *.dfm}</P>
<P>procedure TForm1.FormCreate(Sender: TObject);<BR>var<BR>  pAOInitialize : IAoInitialize;<BR>begin<BR>  pAOInitialize :=IAoInitialize(CoAoInitialize.Create);<BR>  //Set8087CW($133f) ;<BR>  ToolbarControl1:= TToolbarControl.Create(Self);<BR>  ToolbarControl1.Parent:= ToolBar1;<BR>  MapControl1:= TMapControl.Create(Self);<BR>  MapControl1.Parent:= Panel1;<BR>  MapControl1.Align:= alClient;<BR>  TOCControl1:= TTOCControl.Create(Self);<BR>  TOCControl1.Parent:= TabSheet1;<BR>  TOCCOntrol1.Align:= alClient;</P>
<P> ToolbarControl1.AddItem('esriControlTools.ControlsOpenDocCommand', 0, -1, FALSE,0,esriCommandStyleIconOnly);<BR> ToolbarControl1.AddItem('esriControlTools.ControlsSaveAsDocCommand', 0, -1, FALSE,0,esriCommandStyleIconOnly);<BR>  ToolbarControl1.AddItem('esriControlTools.ControlsMapZoomInTool', 0,-1, False,0,esriCommandStyleIconOnly);<BR>  ToolbarControl1.AddItem('esriControlTools.ControlsMapZoomOutTool', 0,-1, False,0,esriCommandStyleIconOnly);<BR>  ToolbarControl1.AddItem('esriControlTools.ControlsMapPanTool', 0,-1, False,0,esriCommandStyleIconOnly);<BR>  ToolbarControl1.AddItem('esriControlTools.ControlsMapFullExtentCommand', 0,-1, False,0,esriCommandStyleIconOnly);<BR>  //ToolbarControl1.AddItem('esriControlTools.ControlsSceneZoomInOutTool', 0,-1, False,0,esriCommandStyleIconOnly);<BR>  ToolbarControl1.AddItem('esriControlTools.ControlsSelectFeaturesTool', 0,-1, False,0,esriCommandStyleIconOnly);</P>
<P>  TOCControl1.SetBuddyControl(MapControl1.DefaultInterface);<BR>  ToolbarControl1.SetBuddyControl(MapControl1.DefaultInterface);<BR>end;</P>
<P>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<BR>var<BR>  P:DWORD;<BR>  H : Integer;<BR>begin<BR>  (CoAoInitialize.Create as IAoInitialize).Shutdown;<BR>  H:=Application.Handle;<BR>  if H<>0 then<BR>  begin<BR>    GetWindowThreadProcessId(H,@P);<BR>    if P=0 then Exit;<BR>    TerminateProcess(OpenProcess(PROCESS_TERMINATE,False,P),$FFFFFFFF);<BR>  end;<BR>end;</P>
<P>function TForm1.CreateTinFromDataFile(DataFile, TinName, TinPath: string;<BR>  MaxEdgeLen: Double; IsEdgeModify: Boolean): ITin;<BR>var<BR>  ipTinEdit: ITinEdit;<BR>  ipEnvelope: IEnvelope;<BR>  pEnvelope: OleVariant;<BR>  List,ListXYZ: TStringList;<BR>  ipPoint: IPoint;<BR>  ipArray: IArray;<BR>  ipUnk: IUnknown;<BR>  I, Count, NodeIndex: Integer;<BR>  XMin, XMax, YMin, YMax: Double;<BR>  IsSuccessful: WordBool;<BR>  ipSpatialReferenceFac: ISpatialReferenceFactory;<BR>  ipProjCoordSystem: IProjectedCoordinateSystem;<BR>begin<BR>  List:= TStringList.Create;<BR>  ListXYZ:= TStringList.Create;<BR>  List.LoadFromFile(DataFile);<BR>  ipArray:= CoArray_.Create as IArray;<BR>  XMin:= 100000000;<BR>  XMax:= -100000000;<BR>  YMin:= 100000000;<BR>  YMax:= -100000000;<BR>  for I:= 0 to List.Count - 1 do<BR>  begin<BR>    if Trim(List.Strings)= '' then Break;<BR>    ListXYZ.DelimitedText:= List.Strings;<BR>    ipPoint:= CoPoint.Create as IPoint;<BR>    if StrToFloat(ListXYZ.Strings[0]) < 1000000 then<BR>      ipPoint.Set_X(StrToFloat(ListXYZ.Strings[0])+41000000)<BR>    else<BR>      ipPoint.Set_X(StrToFloat(ListXYZ.Strings[0]));<BR>    ipPoint.Set_Y(StrToFloat(ListXYZ.Strings[1]));<BR>    ipPoint.Set_Z(StrToFloat(ListXYZ.Strings[2])*-1);<BR>    ipArray.Add(ipPoint as IUnknown);<BR>    if StrToFloat(ListXYZ.Strings[0]) < XMin then XMin:= StrToFloat(ListXYZ.Strings[0]);<BR>    if StrToFloat(ListXYZ.Strings[0]) > XMax then XMax:= StrToFloat(ListXYZ.Strings[0]);<BR>    if StrToFloat(ListXYZ.Strings[1]) < YMin then YMin:= StrToFloat(ListXYZ.Strings[1]);<BR>    if StrToFloat(ListXYZ.Strings[1]) > YMax then YMax:= StrToFloat(ListXYZ.Strings[1]);<BR>  end;<BR>  List.Free;<BR>  ListXYZ.Free;</P>
<P>  ipSpatialReferenceFac:= CoSpatialReferenceEnvironment.Create as ISpatialReferenceFactory;<BR>  ipSpatialReferenceFac.CreateProjectedCoordinateSystem(<BR>    esriSRProjCS_Beijing1954_3_Degree_GK_Zone_41,ipProjCoordSystem);</P>
<P>  ipTinEdit:= CoTin.Create as ITinEdit;<BR>  ipEnvelope:= CoEnvelope.Create as IEnvelope;<BR>  ipEnvelope.Project(ipProjCoordSystem as ISpatialReference);<BR>  ipEnvelope.Set_XMin(XMin);<BR>  ipEnvelope.Set_XMin(XMax);<BR>  ipEnvelope.Set_YMin(YMin);<BR>  ipEnvelope.Set_YMax(YMax);<BR>  ipTinEdit.InitNew(ipEnvelope);<BR>  ipTinEdit.StartEditing(IsSuccessful);<BR>  ipArray.Get_Count(Count);<BR>  for I:= 0 to Count-1 do<BR>  begin<BR>    ipArray.Get_Element(I, ipUnk);<BR>    ipTinEdit.AddPointZ(ipUnk as IPoint, 0, NodeIndex);<BR>  end;<BR>  if IsEdgeModify then<BR>    ModifyTinEdge(ipTinEdit as ITin, MaxEdgeLen);<BR>  ipTinEdit.SaveAs(TinPath+TinName,pEnvelope);<BR>  ipTinEdit.StopEditing(True, IsSuccessful);<BR>  Result:= ipTinEdit as ITin;<BR>end;</P>
<P>procedure TForm1.ModifyTinEdge(ipTin: ITin; MaxEdgeLen: Double);<BR>var<BR>  ipTinEdit: ITinEdit;<BR>  ipTinAdvanced: ITinAdvanced;<BR>  I, EdgeCount, Index, TriCount: LongInt;<BR>  ipTinEdge: ITinEdge;<BR>  EdgeLen: Double;<BR>  ipTriangle: ITinTriangle;<BR>  IsInEditMode, IsSuccessful: WordBool;<BR>  a, b, c, al, be, ga: Double;<BR>begin<BR>  ipTinEdit:= ipTin as ITinEdit;<BR>  ipTinAdvanced:= ipTin as ITinAdvanced;<BR> ipTinAdvanced.Get_EdgeCount(EdgeCount);<BR>  for I:= 1 to EdgeCount do<BR>  begin<BR>    ipTinAdvanced.GetEdge(I, ipTinEdge);<BR>    ipTinEdge.Get_Length(EdgeLen);<BR>    if EdgeLen > MaxEdgeLen then<BR>    begin<BR>      ipTinEdge.Get_LeftTriangle(ipTriangle);<BR>      if ipTriangle <> nil then<BR>      begin<BR>    ipTriangle.Get_Index(Index);<BR>    ipTinEdit.SetTriangleOutsideDataArea(Index);<BR>      end;<BR>      ipTinEdge.Get_RightTriangle(ipTriangle);<BR>      if ipTriangle <> nil then<BR>      begin<BR>    ipTriangle.Get_Index(Index);<BR>    ipTinEdit.SetTriangleOutsideDataArea(Index);<BR>      end;<BR>    end;<BR>  end;</P>
<P>  ipTinAdvanced.Get_TriangleCount(TriCount);<BR>  for I:= TriCount downto 1 do<BR>  begin<BR>    ipTinAdvanced.GetTriangle(I, ipTriangle);<BR>    ipTriangle.Get_Edge(0, ipTinEdge);<BR>    ipTinEdge.Get_Length(a);<BR>    ipTriangle.Get_Edge(1, ipTinEdge);<BR>    ipTinEdge.Get_Length(b);<BR>    ipTriangle.Get_Edge(2, ipTinEdge);<BR>    ipTinEdge.Get_Length(c);<BR>    al := ArcCos((b*b + c*c - a*a)/2/b/c);<BR>    be := ArcCos((a*a + c*c - b*b)/2/a/c);<BR>    ga := pi - al - be;<BR>    if (RadToDeg(al) >= 150) or (RadToDeg(be) >= 150) or (RadToDeg(ga) >= 150) then<BR>      ipTinEdit.SetTriangleOutsideDataArea(I);<BR>  end;<BR>end;</P>
<P><BR>procedure TForm1.acCreateTinFromFileExecute(Sender: TObject);<BR>var<BR>  ipTin: ITin;<BR>  ipTinLayer: ITinLayer;<BR>  ipTinRenderer: ITinRenderer;<BR>  ipTinSingleSymbolRenderer: ITinSingleSymbolRenderer;<BR>  ipSymbol: ISymbol;<BR>  ipSimpleLineSymbol: ISimpleLineSymbol ;<BR>  ipColor: IColor;<BR>begin<BR>  if OpenDialog1.Execute then<BR>  begin<BR>    ipTinLayer:= CoTinLayer.Create as ITinLayer;<BR>    ipTin:= CreateTinFromDataFile(OpenDialog1.FileName, Copy(ExtractFileName(OpenDialog1.FileName), 1 ,Pos('.', ExtractFileName(OpenDialog1.FileName))-1)+'Tin',ExtractFilePath(OpenDialog1.FileName),2500, True);<BR>    ipTinLayer._Set_Dataset(ipTin);<BR>    ipTinLayer.Set_Name('Tin');</P>
<P>    MapControl1.AddLayer(ipTinLayer as ILayer, 0);</P>
<P>    ipTinRenderer:= CoTinEdgeRenderer.Create as ITinRenderer;<BR>    ipTinSingleSymbolRenderer:= ipTinRenderer as ITinSingleSymbolRenderer;<BR>    ipSymbol:= CoSimpleLineSymbol.Create as ISymbol;<BR>    ipSimpleLineSymbol:= ipSymbol as ISimpleLineSymbol;<BR>    ipSimpleLineSymbol.Set_Style(esriSLSSolid);<BR>    ipColor:= CoRgbColor.Create as IColor;<BR>    ipColor.Set_RGB(255);<BR>    ipSimpleLineSymbol.Set_Color(ipColor);<BR>    ipTinSingleSymbolRenderer._Set_Symbol(ipSymbol);</P>
<P>    ipTinLayer.ClearRenderers;<BR>    ipTinLayer.AddRenderer(ipTinRenderer);<BR>  end;<BR>end;</P>
<P>procedure TForm1.ToolButton3Click(Sender: TObject);<BR>var<BR>  ipFeature: IFeature;<BR>  ipGeometry, ipOutGeometry: IGeometry;<BR>  ipCurve: ICurve;<BR>  ipMap: IMap;<BR>  ipSelection: ISelection;<BR>  ipEnumFeature: IEnumFeature;<BR>  ipTinLayer: ITinLayer;<BR>  ipTin: ITin;<BR>  ipTinSurface: ITinSurface;<BR>  StepSize: OleVariant;<BR>  ipPointCollection: IPointCollection;<BR>  I, Count: Integer;<BR>  ipPoint, ipTempPoint: IPoint;<BR>  ipArray: IArray;<BR>  PointArray: array of array of Double;<BR>  ipProximityOperator: IProximityOperator;<BR>  Dis, Z, Max, Min: Double;<BR>begin<BR>  //ipArray:= CoArray_.Create as IArray;<BR>  //获取断面几何对象<BR>  ipMap:= MapControl1.Map;<BR>  ipMap.Get_FeatureSelection(ipSelection);<BR>  ipEnumFeature:= ipSelection as IEnumFeature;<BR>  ipEnumFeature.Reset;<BR>  ipEnumFeature.Next(ipFeature);<BR>  if ipFeature = nil then<BR>  begin<BR>    Showmessage('请选择断面!');<BR>    Exit;<BR>  end;<BR>  ipFeature.Get_Shape(ipGeometry);<BR>  ipCurve:= ipGeometry as ICurve;<BR>  ipCurve.Get_FromPoint(ipPoint);<BR>  //ipArray.Add(ipPoint);<BR>  //获取TinSurface<BR>  ipTinLayer:= MapControl1.Layer[1] as ITinLayer;<BR>  ipTinLayer.Get_Dataset(ipTin);<BR>  ipTinSurface:= ipTin as ITinSurface;<BR>  ipTinSurface.InterpolateShape(ipGeometry,ipOutGeometry, StepSize);<BR>  ipPointCollection:= ipOutGeometry as IPointCollection;<BR>  ipPointCollection.Get_PointCount(Count);<BR>  SetLength(PointArray, Count, 2);<BR>  ipProximityOperator:= ipPoint as IProximityOperator;<BR>  for I:= 0 to Count-1 do<BR>  begin<BR>    ipPointCollection.Get_Point(I, ipTempPoint);<BR>    ipProximityOperator.ReturnDistance(ipTempPoint, Dis);<BR>    PointArray[I,0]:= Round(Dis*100)/100;<BR>    ipTempPoint.Get_Z(Z);<BR>    PointArray[I,1]:= Round(Z*100)/100;<BR>  end;</P>
<P>  Form2:= TForm2.Create(nil);<BR>  Form2.Cell1.OpenFile('G:\A编程区\Delphi\ArcEngine\起点距水深表','');<BR>  Max:= -9999; Min:= 9999;<BR>  for I:= 0 to Count-1 do<BR>  begin<BR>    Form2.Cell1.InsertRow(I+2, 1, 0);<BR>    Form2.Cell1.SetCellDouble(1, I+2, 0, PointArray[I,0]);<BR>    Form2.Cell1.SetCellDouble(2, I+2, 0, PointArray[I,1]*(-1));<BR>    Form2.Series1.AddXY(PointArray[I,0], PointArray[I,1]*(-1));<BR>    Form2.Series2.AddXY(PointArray[I,0], 5);<BR>    if Max < PointArray[I,1]*(-1) then Max:= PointArray[I,1]*(-1);<BR>    if Min > PointArray[I,1]*(-1) then Min:= PointArray[I,1]*(-1);<BR>  end;<BR>  Form2.Chart1.LeftAxis.Minimum:= Min-(Max-Min)*0.3;<BR>  Form2.Chart1.LeftAxis.Maximum:= Max+(Max-Min)*0.3;<BR>  Form2.ShowModal;<BR>  Form2.Free;</P>
<P>end;</P>
<P>procedure TForm1.ToolButton2Click(Sender: TObject);<BR>var<BR>  ipFeature: IFeature;<BR>  ipGeometry: IGeometry;<BR>  ipMap: IMap;<BR>  ipSelection: ISelection;<BR>  ipEnumFeature: IEnumFeature;<BR>  ipTinLayer: ITinLayer;<BR>  ipTin: ITin;<BR>  ipTinEdit: ITinEdit;<BR>  ipTinFeatureEdit: ITinFeatureEdit;<BR>  IsSuccessful: WordBool;<BR>  ipTinSurface: ITinSurface;<BR>  Volume, Area, Depth: Double;<BR>  ipArea: IArea;<BR>  I: Integer;<BR>  ipLayer: ILayer;<BR>  LayerName: WideString;<BR>begin<BR>  ipMap:= MapControl1.Map;<BR>  ipMap.Get_FeatureSelection(ipSelection);<BR>  ipEnumFeature:= ipSelection as IEnumFeature;<BR>  ipEnumFeature.Reset;<BR>  ipEnumFeature.Next(ipFeature);<BR>  if ipFeature = nil then<BR>  begin<BR>    Showmessage('请选择区域!');<BR>    Exit;<BR>  end;<BR>  ipFeature.Get_Shape(ipGeometry);</P>
<P>  Form3:= TForm3.Create(nil);<BR>  Form3.ipGeometry:= ipGeometry;<BR>  for I:= 0 to MapControl1.LayerCount -1 do<BR>  begin<BR>    ipLayer:= MapControl1.Layer;<BR>    ipLayer.QueryInterface(ITinLayer, ipTinLayer);<BR>    if ipTinLayer <> nil then<BR>    begin<BR>      ipTinLayer.Get_Name(LayerName);<BR>      Form3.RzCheckList1.Items.Add(LayerName);<BR>    end;<BR>  end;</P>
<P>  Form3.ShowModal;<BR>  {<BR>  ipTinLayer:= MapControl1.Layer[6] as ITinLayer;<BR>  ipTinLayer.Get_Dataset(ipTin);</P>
<P>  ipTinEdit:= ipTin as ITinEdit;<BR>  //ipTinEdit.StartEditing(IsSuccessful);<BR>  ipTinFeatureEdit:= ipTin as ITinFeatureEdit;<BR>  ipTinFeatureEdit.StartInMemoryEditing(IsSuccessful);<BR>  ipTinEdit.AddShape(ipGeometry,esriTinSoftClip, 0, EmptyParam);<BR>  //ipTinEdit.StopEditing(True, IsSuccessful);</P>
<P>  ipTinSurface:= ipTin as ITinSurface;<BR>  ipTinSurface.GetVolume(-5, 1, Volume);<BR>  ipTinSurface.GetProjectedArea(-5, 1, Area);<BR>  Depth:= Volume/Area+5;<BR>  Showmessage(FloatToStr(Volume));<BR>  Showmessage(FloatToStr(Depth));<BR>  }<BR>end;</P>
<P>procedure TForm1.ToolButton4Click(Sender: TObject);<BR>var<BR>  ipFeature: IFeature;<BR>  ipGeometry: IGeometry;<BR>  ipMap: IMap;<BR>  ipGraphicsLayer: IGraphicsLayer;<BR>  ipGraphicsContainer: IGraphicsContainer;<BR>  ipSelection: ISelection;<BR>  ipEnumFeature: IEnumFeature;<BR>  ipLayer: ILayer;<BR>  ipTinLayer: ITinLayer;<BR>  ipFeatureLayer: IFeatureLayer;<BR>  ipFeatureClass: IFeatureClass;<BR>  ipTin: ITin;<BR>  ipTinAdvanced: ITinAdvanced;<BR>  ipPolygon: IPolygon;<BR>  ipElement: IElement;<BR>  ipFillShapeElement: IFillShapeElement;<BR>  ipFillSymbol: IFillSymbol;<BR>  ipColor: IColor;<BR>  Count: Integer;<BR>  ipTable: ITable;<BR>  ipFeatureCursor: IFeatureCursor;<BR>  ipDataset: IDataset;<BR>  ipWorkspace: IWorkspace;<BR>  ipWorkspaceEdit: IWorkspaceEdit;<BR>  ipSelectionSet: ISelectionSet;<BR>begin<BR>{<BR>  ipMap:= MapControl1.Map;<BR>  ipMap.Get_BasicGraphicsLayer(ipGraphicsLayer);<BR>  ipGraphicsContainer:= ipGraphicsLayer as IGraphicsContainer;</P>
<P><BR>  ipLayer:= MapControl1.Layer[4];<BR>  ipTinLayer:= ipLayer as ITinLayer;<BR>  ipTinLayer.Get_Dataset(ipTin);<BR>  ipTinAdvanced:= ipTin as ITinAdvanced;<BR>  ipTinAdvanced.GetDataArea(ipPolygon);<BR>  ipElement:= CoPolygonElement.Create as IElement;<BR>  ipElement.Set_Geometry(ipPolygon as IGeometry);<BR>  ipFillShapeElement:= ipElement as IFillShapeElement;<BR>  ipFillSymbol:= CoSimpleFillSymbol.Create as IFillSymbol;<BR>  ipColor:= CoRgbColor.Create as IColor;<BR>  ipColor.Set_Transparency(0);<BR>  ipFillSymbol.Set_Color(ipColor);<BR>  ipFillShapeElement.Set_Symbol(ipFillSymbol);<BR>  ipGraphicsContainer.AddElement(ipElement, 0);<BR>  }<BR>  MapControl1.AddShapeFile('H:\','Regin');<BR>  ipLayer:= MapControl1.Layer[0];<BR>  ipFeatureLayer:= ipLayer as IFeatureLayer;</P>
<P>  ipFeatureLayer.Get_FeatureClass(ipFeatureClass);<BR>  //ipFeatureClass.Search(nil, False, ipFeatureCursor);<BR>  //ipFeatureCursor.NextFeature(ipFeature);<BR>  ipFeatureClass.FeatureCount(nil, Count);<BR>  //ipFeatureClass.GetFeature(0, ipFeature);<BR>  //if ipFeature <> nil then<BR>  Showmessage(IntTostr(Count));<BR>  {<BR>  ipDataset:= ipFeatureClass as IDataset;<BR>  ipDataset.Get_Workspace(ipWorkspace);<BR>  ipWorkspaceEdit:= ipWorkspace as IWorkspaceEdit;<BR>  ipWorkspaceEdit.StartEditing(True);<BR>  ipWorkspaceEdit.StartEditOperation;</P>
<P>  ipFeatureClass.Search(nil, False, ipFeatureCursor);<BR>  ipFeatureCursor.NextFeature(ipFeature);<BR>  if ipFeature <> nil then<BR>  begin<BR>  ipFeatureClass.FeatureCount(nil, Count);<BR>  Showmessage(IntTostr(Count));<BR>  end;<BR>  }<BR>end;</P>
<P>procedure TForm1.ToolButton5Click(Sender: TObject);<BR>begin<BR>  Form4:= TForm4.Create(nil);<BR>  Form4.SetMapControl(MapControl1);<BR>  Form4.ShowModal;<BR>  Form4.Free;<BR>end;</P>
<P>end.</P>
举报 回复(0) 喜欢(0)     评分
mrjiou
路人甲
路人甲
  • 注册日期2004-07-03
  • 发帖数78
  • QQ
  • 铜币474枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2006-12-01 13:07
<P>unit Unit3;</P>
<P>interface</P>
<P>uses<BR>  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<BR>  Dialogs, OleCtrls, CELL50Lib_TLB, RzButton, RzRadChk, StdCtrls, RzLstBox,<BR>  RzChkLst, RzPanel, ExtCtrls, RzSplit, esriCarto_TLB, esriGeometry_TLB, esriGeoDatabase_TLB,<BR>  Mask, RzEdit;</P>
<P>type<BR>  TForm3 = class(TForm)<BR>    RzSizePanel1: TRzSizePanel;<BR>    RzPanel1: TRzPanel;<BR>    RzCheckList1: TRzCheckList;<BR>    RzCheckBox1: TRzCheckBox;<BR>    Cell1: TCell;<BR>    RzBitBtn1: TRzBitBtn;<BR>    RzGroupBox1: TRzGroupBox;<BR>    RzEdit1: TRzEdit;<BR>    procedure RzBitBtn1Click(Sender: TObject);<BR>  private<BR>    { Private declarations }<BR>  public<BR>    { Public declarations }<BR>    ipGeometry: IGeometry;<BR>  end;</P>
<P>var<BR>  Form3: TForm3;</P>
<P>implementation</P>
<P>uses Unit1;</P>
<P>{$R *.dfm}</P>
<P>procedure TForm3.RzBitBtn1Click(Sender: TObject);<BR>var<BR>  I, J: Integer;<BR>  LayerName: WideString;<BR>  ipTinLayer: ITinLayer;<BR>  ipLayer: ILayer;<BR>  ipTin: ITin;<BR>  ipTinEdit: ITinEdit;<BR>  ipTinFeatureEdit: ITinFeatureEdit;<BR>  ipTinAdvanced: ITinAdvanced;<BR>  ipPolygon: IPolygon;<BR>  ipInterSection: IGeometry;<BR>  ipTopologicalOperator: ITopologicalOperator;<BR>  IsSuccessful: WordBool;<BR>  ipTinSurface: ITinSurface;<BR>  Volume, Area, Depth: Double;<BR>  Level: Double;<BR>  IsEmpty: WordBool;<BR>begin<BR>  for I:= 0 to Self.RzCheckList1.Count -1 do<BR>  begin<BR>    <BR>    for J:= 0 to Form1.MapControl1.LayerCount-1 do<BR>    begin<BR>      ipLayer:= Form1.MapControl1.Layer[J];<BR>      ipLayer.Get_Name(LayerName);<BR>      if LayerName = RzCheckList1.Items.Strings then<BR>      begin<BR>        ipTinLayer:= ipLayer as ITinLayer;<BR>        ipTinLayer.Get_Dataset(ipTin);<BR>        ipTinAdvanced:= ipTin as ITinAdvanced;<BR>        ipTinAdvanced.GetDataArea(ipPolygon);<BR>        ipTopologicalOperator:= ipPolygon as ITopologicalOperator;<BR>        ipTopologicalOperator.Intersect(ipGeometry, esriGeometry2Dimension, ipInterSection);<BR>        ipInterSection.Get_IsEmpty(IsEmpty);<BR>        if IsEmpty then<BR>        begin<BR>          Cell1.SetCellString(1, I+1, 0, LayerName);<BR>          Cell1.SetCellString(2,I+1, 0, '');<BR>          Cell1.SetCellString(3,I+1, 0, '');<BR>          Continue;<BR>        end;</P>
<P>        ipTinEdit:= ipTin as ITinEdit;<BR>        ipTinFeatureEdit:= ipTin as ITinFeatureEdit;<BR>        ipTinFeatureEdit.StartInMemoryEditing(IsSuccessful);<BR>        ipTinEdit.AddShape(ipGeometry,esriTinSoftClip, 0, EmptyParam);<BR>        Level:= StrToFloat(RzEdit1.Text);<BR>        ipTinSurface:= ipTin as ITinSurface;<BR>        ipTinSurface.GetVolume(Level, 1, Volume);<BR>        ipTinSurface.GetProjectedArea(Level, 1, Area);<BR>        Depth:= Volume/Area-Level;<BR>        Volume:= Round(Volume/100000)/100;<BR>        Depth:= Round(Depth*100)/100;<BR>        Cell1.SetCellString(1, I+1, 0, Copy(LayerName,1, 4)+'-'+Copy(LayerName,5, 2));<BR>        Cell1.SetCellDouble(2,I+1, 0, Volume);<BR>        Cell1.SetCellDouble(3,I+1, 0, Depth);<BR>      end;<BR>    end;<BR>  end;<BR>end;</P>
<P>end.</P>
举报 回复(0) 喜欢(0)     评分
mrjiou
路人甲
路人甲
  • 注册日期2004-07-03
  • 发帖数78
  • QQ
  • 铜币474枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2006-12-01 13:07
<P>unit Unit4;</P>
<P>interface</P>
<P>uses<BR>  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<BR>  Dialogs, esriMapControl_TLB, StdCtrls, RzLstBox, RzCmboBx, esriCarto_TLB,<BR>  esriSystem_TLB, RzButton, esriGeoDatabase_TLB, esriDataSourcesFile_TLB,<BR>  esriGeometry_TLB;</P>
<P>type<BR>  TForm4 = class(TForm)<BR>    RzComboBox1: TRzComboBox;<BR>    RzRankListBox1: TRzRankListBox;<BR>    RzButton1: TRzButton;<BR>    RzButton2: TRzButton;<BR>    RzColorComboBox1: TRzColorComboBox;<BR>    RzBitBtn1: TRzBitBtn;<BR>    RzBitBtn2: TRzBitBtn;<BR>    procedure RzBitBtn1Click(Sender: TObject);<BR>  private<BR>    { Private declarations }<BR>    MapCtrl: TMapControl;<BR>  public<BR>    { Public declarations }<BR>    procedure SetMapControl(AMapCtrl: TMapControl);<BR>    function CreateFeatureClass(outPath: string; lyrName: string): IFeatureClass;<BR>    procedure OptimizeContour(ipFeatureClass: IFeatureClass);<BR>  end;</P>
<P>var<BR>  Form4: TForm4;</P>
<P>implementation</P>
<P><BR>{$R *.dfm}</P>
<P>{ TForm4 }</P>
<P>procedure TForm4.SetMapControl(AMapCtrl: TMapControl);<BR>var<BR>  ipMap: IMap;<BR>  ipEnumLayer: IEnumLayer;<BR>  ipUID: IUID;<BR>  ipLayer: ILayer;<BR>  Str: WideString;<BR>begin<BR>  MapCtrl:= AMapCtrl;<BR>  ipMap:= MapCtrl.Map;<BR>  ipUID:= CoUID.Create;<BR>  ipUID.Value:= '{FE308F36-BDCA-11D1-A523-0000F8774F0F}';<BR>  ipMap.Get_Layers(ipUID, False, ipEnumLayer);<BR>  if ipEnumLayer <> nil then<BR>  begin<BR>    ipEnumLayer.Reset;<BR>    ipEnumLayer.Next(ipLayer);<BR>    ipLayer.Get_Name(Str);<BR>    RzComboBox1.Items.Add(Str);<BR>  end;<BR>  Self.RzRankListBox1.Add('0 m');<BR>  Self.RzRankListBox1.Add('1 m');<BR>end;</P>
<P>procedure TForm4.RzBitBtn1Click(Sender: TObject);<BR>var<BR>  I: Integer;<BR>  ipLayer: ILayer;<BR>  ipTinLayer: ITinLayer;<BR>  Str: WideString;<BR>  ipTin: ITin;<BR>  ipTinSurface: ITinSurface;<BR>  ipDoubleArray: IDoubleArray;<BR>  ipFeatureLayer: IFeatureLayer;<BR>  ipFeatureClass: IFeatureClass;<BR>    Count: Integer;<BR>begin<BR>  for I:= 0 to MapCtrl.LayerCount-1 do<BR>  begin<BR>    ipLayer:= MapCtrl.Layer;<BR>    ipLayer.Get_Name(Str);<BR>    if Str = RzComboBox1.Text then<BR>    begin<BR>      ipTinLayer:= ipLayer as ITinLayer;<BR>      ipTinLayer.Get_Dataset(ipTin);<BR>      ipTinSurface:= ipTin as ITinSurface;<BR>      ipDoubleArray:= CoDoubleArray.Create as IDoubleArray;<BR>      ipDoubleArray.Add(-8.5);<BR>      ipFeatureClass:= CreateFeatureClass('H:\', '8.5');<BR>      ipTinSurface.ContourList(ipDoubleArray, ipFeatureClass,'Elevation' ,1);<BR>      //OptimizeContour(ipFeatureClass);<BR>      ipFeatureLayer:= CoFeatureLayer.Create as IFeatureLayer;<BR>      ipFeatureLayer.Set_Name('8.5');<BR>      ipFeatureLayer._Set_FeatureClass(ipFeatureClass);<BR>      MapCtrl.AddLayer(ipFeatureLayer,1);<BR>      Break;<BR>    end;<BR>  end;<BR>end;</P>
<P>function TForm4.CreateFeatureClass(outPath,<BR>  lyrName: string): IFeatureClass;<BR>var<BR>  ipWorkspaceFactory: IWorkspaceFactory;<BR>  ipWorkspace: IWorkspace ;<BR>  ipFeatureWorkSapce: IFeatureWorkspace;<BR>  ipFields: IFields;<BR>  ipFieldsEdit: IFieldsEdit;<BR>  ipField: IField;<BR>  ipFieldEdit: IFieldEdit;<BR>  ipGeometryDef: IGeometryDef;<BR>  ipGeometryDefEdit: IGeometryDefEdit;<BR>  ipSpatialReference: ISpatialReference;<BR>  ipMap: IMap;<BR>begin<BR>  ipWorkspaceFactory:= CoShapefileWorkspaceFactory.Create as IWorkspaceFactory;<BR>  ipWorkspaceFactory.OpenFromFile(outPath,0,ipWorkspace);<BR>  ipFeatureWorkSapce:= ipWorkspace as IFeatureWorkspace;<BR>  ipFields:= CoFields.Create as IFields;<BR>  ipFieldsEdit:= ipFields as IFieldsEdit;<BR>  ipField:= CoField.Create as IField;<BR>  ipFieldEdit:= ipField as IFieldEdit;<BR>  ipFieldEdit.Set_Name('Shape');<BR>  ipFieldEdit.Set_type_(esriFieldTypeGeometry);<BR>  ipGeometryDef:= CoGeometryDef.Create as IGeometryDef;<BR>  ipGeometryDefEdit:= ipGeometryDef as IGeometryDefEdit;<BR>  ipMap:= MapCtrl.Map;<BR>  ipMap.Get_SpatialReference(ipSpatialReference);<BR>  ipGeometryDefEdit.Set_GeometryType(esriGeometryPolyline);<BR>  ipGeometryDefEdit._Set_SpatialReference(ipSpatialReference);<BR>  ipFieldEdit._Set_GeometryDef(ipGeometryDef);<BR>  ipFieldsEdit.AddField(ipField);<BR>  ipFeatureWorkSapce.CreateFeatureClass(lyrName, ipFields, nil,nil,esriFTSimple,'Shape','',Result);<BR>end;</P>
<P>procedure TForm4.OptimizeContour(ipFeatureClass: IFeatureClass);<BR>var<BR>  ipTable: ITable;<BR>  ipFeatureCursor: IFeatureCursor;<BR>  ipFeature: IFeature;<BR>  ipGeometry: IGeometry;<BR>  ipPolycurve: IPolyCurve;<BR>  ipPolyline4: IPolyline4;<BR>  ipPointCollection: IPointCollection;<BR>  I, Count: Integer;<BR>  Point1, Point2, Point3: IPoint;<BR>  fids: array of LongInt;<BR>  ipClass: IClass;<BR>  ipIIndexes: IIndexes;<BR>begin</P>
<P><BR>  //ipTable:= ipFeatureClass as ITable;<BR>  ipFeatureClass.FeatureCount(nil, Count);<BR>  SetLength(fids, Count);<BR>  for I:= 0 to Count-1 do<BR>    fids:= I;<BR>  ipFeatureClass.GetFeatures(fids, True, ipFeatureCursor);<BR>  ipFeatureCursor.NextFeature(ipFeature);<BR>  ipFeature.Get_Shape(ipGeometry);<BR>  ipPolyline4:= ipGeometry as IPolyline4;<BR>  //ipPointCollection:= ipGeometry as IPointCollection;<BR>  //ipPointCollection.Get_PointCount(Count);<BR>  //for I:= 0 to Count-1 do<BR>  //begin<BR>    //Point1<BR>  //end;<BR>  ipPolyline4.SimplifyEx(True);<BR>  ipFeatureCursor.Flush;<BR>end;</P>
<P>end.</P>
举报 回复(0) 喜欢(0)     评分
hsghxm
路人甲
路人甲
  • 注册日期2004-10-27
  • 发帖数517
  • QQ4604052
  • 铜币1枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2006-12-01 17:09
<img src="images/post/smile/dvbbs/em05.gif" /><img src="images/post/smile/dvbbs/em06.gif" />
MSN:hsghxm@163.com QQ:4604052 (很少用,最好别加) Email:hsghxm@163.com 我的BOLG:http://www.gisempire.com/blog/user1/864/index.htm
举报 回复(0) 喜欢(0)     评分
eagling
路人甲
路人甲
  • 注册日期2004-10-21
  • 发帖数126
  • QQ
  • 铜币540枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2006-12-04 11:15
<P>这么长啊,看了都累啊,</P>
中国GIS的未来,要靠GIS农民创造.
举报 回复(0) 喜欢(0)     评分
spacequake
路人甲
路人甲
  • 注册日期2006-03-13
  • 发帖数7
  • QQ
  • 铜币133枚
  • 威望0点
  • 贡献值0点
  • 银元0个
6楼#
发布于:2007-01-13 21:01
<img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" />
举报 回复(0) 喜欢(0)     评分
wheroy
路人甲
路人甲
  • 注册日期2004-09-04
  • 发帖数159
  • QQ
  • 铜币251枚
  • 威望0点
  • 贡献值0点
  • 银元0个
7楼#
发布于:2007-01-21 23:55
FeatureClass的个数要用检索
举报 回复(0) 喜欢(0)     评分
whmwxhanshan123
路人甲
路人甲
  • 注册日期2006-06-17
  • 发帖数3108
  • QQ
  • 铜币6445枚
  • 威望0点
  • 贡献值0点
  • 银元0个
8楼#
发布于:2007-01-25 20:06
<img src="images/post/smile/dvbbs/em07.gif" />
举报 回复(0) 喜欢(0)     评分
candycanqq
路人甲
路人甲
  • 注册日期2006-03-05
  • 发帖数57
  • QQ
  • 铜币264枚
  • 威望0点
  • 贡献值0点
  • 银元0个
9楼#
发布于:2007-04-14 11:35
<img src="images/post/smile/dvbbs/em03.gif" /><img src="images/post/smile/dvbbs/em03.gif" />
举报 回复(0) 喜欢(0)     评分
上一页
游客

返回顶部