What is happening, is CAD/Mobile creates a call. The list of active calls are then put into a csv file where it is created into a shape file and added to the map.
Elizabeth,
When you say created into a shape file do you mean that the CSV file is geocoded with the locator to create the shape file?
I am not an ArcObjects expert but can get my way around the geocoding ArcObjects code. If the CSV is getting geocoded, I would be curious as to how it is getting done right now because I might have an easier way to do it with geoprocessing in C#.
Brad
Well I can't get passed opening it. I keep getting a useless error that tells me nothing. If you know of another way, I am all ears. All this worked great for 9.3. Here is the code for creating the shape from a csv.
IWorkspaceFactory pFact = new TextFileWorkspaceFactory();
IWorkspace pWorkspace = pFact.OpenFromFile(LocalFolder, 0);
IFeatureWorkspace pFeatws = (IFeatureWorkspace)pWorkspace;
ITable pTable = pFeatws.OpenTable(CSVFile); //open the .csv file... !!! Can't get passed this part.
ShapefileWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(LocalFolder, 0);
pMatchFields = geocoder.MatchFields; // Fields from Locator
pTableFieldsEdit = (IFieldsEdit)pTable.Fields; // Fields from ActiveCalls.csv
pOutputFields = (IFieldsEdit)new Fields();
pTableFields = pTableFieldsEdit;
pOutputFields.FieldCount_2 = pTableFields.FieldCount + pMatchFields.FieldCount + 1;
pFieldEdit = (IFieldEdit)new Field();
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
pFieldEdit.Name_2 = "FID";
// Add FID Field
pOutputFields.set_Field(0, pFieldEdit);
// add the fields from the .csv table
for (int i = 1; i <= pTableFields.FieldCount; i++)
pOutputFields.set_Field((i), pTableFields.get_Field(i - 1));
// add the match fields From Locator
for (int i = (1 + pTableFields.FieldCount); i <= (pMatchFields.FieldCount + pTableFields.FieldCount); i++)
{
pOutputFields.set_Field(i, pMatchFields.get_Field(i - pTableFields.FieldCount - 1));
}
// Create the feature class.
pFeatureClass = pFeatureWorkspace.CreateFeatureClass(ShapeFileName, pOutputFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
// create the set of output field names
for (int i = 0; i <= pMatchFields.FieldCount - 1; i++)
{
strOutputFieldNames = strOutputFieldNames + pMatchFields.get_Field(i).Name;
if (i != pMatchFields.FieldCount - 1)
{
strOutputFieldNames = strOutputFieldNames + ",";
}
}
pPropertySet = new PropertySet();
for (int i = 0; i <= pTableFields.FieldCount - 1; i++)
{
pPropertySet.SetProperty(pTableFields.get_Field(i).Name, pTableFields.get_Field(i).Name);
}
strAddressFieldNames = GetAddressFieldNames((IAddressInputs)geocoder, pTable);
ITrackCancel trackCancel = new CancelTrackerClass();
// Geocode the Addresses.....
geocoder.MatchTable(pTable, strAddressFieldNames, "", pFeatureClass, strOutputFieldNames, pPropertySet, trackCancel);
// attach the locator to the geocoded feature class for future use in re-geocoding...
pLocatorDataset = (ILocatorDataset)geocoder;
pLocatorAttach = (ILocatorAttach2)pLocatorDataset.LocatorWorkspace;
pLocatorAttach.AttachLocator((ILocator)geocoder, (ITable)pFeatureClass, strAddressFieldNames, strOutputFieldNames);
}
catch (Exception e)
{
MessageBox.Show("Error when geocoding file. " + e.Message);
Elizabeth,
Yeah that code is the hard way to do it . All of that code can be replaced by this. You just need to change the path to the table, locator and where you want the geocoded featureClass to go. Also, the field mapping is "LocatorFieldName TableFieldName" with each field separated with a semicolon. The 10.x locators have had the same field names for some time so I think Street,City,State,Zip should be the same for you too. You will just need to put in the table field names to replace ADDRESS,CITY,STATE,ZIP below.
You will also need the following using:
using ESRI.ArcGIS.Geoprocessing;
public void GeocodeAddressesTool()
{
String table = @"C:\geocoding\redlands\redlands_addr.csv";
String locator = @"C:\geocoding\redlands\redlands_points_locator";
String fieldMapping = "Street ADDRESS;" + "City CITY;" + "State STATE;" + "Zip ZIP";
String outputFC = @"C:\geocoding\redlands\redlands_addr_geocoded";
IVariantArray parameters = new VarArrayClass();
parameters.Add(table);
parameters.Add(locator);
parameters.Add(fieldMapping);
parameters.Add(outputFC);
IGeoProcessor GP = new GeoProcessorClass();
GP.OverwriteOutput = true;
object Missing = System.Type.Missing;
try
{
GP.Execute("GeocodeAddresses_geocoding", parameters, null);
}
catch (Exception e)
{
throw new Exception("Tool threw an exception: " + e.Message + " GP Messages: " + GP.GetMessages(ref Missing));
}
}
This will create the shape need on the map? This replaces all of that? That would be awesome. I am not as familiar with this. I know a bit and how it worked in 9.3, but have very little experience with ArcGIS in general. So this help is greatly appreciated.Hopefully, this will get me passed this part and on to the next.
I am going out for a bit, but will be sure to try this when I get back.
Elizabeth,
It will do everything that you did above but with a lot less code. It will create a shapefile with all of the geocoding results in it as well as all of the original input data fields copied into the geocoded featureClass as well. Essentially it is doing the exact thing that happens when using the GeocodeAddresses GP tool in ArcMap so you should get exactly the same output as you got in ArcMap.
Brad
This gives me an error when trying to create the GeoProcessorClass. It says "Interop type can't be embedded. Use the applicable interface instead." And I need to get a count of Active Calls.
Elizabeth,
Go to the Project references and make sure that the ESRI.ArcGIS.Geoprocessing assembly has the property "Embed Interop Types" set to false.
Brad
Ok fixed the embedded error. But I do the GP.Execute and I get this error:
I have seen this with another program too and have not figured out what is causing it.
Elizabeth,
I can't guarantee this will work but try disabling multithreading in the locator and see if that helps.
Brad