0

An app I'm developing needs to handcraft ESRI JSON to display simple polygons in ArcMap Desktop upon import. I want to specify color/transparency/outlining for the polygons in a layer and ideally different colors for different polygons. (The app does not have access to APIs for this, so it's all done the hard way.)

I've found no documentation for handcrafted JSON but got a few ideas from looking at JSON (Server) examples on the Net, for example drawingInfo/renderer, but haven't been able to get this working. (Maybe drawingInfo is supported by Server but not by Desktop?). I've tried a renderer of type "uniqueValue" without success and have fallen back to trying a renderer of type "simple".

Below, based largely on guesswork, is my attempt. On import into ArcCatalog/ArcMap 10.4, the polygon is displayed but the attempt to specify color and outline was ignored.

{"displayFieldName":"","fieldAliases":{"Name":"Name","Description":"Description","Latitude":"Latitude","Longitude":"Longitude","TriangAccu":"TriangAccu","SatHorWKID":"SatHorWKID","SatVerWKID":"SatVerWKID","GridWKID":"GridWKID"},"geometryType":"esriGeometryPolygon",
 "drawingInfo": {
  "renderer": {
   "type": "simple",
   "symbol": {
      "type": "esriSFS",
      "style": "esriSFSSolid",
      "color": [
       255,
       0,
       0,
       255
      ],
      "outline": {
       "type": "esriSLS",
       "style": "esriSLSSolid",
       "color": [
        0,
        0,
        255,
        255
       ],
       "width": 0.4
      }
     }
  }
  },
"hasZ":"false","spatialReference":{"wkid":"4326","latestWkid":"4326"},"fields":[{"name":"Name","type":"esriFieldTypeString","alias":"Name","length":"45"},{"name":"Description","type":"esriFieldTypeString","alias":"Description","length":"140"},{"name":"Latitude","type":"esriFieldTypeDouble","alias":"Latitude"},{"name":"Longitude","type":"esriFieldTypeDouble","alias":"Longitude"},{"name":"TriangAccu","type":"esriFieldTypeString","alias":"TriangAccu","length":"20"},{"name":"SatHorWKID","type":"esriFieldTypeString","alias":"SatHorWKID","length":"8"},{"name":"SatVerWKID","type":"esriFieldTypeString","alias":"SatVerWKID","length":"8"},{"name":"GridWKID","type":"esriFieldTypeString","alias":"GridWKID","length":"8"}],"features":[{"attributes":{"Name":"North","Description":"","Latitude":"-33.63610000","Longitude":"151.33165000","TriangAccu":"","SatHorWKID":"4326","SatVerWKID":"","GridWKID":""},
"geometry":{
"rings":[[ 
[151.31426667,-33.64595000],
[151.29100000,-33.64000000],
[151.33166667,-33.58195000],
[151.33365000,-33.64341667],
[151.31426667,-33.64595000]
]]
}}]}
  • I also have an ArcPy script to import the Json file. Possibly the easiest is to handle things there? Will research that. – BillF Mar 2 '16 at 4:57
  • Does anyone think it 'looks like it should work'? If so, could be a 10.4 issue? Haven't tried it on 10.3. – BillF Mar 2 '16 at 21:37
1

While I couldn't solve this in JSON, I did get a reasonable solution by modifying my ArcPy script that imports the JSON.

First I created a .lyr file containing the polygon symbology with desired colour and outlining. Trying to set transparency here did not stick.

In my python script I used code similar to the following. Transparency needed to be set in two places for it to work.

        tempLayerName = outputFeatureName
        targetGroupLayer = arcpy.mapping.ListLayers ( mxd, groupLayerName, dataFrame ) [ 0 ]
        arcpy.MakeFeatureLayer_management ( os.path.join ( geodatabase, outputFeatureName ), tempLayerName )
        tempAddedLayer = arcpy.mapping.Layer ( tempLayerName )
        if groupLayerName == "Areas":
            tempAddedLayer.transparency = 50
        sourceLayer = arcpy.mapping.Layer( layerFilespec ) # Filespec of .lyr file
        if groupLayerName == "Areas":
            sourceLayer.transparency = 50
        arcpy.mapping.UpdateLayer( dataFrame, tempAddedLayer, sourceLayer, True )
        arcpy.mapping.AddLayerToGroup( dataFrame, targetGroupLayer, tempAddedLayer, "AUTO_ARRANGE" )

An interesting post that might also have helped is: How to apply the four colors theorem in a polygon map in ArcGIS/ArcToolBox automatcally?

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.