GIS二次开发经典代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1、保存栅格数据(注意:保存的时候不要忘记要将栅格数据保存到栅格数据集工作空间中,同时还有栅格的扩展名一定要加上。)
Public Sub SaveRaster()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
pMap.DeleteLayer yer(0)
Dim pRasterDataset As IRasterDataset
Dim pWks As IRasterWorkspace
Dim pWksFact As IWorkspaceFactory
Set pWksFact = New RasterWorkspaceFactory
Set pWks = pWksFact.OpenFromFile("D:\Projects\ZLS\temp", 0)
Dim pRBC As IRasterBandCollection
Set pRasterDataset = pWks.OpenRasterDataset("test")
'Dim pRBC As IRasterBandCollection
Dim pRLayer As IRasterLayer
Set pRLayer = New RasterLayer
pRLayer.CreateFromDataset pRasterDataset
Dim pRaster As IRaster
Set pRaster = pRLayer.Raster
Set pRBC = pRaster
Dim pDs As IDataset
Set pDs = pRBC.SaveAs("test", pWks, "TIFF") copyright
pMap.AddLayer pRLayer
End Sub
2、根据已有数据字段,创建shape文件,并将数据插入到shape文件中(delphi代码)
function CreateNewShape(pCursor: IFeatureCursor; pFCls: IFeatureClass; pPath: WideString; pNewFClsName:WideString): IFeatureClass;
var
pShapeFieldName, ConfigKeyword: WideString;
pNewFCls: IFeatureClass;
pFeature: IFeature;
pNewFCursor: IFeatureCursor;
pFeatureBuffer: IFeatureBuffer;
pFields: IFields;
pShape: IGeometry;
pGeoType: esriGeometryType;
pWFact: IWorkspaceFactory;
pWorkspace: IWorkspace;
pWorkspaceEdit: IWorkspaceEdit;
pFWks: IFeatureWorkspace;
pDataset: IDataset;
pCLSID: IUID;
pEXTCLSID: IUID;
pNewID: OleVariant;
bl: wordbool;
i, pFieldCount: integer;
pValue: OleVariant;
begin
ConfigKeyword := '';
//Determine the appropriate geometry type corresponding the the feature type
if pCLSID = nil then
begin
pFCls.Get_CLSID(pCLSID);
pFCls.Get_ShapeType(pGeoType);
end;
//create fields collection
if pFields = nil then
begin
pFCls.Get_Fields(pFields);
end;
//get geometry field name
pFCls.Get_ShapeFieldName(pShapeFieldName);
pEXTCLSID := nil;
pWFact:=CoshapefileWorkspaceFactory.create as IWorkspaceFactory;
pWFact.OpenFromFile(pPath, 0, pWorkspace);
pFWks := pWorkspace as IFeatureWorkspace;
bl := NameExits(pWorkspace, pNewFClsName);
//create shapefile in the temp folder
if not bl then
begin
pFWks.CreateFeatureClass(pNewFClsName, pFields, pCLSID, pEXTCLSID, pGeoType, pShapeFieldName,ConfigKeyword, pNewFCls);