Select to view content in your preferred language

Setting layer scale and symbology

4079
3
03-01-2012 11:32 PM
MichaelHarrop
Emerging Contributor
Hi

Is it possible to set the visible scale of a layer using ArcPy? What i'm aiming to do is apply the symbology from one layer to a number of other layers but vary the scale at which each layer is visible using Arcpy

For example, we have 5 feature classes essentially showing the same data at different resolutions e.g 1m,10m, 100m. I want to create a layer file for one feature class, then using arcpy assign this symbology to create layer files for the other feature classes but at the same time alter the display scale depening on the resolution

Thanks
Tags (2)
3 Replies
JeffBarrette
Esri Regular Contributor
At 10.0, this requires a bit of extra logic but it is possible.  You would need to add your layer file multiple times, uniquely name each layer and then check the data frame scale and turn on/off layers.

At 10.1, we've exposed the layer scale min/max properties on the Layer object.

Jeff
0 Kudos
MichaelHarrop
Emerging Contributor
Thanks Jeff,

We think we have a way around, we are goingto create a dummy layer file for each of the required scales, then set up a tool to changethe data source, apply the symbology, rename the layer file and save as a new mxd which we then use to create map services

However our main issue is changing the datasource, the dummy layers point to a file geodatabase with but with the links broken and we are attempting to use this to change the source to SDE

import arcpy
mxd = arcpy.mapping.MapDocument(r"J:\users\harromi\replacesource\dummy.mxd")
sdepath = r"Z:\webapp\mapservices\Maps\connection-files\DEV\GISCO-DEV-direct-giscoread.sde"
for lyr in arcpy.mapping.ListBrokenDataSources(mxd):
    if lyr.supports("DATASOURCE"):
        if lyr.dataSource == r"H:\MyDocuments\ArcGIS\Default.gdb\Export_Output":
            lyr.replaceDataSource(sdepath, "SDE_WORKSPACE", "GISCOVIEW.STAT_LIFEXF_NUTS2_2006_8_01M", True)
            lyr.name = "LifeEX"
mxd.saveACopy(r"H:\MyDocuments\ArcGIS\Untitled6.mxd")


Similar code works when updating the source to a another fgdb feature but won't work for SDE

Thanks
0 Kudos
williamangle
New Contributor
I'm running into a similar problem. I'm attempting to create a map with two layers, one of which is visible at scales greater than 1:500000, the other being visible at scales less than 1:500000. I had attempted to define a function to conditionally set the visibility of the layer based on the dataframe's current scale, but am lost on how to update the visibility parameters of the layers on a change of scale within the map. For example:
def closeVisible(scale):
    if scale < 500000:
        return True
    else:
        return False

def farVisible(scale)
    if scale > 500000:
        return True
    else:
        return False


I would define the visibility of the layers like so:
layer1.visible = closeVisible(dataframe.scale)
layer2.visible = farVisible(dataframe.scale)



At 10.0, this requires a bit of extra logic but it is possible.  You would need to add your layer file multiple times, uniquely name each layer and then check the data frame scale and turn on/off layers....


I'm not sure I understand what you mean by "check the data frame scale and turn on/off layers." Are you indicating that this should be done statically, as coded above? Is there another way to do this? Ideally, every time dataframe.scale changed, the layer visibility would be redefined using the listed functions. Any help is greatly appreciated!

Thanks,
Paul

EDIT: I should have mentioned in my initial post that dataframe.scale is being changed by zooming in and out of the map within ArcMap. Is there anything in the ArcPy library or other available Python libraries that interfaces with the programs scale setting function? My function definition won't work because visible is strictly a boolean type and is set by the function only once, after which I'm assuming the function instance is tossed into cyber-limbo.

Then end goal is to be able to script the creation of a raster layer every day with a maximum and minimum scale setting-- a simple task I'm assuming with 10.1. Is the ArcPy module from 10.1 available for download aside from installing the full 10.1 beta?
0 Kudos