Are there .Net examples of strictly batch processing - i.e. no gui just requesting gps data to be returned for a file

874
5
07-27-2018 07:22 AM
MarkKetchum
New Contributor

I'm new to ArcGIS and have found plenty of mapping examples, but I have to process a text file of addresses to get gps information that is then written to a table. Just wanted to know if there was something available I could refer to that does something similar.

0 Kudos
5 Replies
JoeHershman
MVP Regular Contributor

There is nothing requiring a user interface or the MapView control required by the API.  You can create a .net console application and use the API.  The geocoding just requires you make calls to LocatorTask.

private async void ExecuteFindAddress()
{
     try
     {
          LocatorTask geocodeTask;


          geocodeTask = await LocatorTask.CreateAsync(new Uri(Constants.GeocodeUrl));

          GeocodeParameters parameters = GetGeocodeParameters();
          
          //this would just be any generic way of grabbing data
          foreach (data in datas)
          {
               var searchValues = new Dictionary<string, string>
               {
                    { "address", string.IsNullOrEmpty(data.Address) ? "" : data.Address },
                    { "city", string.IsNullOrEmpty(data.City) ? "" : data.City },
                    { "region", string.IsNullOrEmpty(data.State) ? "" : data.State },
                    { "postal", string.IsNullOrEmpty(data.Zip) ? "" : data.Zip },
                    { "postalExt", string.IsNullOrEmpty(data.ZipPlusFour) ? "" : data.ZipPlusFour }
               };
               
               var geocodeResults = await geocodeTask.GeocodeAsync(searchValues, parameters);
               GeocodeResult result = geocodeResults.FirstOrDefault();

               //write my result to file
          }
          

     }
     catch (Exception e)
     {
          //log error
     }
}

private GeocodeParameters GetGeocodeParameters()
{
     var parameters = new GeocodeParameters();
     parameters.ResultAttributeNames.Add("City");
     parameters.ResultAttributeNames.Add("Postal");
     parameters.ResultAttributeNames.Add("PostalExt");
     parameters.ResultAttributeNames.Add("RegionAbbr");
     parameters.ResultAttributeNames.Add("StAddr");

     parameters.CountryCode = "USA";

     parameters.SearchArea = _fullExtent;
     return parameters;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Thanks,
-Joe
0 Kudos
MarkKetchum
New Contributor

Thanks for the response, I get the error LocatorTask does not contain a definition for CreateAsync.

Do I have the correct version of the .net extension? ArcGIS_Runtime_SDK_DotNet_100_3_0.vsix

0 Kudos
dotMorten_esri
Esri Notable Contributor

Did you initialize the runtime first before using it?

Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.Initialize();

Also although the VSIX is correct, which NuGet package version are you referencing?

0 Kudos
MarkKetchum
New Contributor

Thanks got it to work.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

If you are using async code in a .NET console app you may also need to set the SynchronizationContext because console apps do not have a SynchronizationContext initialized by default. If you search the web for "console application synchronizationcontext" you will find various examples/solutions.

Cheers

Mike

0 Kudos