1

I have a model that works fine in ArcMap for converting to KML, but when I publish it as a geoprocessing service, only the first attempt from a web application works. All following attempts return KML files with commas instead of points in their geometries:

First run : -72.5123508930792,46.02718407088821,0 -72.89026165964782,45.9512204096942,0 -73.00197113196214,45.60643088717575,0

Second run : -72,5123508930792,46,02718407088821,0 -72,89026165964782,45,9512204096942,0 -73,00197113196214,45,60643088717575,0

I believe that changing the locale setting (decimal delimiter) of the arcGIS server machine might fix this issue, but changing it permanently is simply not an option. I need to find an alternative.

I have tried exporting the model to python and editing the script to change the locale with python (and then return it to its original locale):

locale.setlocale(locale.LC_ALL,"english")
arcpy.LayerToKML_conversion(sourceLayer, kmzFileName, "1", "false", "DEFAULT", "1024", "96", "CLAMPED_TO_GROUND")
locale.setlocale(locale.LC_ALL,"")

as outlined here: https://community.esri.com/thread/110968

But this doesnt seem to work.

Does anyone know of a way to manually override the way ArcGIS Server/arcpy.LayerToKML_conversion uses the system locale/decimal delimiter?

1

There is/was a bug with LayerToKML. I think it was resolved, but I dont remember the specifics of it. The tool was using the locale of the machine but this was causing problems in the KML as you're discovering. When the machine is in an English locale (like English-US), all works fine. From your side the only thing you can do is change the locale on the machine. Trying to set the locale like you're doing in Python is a good idea, but it wont work. Its core ArcMap/Server handling the conversion, this setting will not have any impact.

To get more information you'll need to engage your locale distributor's Technical Support, ask them to find a bug on LayerToKML regarding incorrect locale settings. They can find when it was resolved. Meaning if you can't change the server's locale, maybe you can update to a version where it has been fixed.

0

In case this is of any help to anyone, I found a workaround for this bug by using esriRequest to query the target layer and return the results as a kmz file by changing the "f" parameter to "kmz" and handleAs to "blob" :

//geom is the geometry drawn by the user for the query
var geomREST = JSON.stringify(geom.toJson());
var layersRequest = esriRequest({
        url: layerURL + "/query",
        content: {
          returnGeometry: true,
          geometry: geomREST,
          geometryType: "esriGeometryPolygon",
          outFields: '*',
          f: "kmz"
        },
        handleAs: "blob",
        callbackParamName: "callback"
      },{
        usePost: true
      });

Then in the callback just download the blob with:

if (window.navigator.msSaveOrOpenBlob) { // for IE and Edge
  window.navigator.msSaveBlob(blob, fileName);
} else {
  var link = document.createElement("a");
  document.body.appendChild(link);
  link.style = "display: none";
  url = window.URL.createObjectURL(blob);
  link.href = url;
  link.download = fileName;
  link.click();
  window.URL.revokeObjectURL(url);
  document.body.removeChild(link);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.