|
阅读:1892回复:3
[求助]vc+ao怎么实现shapefile文件的保存??
<P>各位GIS大虾,有谁能帮小弟解决一下shapefile文件的保存??小弟用的是vc+AO.</P>
<P>小弟先谢谢各位大虾了!</P> |
|
|
1楼#
发布于:2005-12-05 11:14
HRESULT CreateShapefile(BSTR bstrPath, BSTR bstrName, esriGeometryType lGeoType,<BR> CStringArray ;arrFieldName, CArray<esriFieldType, esriFieldType> ;arrFieldType, <BR> IFeatureClass** ppFeatureClass)<BR>{<BR> if (arrFieldName.GetSize() != arrFieldType.GetSize())<BR> return E_FAIL;<BR> <BR> if (!ppFeatureClass)<BR> return E_POINTER;<BR> <BR> HRESULT hr;<BR> <BR> // Open the folder to contain the shapefile as a workspace<BR> IWorkspaceFactoryPtr ipWorkspaceFactory(CLSID_ShapefileWorkspaceFactory);<BR> IWorkspacePtr ipWS;<BR> hr = ipWorkspaceFactory->OpenFromFile(bstrPath, 0, ;ipWS);<BR> IFeatureWorkspacePtr ipFWS(ipWS);<BR> <BR> // Set up a simple fields collection<BR> IFieldsPtr ipFields(CLSID_Fields);<BR> IFieldsEditPtr ipFieldsEdit(ipFields);<BR> <BR> // Make the shape field<BR> // it will need a geometry definition, with a spatial reference<BR> IFieldPtr ipField(CLSID_Field);<BR> IFieldEditPtr ipFieldEdit(ipField);<BR> hr = ipFieldEdit->put_Name(CComBSTR(L"Shape"));<BR> hr = ipFieldEdit->put_Type(esriFieldTypeGeometry);<BR> <BR> IGeometryDefPtr ipGeomDef(CLSID_GeometryDef);<BR> IGeometryDefEditPtr ipGeomDefEdit(ipGeomDef);<BR> hr = ipGeomDefEdit->put_GeometryType(lGeoType);<BR> ISpatialReferencePtr ipSpatialRef(CLSID_UnknownCoordinateSystem);<BR> hr = ipGeomDefEdit->putref_SpatialReference(ipSpatialRef);<BR> hr = ipFieldEdit->putref_GeometryDef(ipGeomDef);<BR> hr = ipFieldsEdit->AddField(ipField);<BR> <BR> esriFieldType lType;<BR> long lFieldCount = arrFieldType.GetSize();<BR> for (long i=0; i<lFieldCount; i++)<BR> {<BR> ipField.CreateInstance(CLSID_Field);<BR> ipFieldEdit = ipField;<BR> lType = arrFieldType.GetAt(i);<BR> hr = ipFieldEdit->put_Type(lType);<BR> hr = ipFieldEdit->put_Name(CComBSTR(arrFieldName.GetAt(i)));<BR> hr = ipFieldsEdit->AddField(ipField);<BR> }<BR> <BR> // Create the shapefile<BR> // (some parameters apply to geodatabase options and can be defaulted as Nothing)<BR> IFeatureClassPtr ipFeatClass;<BR> hr = ipFWS->CreateFeatureClass(bstrName, ipFields, 0, 0, esriFTSimple, <BR> CComBSTR(L"Shape"), CComBSTR(L""), ;ipFeatClass);<BR> <BR> *ppFeatureClass = ipFeatClass;<BR> if (*ppFeatureClass)<BR> (*ppFeatureClass)->AddRef();<BR> else<BR> return E_FAIL;<BR> <BR> return S_OK;<BR>}
|
|
|
|
2楼#
发布于:2005-12-06 16:52
谢谢大虾指教!!<img src="images/post/smile/dvbbs/em02.gif" />
|
|
|
3楼#
发布于:2006-01-17 16:59
多谢大侠指教了,小弟受教了。
|
|