原码是
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.Vector;
import com.esri.arcgis.datasourcesGDB.AccessWorkspaceFactory;
import com.esri.arcgis.datasourcesGDB.SdeWorkspaceFactory;
import com.esri.arcgis.datasourcesfile.ShapefileWorkspaceFactory;
import com.esri.arcgis.geodatabase.*;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.IClone;
import com.esri.arcgis.system.ICloneProxy;
import com.esri.arcgis.system.IName;
import com.esri.arcgis.system.INameProxy;
import com.esri.arcgis.system.IPropertySet;
import com.esri.arcgis.system.PropertySet;
import com.esri.arcgis.system.esriLicenseProductCode;
public class SHPToGeo {
AoInitialize aoInit=null;
IFeatureWorkspace ws;
private IFeatureClass annoFClass = null;
private String _instance = "5151/tcp";
private IFeatureClassName _pInFCName = null;
private String _sOutFCName = null;
private IPropertySet pPropSet = null;
private IWorkspaceName pOutWsName = null;
private Vector data = new Vector();
private String layname = null;
public static void main(String []arg)
{
Date d = new Date();
System.out.println(d.getHours()+" "+d.getMinutes()+" "+d.getSeconds());
// new SHPToGeo();
}
public SHPToGeo(String server,String datebaseN,String user,String password,String layname)
{
this.layname = layname;
try
{
EngineInitializer.initializeVisualBeans();
aoInit = new AoInitialize();
aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
// ICommandHostPtr pICommandHost(__uuidof(CommandHost));
pPropSet = new PropertySet();
IWorkspaceFactory pSdeFact = new SdeWorkspaceFactory();
pPropSet.setProperty( "SERVER", server);
pPropSet.setProperty( "INSTANCE", "5151/tcp");
pPropSet.setProperty( "DATABASE", datebaseN);
pPropSet.setProperty( "USER", user);
pPropSet.setProperty( "PASSWORD", password);
pPropSet.setProperty( "version", "sde.default");
}
catch( IOException e)
{
e.printStackTrace();
}
}
public void saveShap()
{
getInConvert();
ggg();
ConvertFeatureClass(_pInFCName, pOutWsName, null, _sOutFCName);
}
public void getInConvert()
{
Vector v = new Vector();
try {
pOutWsName =new WorkspaceName();
pOutWsName.setWorkspaceFactoryProgID("esriDataSourcesGDB.SDEWorkspaceFactory");
pOutWsName.setConnectionProperties(pPropSet);
_pInFCName = new FeatureClassName();
IDatasetName pDatasetName ;
pDatasetName = (IDatasetName)_pInFCName;
pDatasetName.setName(layname);
pDatasetName.setWorkspaceNameByRef(pOutWsName);
_sOutFCName = pDatasetName.getName();
// IDatasetName pDatasetName1 = (IDatasetName)_pInFCName;
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void ggg()
{
try {
IWorkspaceName pINWsName = null;
IDatasetName pInDatasetName ;
pINWsName = new WorkspaceName();
pINWsName.setPathName("D:\\DownLoads\\");
pINWsName.setWorkspaceFactoryProgID("esriCore.ShapefileWorkspaceFactory.1");
_pInFCName = new FeatureClassName();
pInDatasetName = (IDatasetName)_pInFCName;
pInDatasetName.setName(layname);
pInDatasetName.setWorkspaceNameByRef(pINWsName) ;
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void ConvertFeatureClass(IFeatureClassName pInFCName,IWorkspaceName pOutWorkspaceName ,IFeatureDatasetName pOutFDName ,String strOutFCName)
{
//' Set Output feature class name
FeatureClassName pOutFCName ;
try {
pOutFCName = new FeatureClassName();
IDatasetName pDatasetName;
pDatasetName = (IDatasetName)pOutFCName;
pDatasetName.setName(strOutFCName);
pDatasetName.setWorkspaceNameByRef(pOutWorkspaceName);
if (pOutFDName!=null)
{
pOutFCName.setFeatureDatasetNameByRef(null);
}
// ' Get the fields for the input feature class
// ' and run them through the field checker
// ' Strip field names which are qualified as Owner.TableName.FieldName
// ' this will avoid breaking the field name width limit
IFields pFields;
IFields []pOutFields = null;
IFeatureClass pInFeatureClass = null;
IName pName ;
pName=(IName)pInFCName;
pInFeatureClass =new IFeatureClassProxy( pName.open());
// pInFeatureClass.addField(fj);
IClone pSource ;
pSource = new ICloneProxy(pInFeatureClass.getFields());
pFields = new IFieldsProxy(pSource.esri_clone());
//
ISQLSyntax pSQLSyntax;
pDatasetName = (IDatasetName)pInFCName;
pName =new INameProxy( pDatasetName.getWorkspaceName());
pSQLSyntax =new ISQLSyntaxProxy( pName.open()); //'Inline QI on Workspace object
//
int i;
IField pField ;
IFieldEdit pFieldEdit;
String []sStrippedName=null;
String []sDbName=null;String []sOwnerName=new String[1]; String []sTableName=null ;
//
//// ' For each field, strip the name
//// ' The check on Owner name avoids processing the Shape.Area and Shape.Len fields.
//// ' (these are handled by the feature data converter).
for ( i = 0;i {
pField = pFields.getField(i);
sOwnerName[0] ="" ;
pSQLSyntax.parseColumnName(pField.getName(), sDbName, sOwnerName, sTableName, sStrippedName);
if (sOwnerName.length > 0)
{
pFieldEdit =new IFieldEditProxy( pField);
pFieldEdit.setName(pField.getName()) ;
}
}
//
// pSQLSyntax.parseColumnName(fj.getName(), sDbName, sOwnerName, sTableName, sStrippedName);
//
IEnumFieldError[] pEnumFieldError = null;
IFieldChecker pFieldChecker;
pFieldChecker = new FieldChecker();
pFieldChecker.validate(pFields, pEnumFieldError, pOutFields) ;
//
IFeatureDataConverter pFeatureDataConverter ;
pFeatureDataConverter = new FeatureDataConverter();
//
// //' Do the conversion
IEnumInvalidObject pEnumInvalidObject;
pEnumInvalidObject = pFeatureDataConverter.convertFeatureClass(pInFCName,null,pOutFDName,pOutFCName,null,null,"",1000,0);
pOutWsName = null;
pOutWsName = null;
_sOutFCName = null;
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}