Delphi版 ArcEngine 根据属性查询要素
function SearchByPropInfo(pLayer: ILayer; sWhere: string; out iCounts: Integer): IFeatureCursor;
var
pQueryFilter: IQueryFilter;
pFeatureLayer: IFeatureLayer;
pFeatureSelection: IFeatureSelection;
pSymbol : ISymbol;
pFillSymbol: ISimpleFillSymbol;
pLineSymbol: ISimpleLineSymbol;
pMarkerSymbol: ISimpleMarkerSymbol;
pColor : IRgbColor;
begin
pFeatureLayer := pLayer as IFeatureLayer;
pQueryFilter := CoQueryFilter.Create as IQueryFilter;
pQueryFilter.WhereClause := sWhere;
Result := pFeatureLayer.Search(pQueryFilter, False);
pColor := CoRgbColor.Create as IRgbColor;
pColor := getRGB(0, 255, 255, 255);
//得到图层要素的几何类型
case pFeatureLayer.FeatureClass.ShapeType of
esriGeometryPoint, esriGeometryMultipoint:
begin
pMarkerSymbol := CoSimpleMarkerSymbol.Create as ISimpleMarkerSymbol;
pMarkerSymbol.Color := pColor as IColor;
pMarkerSymbol.Style := esriSMSCircle;
pSymbol := pMarkerSymbol as ISymbol;
end;
esriGeometryPolygon:
begin
pFillSymbol := CoSimpleFillSymbol.Create as ISimpleFillSymbol;
pFillSymbol.Color := pColor as IColor;
pFillSymbol.Style := esriSFSDiagonalCross;
pSymbol := pFillSymbol as ISymbol;
end;
esriGeometryPolyline:
begin
pLineSymbol := CoSimpleLineSymbol.Create as ISimpleLineSymbol;
pLineSymbol.Color := pColor as IColor;
pLineSymbol.Style := esriSLSSolid;
pLineSymbol.Width := 2;
pSymbol := pLineSymbol as ISymbol;
end;
end;
pFeatureSelection := pLayer as IFeatureSelection;
pFeatureSelection.SetSelectionSymbol := True;
pFeatureSelection.SelectionSymbol := pSymbol;
pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultNew, False);
//得到被选的要素的个数
iCounts := pFeatureSelection.SelectionSet.Count;
end;
var
pQueryFilter: IQueryFilter;
pFeatureLayer: IFeatureLayer;
pFeatureSelection: IFeatureSelection;
pSymbol : ISymbol;
pFillSymbol: ISimpleFillSymbol;
pLineSymbol: ISimpleLineSymbol;
pMarkerSymbol: ISimpleMarkerSymbol;
pColor : IRgbColor;
begin
pFeatureLayer := pLayer as IFeatureLayer;
pQueryFilter := CoQueryFilter.Create as IQueryFilter;
pQueryFilter.WhereClause := sWhere;
Result := pFeatureLayer.Search(pQueryFilter, False);
pColor := CoRgbColor.Create as IRgbColor;
pColor := getRGB(0, 255, 255, 255);
//得到图层要素的几何类型
case pFeatureLayer.FeatureClass.ShapeType of
esriGeometryPoint, esriGeometryMultipoint:
begin
pMarkerSymbol := CoSimpleMarkerSymbol.Create as ISimpleMarkerSymbol;
pMarkerSymbol.Color := pColor as IColor;
pMarkerSymbol.Style := esriSMSCircle;
pSymbol := pMarkerSymbol as ISymbol;
end;
esriGeometryPolygon:
begin
pFillSymbol := CoSimpleFillSymbol.Create as ISimpleFillSymbol;
pFillSymbol.Color := pColor as IColor;
pFillSymbol.Style := esriSFSDiagonalCross;
pSymbol := pFillSymbol as ISymbol;
end;
esriGeometryPolyline:
begin
pLineSymbol := CoSimpleLineSymbol.Create as ISimpleLineSymbol;
pLineSymbol.Color := pColor as IColor;
pLineSymbol.Style := esriSLSSolid;
pLineSymbol.Width := 2;
pSymbol := pLineSymbol as ISymbol;
end;
end;
pFeatureSelection := pLayer as IFeatureSelection;
pFeatureSelection.SetSelectionSymbol := True;
pFeatureSelection.SelectionSymbol := pSymbol;
pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultNew, False);
//得到被选的要素的个数
iCounts := pFeatureSelection.SelectionSet.Count;
end;