I'm currently needing to make a tool that's inside another Java addin application which allows a user to update an existing feature (parcels for example) in the database. The user should be able to navigate to and select the shapefile or feature class they want to specify as the source.
Instead of using full blown ArcObjects, I was trying to leverage the Geoprocessing processes available to expedite this (and make coding a little less bulky) since it's effectively using delete features and copy features and, as a sanity check, I wanted to use the FeatureCompare as well to make sure the schemas of the source and target are the same before performing a delete on the existing features in the database.
While in the mapping application, the program has a live connection to the database, but even with that, I have been having some issues with NullPointerException errors when I try to run any of the processes and have also been trying to figure out the best way to get something returned from the FeatureCompare to let the program know whether or not to proceed with deleting and copying or stopping and letting the user know that it won't proceed.
I've also been having a bit of a time getting Java to recognize a .gdb as anything besides a folder, but if I can get it to run for a .shp load, I'll tackle that later.
Below are some snippets - the current setup I'm working with is 10.4.1, Java 1.8, Oracle 12c
Thanks.
Bart
================================
public void compareFeatures(String source, String target) throws IOException {
try {
// compare in and out feature schemas
FeatureCompare featComp = new FeatureCompare();
// set the target schema
featComp.setInBaseFeatures(source);
// set the test features schema
featComp.setInTestFeatures(target);
featComp.setSortField("AC_LAB");
// just compare the schemas
featComp.setCompareType("SCHEMA_ONLY");
// and omit these fields from comparison
featComp.setOmitField("Shape, Shape_Leng, Shape_Area, Shape_Length, AREA, LEN");
// execute the compare
gp.execute(featComp, trackCancel);
int index = 0;
gp.getReturnCode(index);
}
catch(Exception cf) {
cf.printStackTrace();
setResultText("Error: " + cf.getMessage());
}
}
public void deleteFeatures(String target) throws IOException {
try {
// delete features in the database
DeleteFeatures delFeat = new DeleteFeatures();
delFeat.setInFeatures(target);
gp.execute(delFeat, trackCancel);
System.out.println("Features deleted ... ");
}
catch(Exception df) {
df.printStackTrace();
setResultText("Error: " + df.getMessage());
}
}
@Action
public void execute() {
System.out.println("I'm in the execute function");
try {
String sourceFile = inputFile.toString();
String targetFile = "comboBox.getSelectedItem()";
System.out.println("source file is: " + sourceFile + "\n");
System.out.println("target file is: " + targetFile + "\n");
System.out.println("Comparing schemas for " + targetFile + " and " + sourceFile + "\n");
compareFeatures(sourceFile, targetFile);
if (compareSucceeds) {
System.out.println("Deleting features from " + targetFile + "\n");
deleteFeatures(targetFile);
System.out.println("Loading new features ... "\n");
copyFeatures(sourceFile, targetFile);