Share via


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

Remarks

To perform a batch geocode of your point-of-interest data, follow these steps:

  1. Call the Start BatchGeocode method.

  2. Call the UploadData method, passing in the job ID that is returned from the StartBatchGeocode method.

  3. During the data upload, you can check the progress of the job by calling the GetJobState method.

  4. When the upload has completed, call the FinishUpload method.

  5. 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");
}