CustomerDataService.StartBatchGeocode Method
CustomerDataService.StartBatchGeocode Method
Starts a batch geocoding job. This method returns a unique job ID that can be used in subsequent calls.
Public Function StartBatchGeocode(specification As BatchGeocodeSpecification) As String
[C#]
public string StartBatchGeocode(BatchGeocodeSpecification specification);
Parameters
- specification
A BatchGeocodeSpecification object.
Remarks
To perform a batch geocode of your point-of-interest data, follow these steps:
Call the Start BatchGeocode method.
Call the UploadData method, passing in the job ID that is returned from the StartBatchGeocode method.
During the data upload, you can check the progress of the job by calling the GetJobState method.
When the upload has completed, call the FinishUpload method.
Call the GetDownloadFileUrl method to access the geocoded data.
Example
[Visual Basic]
Dim DataService As New CustomerDataService
DataService.Credentials = New NetworkCredential(myUserName, mySecurePassword, myDomainName)
' Create BatchGeocodeSpecification
Dim uploadSpec As New BatchGeocodeSpecification
uploadSpec.JobName = "BatchGeocodeJob"
uploadSpec.MaximumGeocodingLevel = GeocodingLevel.Street
uploadSpec.RejectAmbiguousGeocodes = True
' Start Batch Geocode
Dim jobID As String = DataService.StartBatchGeocode(uploadSpec)
' Upload data
Dim localUploadStream As New FileStream("c:\uploadfile.xml", FileMode.Open, FileAccess.Read, FileShare.Read)
Dim localUploadReader As New BinaryReader(localUploadStream)
Dim filesize As Long = localUploadStream.Length
Dim bytesPreviouslyUploaded As Long = 0
While (bytesPreviouslyUploaded < filesize)
Dim localBuffer As Byte() = localUploadReader.ReadBytes(2000)
bytesPreviouslyUploaded = DataService.UploadData(jobID, localBuffer, bytesPreviouslyUploaded)
End While
DataService.FinishUpload(jobID, filesize)
' Wait for job to complete
Dim jobState As JobState = DataService.GetJobState(jobID)
While (jobState = jobState.Pending OrElse jobState = jobState.InProcess)
Thread.Sleep(10000)
jobState = DataService.GetJobState(jobID)
End While
' download the results
If (jobState = jobState.CompletedSuccess) Then
Dim downloadURL As String = DataService.GetDownloadFileURL(jobID)
Dim downloadClient As New System.Net.WebClient
downloadClient.Credentials = New NetworkCredential(myUserName, mySecurePassword, myDomainName)
downloadClient.DownloadFile(downloadURL, "c:\results.zip")
End If
[C#]
CustomerDataService DataService = new CustomerDataService();
DataService.Credentials = new NetworkCredential(myUserName, mySecurePassword, myDomainName);
// Create BatchGeocodeSpecification
BatchGeocodeSpecification uploadSpec = new BatchGeocodeSpecification();
uploadSpec.JobName = "BatchGeocodeJob";
uploadSpec.MaximumGeocodingLevel = GeocodingLevel.Street;
uploadSpec.RejectAmbiguousGeocodes = true;
// Start Batch Geocode
string jobID = DataService.StartBatchGeocode(uploadSpec);
// Upload data
FileStream localUploadStream = new FileStream(@"c:\uploadfile.xml", FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryReader localUploadReader = new BinaryReader(localUploadStream);
long filesize = localUploadStream.Length;
long bytesPreviouslyUploaded = 0;
while (bytesPreviouslyUploaded < filesize)
{
byte[] localBuffer = localUploadReader.ReadBytes(2000);
bytesPreviouslyUploaded = DataService.UploadData(jobID, localBuffer, bytesPreviouslyUploaded);
}
DataService.FinishUpload(jobID, filesize);
// Wait for job to complete
JobState jobState = DataService.GetJobState(jobID);
while (jobState == JobState.Pending || jobState == JobState.InProcess)
{
Thread.Sleep(10000);
jobState = DataService.GetJobState(jobID);
}
// download the results
if (jobState == JobState.CompletedSuccess)
{
string downloadURL = DataService.GetDownloadFileURL(jobID);
System.Net.WebClient downloadClient = new WebClient();
downloadClient.Credentials = new NetworkCredential(myUserName, mySecurePassword, myDomainName)
downloadClient.DownloadFile(downloadURL, @"c:\results.zip");
}