0

The gdal_translate program has an option to define an XML file with the necessary information to download an image using various web map server specifications. I am using this XML option with an ArcGIS rest server. This web page describes the format of this XML file and states (under the SRS tag):

For ArcGIS Server the spatial reference can be specified as either
a well-known ID or as a spatial reference json object.

Instead of an EPSG code, I would like to use a spatial reference JSON object in the XML file as described on the link on the above page. If I go to the link on that page, it describes how to define a spatial reference JSON object with well-known text with the following example:

{"wkt" : "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]]"}

As an example, I insert the JSON object into an XML file and come up with the following XML file:

<GDAL_WMS>
     <Service name="AGS">
         <ServerUrl>http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer</ServerUrl>
         <ImageFormat>tiff</ImageFormat>
         <Layers>show:1,2,3</Layers>
         <BBoxOrder>xyXY</BBoxOrder>
         <SRS>{"wkt" : "PROJCS[\"NAD83_Colorado_Central_ftUS\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"scale_factor\",1],PARAMETER[\"standard_parallel_1\",38.45],PARAMETER[\"standard_parallel_2\",39.75],PARAMETER[\"central_meridian\",-105.5],PARAMETER[\"latitude_of_origin\",37.83333333333334],PARAMETER[\"false_easting\",3000000.000316083],PARAMETER[\"false_northing\",999999.9999960001],UNIT[\"Foot_US\",0.30480060960121924]]"}</SRS>
     </Service>
     <DataWindow>
         <UpperLeftX>3092251.0000000000000</UpperLeftX>
         <UpperLeftY>1635556.0000000000000</UpperLeftY>
         <LowerRightX>3099051.0000000000000</LowerRightX>
         <LowerRightY>1629263.0000000000000</LowerRightY>
         <SizeX>1038</SizeX>
         <SizeY>961</SizeY>
     </DataWindow>
</GDAL_WMS>

I save this file as "test.xml" and call gdal_translate as follows:

gdal_translate -of GTiff "F:\temp\test.xml" "F:\temp\test.imagery.tif"

I get the following output when I run this command and the incorrect image is downloaded:

ERROR 1: Failed to lookup UOM CODE 0
Input file size is 1038, 961
0...10...20...30...40...50...60...70...80...90...100 - done.

I suspect GDAL is trying to get an EPSG code or a coordinate system to send to the web service and is not able to for some reason. So I think the web site's default projection is being used (maybe the ESRI web Mercator projection 102100?). In any case, the image returned from the command does not match what I expect.

The funny thing is that if I use the gdal_translate --debug option with the above gdal_translate command, gdal_translate shows that it's breaking the command up into two calls to the AGS service to download two images with the maximum number of pixels being 1024 in each of the images. If I go to the first of these web sites, the image I expect is shown:

http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/export?f=image&bbox=3092251.00000000,1629263.00000000,3098959.28516378,1635556.00000000&size=1024,961&dpi=&imageSR={%22wkt%22%20:%20%22PROJCS[\%22NAD83_Colorado_Central_ftUS\%22,GEOGCS[\%22GCS_North_American_1983\%22,DATUM[\%22North_American_Datum_1983\%22,SPHEROID[\%22GRS_1980\%22,6378137,298.257222101]],PRIMEM[\%22Greenwich\%22,0],UNIT[\%22Degree\%22,0.017453292519943295]],PROJECTION[\%22Lambert_Conformal_Conic_2SP\%22],PARAMETER[\%22scale_factor\%22,1],PARAMETER[\%22standard_parallel_1\%22,38.45],PARAMETER[\%22standard_parallel_2\%22,39.75],PARAMETER[\%22central_meridian\%22,-105.5],PARAMETER[\%22latitude_of_origin\%22,37.83333333333334],PARAMETER[\%22false_easting\%22,3000000.000316083],PARAMETER[\%22false_northing\%22,999999.9999960001],UNIT[\%22Foot_US\%22,0.30480060960121924]]%22}&bboxSR={%22wkt%22%20:%20%22PROJCS[\%22NAD83_Colorado_Central_ftUS\%22,GEOGCS[\%22GCS_North_American_1983\%22,DATUM[\%22North_American_Datum_1983\%22,SPHEROID[\%22GRS_1980\%22,6378137,298.257222101]],PRIMEM[\%22Greenwich\%22,0],UNIT[\%22Degree\%22,0.017453292519943295]],PROJECTION[\%22Lambert_Conformal_Conic_2SP\%22],PARAMETER[\%22scale_factor\%22,1],PARAMETER[\%22standard_parallel_1\%22,38.45],PARAMETER[\%22standard_parallel_2\%22,39.75],PARAMETER[\%22central_meridian\%22,-105.5],PARAMETER[\%22latitude_of_origin\%22,37.83333333333334],PARAMETER[\%22false_easting\%22,3000000.000316083],PARAMETER[\%22false_northing\%22,999999.9999960001],UNIT[\%22Foot_US\%22,0.30480060960121924]]%22}&format=tiff&layerdefs=&layers=show:1,2,3&transparent=false&time=&layerTimeOptions=&dynamicLayers=

