Updating raster of mxd file using ArcPy?

Using ArcGIS 10 wanted to update the raster file in a mxd file using python. for example, i created a.mxd which contains b.tif file in it. now, i obtained c.tif and want to update the a.mxd, i.e. want to delete b.tif and add c.tif, or overwrite b.tif with c.tif

import arcpy mxd = arcpy.mapping.MapDocument(r"C:dataa.mxd") df = arcpy.mapping.ListDataFrames(mxd)[0] updateLyr = arcpy.mapping.ListLayers(mxd)[0] sourceLyr = arcpy.mapping.Layer(arcpy.Raster(r"C:datac.tif")) arcpy.mapping.UpdateLayer(df, updateLyr, sourceLyr, True) del mxd

i started as above, but i think that i am not getting most of the things correctly.

I think you wantreplaceDataSourceinstead ofUpdateLayer. Update uses a template, the sourceLyr, and applies its properties (data path, symbology, etc.) to the layer-to-be-updated whereas you only want to change the data path/filename.

See Updating and fixing data sources with arcpy.mapping in the Esri docs for more detail, and Changing data source path involving feature dataset in *.lyr files using ArcPy? here on for some quirky behaviour to be aware of.

Create a layer file consisting of your new tif, named 'c.lyr' and place it in the same directory (i.e. c:datac.lyr) Then run this inside the map document:

import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") for df in arcpy.mapping.ListDataFrames(mxd): for refLayer in arcpy.mapping.ListLayers(mxd, "*b.tif", df): mosaic = arcpy.mapping.Layer(u'C:datac.lyr') arcpy.mapping.InsertLayer(df, refLayer, mosaic, "BEFORE") mosaic.visible = refLayer.visible mosaic.brightness = refLayer.brightness mosaic.contrast = refLayer.contrast mosaic.transparency = refLayer.transparency = arcpy.mapping.RemoveLayer(df, refLayer) arcpy.RefreshActiveView() arcpy.RefreshTOC() del mxd, df try: del refLayer, mosaic except: pass finally: print u'TIF updated!'

Or if you prefer a function:

def UpdateTIF(mxd, old, new): #mxd: path to mxd to update #old: wildcard matching pattern for the old source #new: layer file referencing new source import arcpy mxd = arcpy.mapping.MapDocument(mxd) for df in arcpy.mapping.ListDataFrames(mxd): for refLayer in arcpy.mapping.ListLayers(mxd, old, df): mosaic = arcpy.mapping.Layer(new) arcpy.mapping.InsertLayer(df, refLayer, mosaic, "BEFORE") mosaic.visible = refLayer.visible mosaic.brightness = refLayer.brightness mosaic.contrast = refLayer.contrast mosaic.transparency = refLayer.transparency = arcpy.mapping.RemoveLayer(df, refLayer) del mxd, df try: del refLayer, mosaic except: pass finally: print u'TIF updated!'

Execute this with a call like:

UpdateTIF('C:dataa.mxd', '*b.tif', 'C:datac.lyr')

Add 'serviceProperties' property to the Arcpy TableView class

In the ArcPy Mapping Module, please add the property named 'serviceProperties' to the TableView class. This property exists on the 'feature layer' class and allows ptyhon programmers like myself identify what server a particular SDE layer is coming from.

I am trying to write a Python tool to repoint all the sources in a particular MXD from one server to another. However the MXD contains layers and table views from multiple SDE's, I just want to repoint the data from one SDE(Like repointing data sources from a Test SDE to a production SDE).

The 'replacedatasource' method for repointing layers is insufficient, since it relies on me the programmer knowing what the path is to the SDE connection file used to add the table to the map. However, since I am just the programmer, I have no idea what the name of particular SDE connections users added data from. I'd rather just search each layer and tableview and check the service or server line to see if the name of a particular server is there. If it is I can run my code to repoint the layer to a different server.

Aligning the raster with control points

Generally, you will georeference your raster data using existing spatial data (target data)—such as georeferenced rasters or a vector feature class—that resides in the desired map coordinate system. The process involves identifying a series of ground control points—known x,y coordinates—that link locations on the raster dataset with locations in the spatially referenced data (target data). Control points are locations that can be accurately identified on the raster dataset and in real-world coordinates. Many different types of features can be used as identifiable locations, such as road or stream intersections, the mouth of a stream, rock outcrops, the end of a jetty of land, the corner of an established field, street corners, or the intersection of two hedgerows.

The control points are used to build a polynomial transformation that will shift the raster dataset from its existing location to the spatially correct location. The connection between one control point on the raster dataset (the from point) and the corresponding control point on the aligned target data (the to point) is a link.

The example below shows a from control point (yellow cross) placed on the vector target data at a street crossing and the associated control point (green cross) placed on the raster dataset. The associated link is represented by the blue line joining the control points.

The number of links you need to create depends on the complexity of the transformation you plan to use to transform the raster dataset to map coordinates. However, adding more links will not necessarily yield a better registration. If possible, you should spread the links over the entire raster dataset rather than concentrating them in one area. Typically, having at least one link near each corner of the raster dataset and a few throughout the interior produces the best results.

Generally, the greater the overlap between the raster dataset and target data, the better the alignment results, because you'll have more widely spaced points with which to georeference the raster dataset. For example, if your target data only occupies one-quarter of the area of your raster dataset, the points you could use to align the raster dataset would be confined to that area of overlap. Thus, the areas outside the overlap area are not likely to be properly aligned.

Keep in mind that your georeferenced data is only as accurate as the data to which it is aligned. To minimize errors, you should georeference to data that is at the highest resolution and largest scale for your needs.

Updating raster of mxd file using ArcPy? - Geographic Information Systems

Introduction: In the previous chapter, we learned how to make statistical tables [1] , But in many cases data is needed to reveal the content simply and clearly, so it’s also essential to learn how to make statistical graphs

1. Experimental purpose

Master the method of displaying data according to existing style symbols

Master the method of selecting elements and attributes according to location

Master the method of making statistical graphs

Ch2File. chap2markingchartchart.mxd

3. Experimental requirements

Count the scope of the noise area, what types of land use are there, and what is the area?

In the category of tokenizationUnique valueselectLand use, And then add all fields and color according to the color band (manually)

Step 2 Unlock the land affected by noise

(1) In the main menu selectionChoose by location. Where the target layer isLand use, The original layer isNoise layer, The space selection method isThrough the intersection of two layersMake a selection, then apply

Find the date on the land use layer, and then output it, where the output is the feature selected in the experiment, and then save it

(3) The land use area affected by noise is obtained, as shown in the figure below

Open the attribute table for land use typeStatistics summary, The selection isSummarize the area, And then make aSum, Then output, the output type is attribute table, save, add to the map

Step three make a statistical chart

Display the made form, that is, passView, Find the chart, and create the chart

Herex axisIndicates land use. You can also debug color, label display, legend display, etc., and then click Next

(2) Set and add the title and legend title for the statistical quantity, as shown in the figure below

(3) Modify the legend and title, as shown below

Finally, make a picture in the view,Adjust the layoutTo bring up the menu as shown below

Watch the video: Convert ArcGIS file types .lyr.mxd to QGIS with SLYR. burdGIS (October 2021).