But the final image is still the same incorrect image after executing this command?! That's about as far as I've gotten with this project. The question is how do I format the XML file so the final image is the expected image in the correct projection?

  • The error message implies it couldn't interpret the unit of measure object. You could try changing the name from "Foot_US" to "US survey foot" which is the EPSG name. I don't understand why you wouldn't use the wkid: 2232. – mkennedy Jul 27 '17 at 19:45
  • @mkennedy I can't use the EPSG code/wkid name because I cannot automatically get this code from the WKT. All I have is the WKT information. I am able to read the WKT into GDAL to get a projection, but GDAL is not able to get an EPSG code from the WKT using the AutoIdentifyEPSG function. So for this case, I could manually use the EPSG code of 2232 but I have other cases for which the EPSG code cannot be determined. – Burrow Jul 27 '17 at 20:42
0

I finally figured out the solution to this problem after discussing with a few people I work with. The problem was just a simple formatting issue in the XML file. The spatial reference JSON object with the WKT in the XML file had spaces in the example above. Apparently, you cannot have spaces. So instead of the following line in the XML file:

<SRS>{"wkt" : "PROJCS[\"NAD83_Colorado_Central_ftUS\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"scale_factor\",1],PARAMETER[\"standard_parallel_1\",38.45],PARAMETER[\"standard_parallel_2\",39.75],PARAMETER[\"central_meridian\",-105.5],PARAMETER[\"latitude_of_origin\",37.83333333333334],PARAMETER[\"false_easting\",3000000.000316083],PARAMETER[\"false_northing\",999999.9999960001],UNIT[\"Foot_US\",0.30480060960121924]]"}</SRS>

This line should be used in the XML file:

<SRS>{"wkt":"PROJCS[\"NAD83_Colorado_Central_ftUS\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"scale_factor\",1],PARAMETER[\"standard_parallel_1\",38.45],PARAMETER[\"standard_parallel_2\",39.75],PARAMETER[\"central_meridian\",-105.5],PARAMETER[\"latitude_of_origin\",37.83333333333334],PARAMETER[\"false_easting\",3000000.000316083],PARAMETER[\"false_northing\",999999.9999960001],UNIT[\"Foot_US\",0.30480060960121924]]"}</SRS>

(with no spaces)

If I make this simple change everything works fine.

I think the file with spaces does not work because GDAL does not automatically insert the escape characters into the URL (the %20 character for a space), so you just end up with everything before the first space as the URL, and this URL gives the incorrect image. If I copy/paste the URL used by GDAL into a web browser such as Chrome to see if it works, it will bring up the correct image because Chrome automatically inserts the escape characters for spaces into the URL reported by GDAL. Hopefully this makes sense. The easiest solution for me was to just get rid of spaces in the JSON object, but you could probably just as easily put the escape characters for a space in the JSON object and everything should work correctly.

Indeed, the URL that works that I posted in the original question has all the escape characters and works fine. But the URL reported by GDAL does not have the escape characters and the downloaded file likely does not include anything after the first space in the URL (the URL that's used is everything up to the "wkt":

http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/export?f=image&bbox=3092251.00000000,1629263.00000000,3098959.28516378,1635556.00000000&size=1024,961&dpi=&imageSR={"wkt" : "PROJCS[\"NAD83_Colorado_Central_ftUS\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"scale_factor\",1],PARAMETER[\"standard_parallel_1\",38.45],PARAMETER[\"standard_parallel_2\",39.75],PARAMETER[\"central_meridian\",-105.5],PARAMETER[\"latitude_of_origin\",37.83333333333334],PARAMETER[\"false_easting\",3000000.000316083],PARAMETER[\"false_northing\",999999.9999960001],UNIT[\"Foot_US\",0.30480060960121924]]"}&bboxSR={"wkt" : "PROJCS[\"NAD83_Colorado_Central_ftUS\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"scale_factor\",1],PARAMETER[\"standard_parallel_1\",38.45],PARAMETER[\"standard_parallel_2\",39.75],PARAMETER[\"central_meridian\",-105.5],PARAMETER[\"latitude_of_origin\",37.83333333333334],PARAMETER[\"false_easting\",3000000.000316083],PARAMETER[\"false_northing\",999999.9999960001],UNIT[\"Foot_US\",0.30480060960121924]]"}&format=tiff&layerdefs=&layers=show:1,2,3&transparent=false&time=&layerTimeOptions=&dynamicLayers=

It seems like the GDAL source code could be corrected to remove spaces in the spatial reference JSON object. I don't know whether this is a high priority for the primary GDAL contributors, but if I have time I might look into doing this. Just having this solution online should help people if somebody else has this problem though.

EDIT:

After using this solution for a month or so, I have discovered that the projection is not correctly written to the GeoTIFF file using this solution. So I make sure it's written correctly by writing the projection WKT to a temporary .prj file and using the -a_srs command with the .prj file as an argument to this command. This correctly adds the projection to the GeoTIFF file and the WKT shows up correctly when I run gdal_translate from the command line with this extra information.

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.