Ejemplo n.º 1
0
            # update layer                                            
            main_df = mp.ListDataFrames(mxd)[1]
            main_lyrs = mp.ListLayers(mxd, "", main_df)
            src_lyr = None
            ref_lyr = main_lyrs[0]
            
            for lyr in main_lyrs[1:]:
                lyr_name = lyr.name  # get layer name

                # remove layers
                mp.RemoveLayer(main_df, lyr)

            # insert layers from the template map document
            for in_lyr in lyr_list:
                ins_lyr = mp.Layer(in_lyr)
                mp.InsertLayer(main_df, ref_lyr, ins_lyr)

            # save mapdoc
            mxd.save()
            
            # export map
            map_name = os.path.join(out_dir, mdoc_name)
            mp.ExportToPNG(mxd, map_name, resolution=96)
            
            print '\n'
            del mxd
            count += 1
            

        
        
Ejemplo n.º 2
0
# (1)添加图层
import arcpy.mapping as mapping

mxd = mapping.MapDocument(
    r"E:\ArcPyStudy\Data\ArcpyBook\Ch2\Crime_Ch2_new.mxd")
df = mapping.ListDataFrames(mxd)[0]
layer = mapping.Layer(
    r"E:\ArcPyStudy\Data\ArcpyBook\data\School_Districts.lyr")
mapping.AddLayer(df, layer, "AUTO_ARRANGE")
# (2)插入图层
import arcpy.mapping as mapping

mxd = mapping.MapDocument(
    r"E:\ArcPyStudy\Data\ArcpyBook\Ch2\Crime_Ch2_new.mxd")
df = mapping.ListDataFrames(mxd, "Crime")[0]
refLayer = mapping.ListLayers(mxd, "Burg*", df)[0]  # 指定图层
insertLayer = mapping.Layer(
    r"E:\ArcPyStudy\Data\ArcpyBook\data\CityOfSanAntonio.gdb\Crimes2009")
mapping.InsertLayer(df, refLayer, insertLayer, "BEFORE")

# 9 更新图层的符号系统
import arcpy.mapping as mapping

mxd = mapping.MapDocument(
    r"E:\ArcPyStudy\Data\ArcpyBook\Ch2\Crime_Ch2_new.mxd")
df = mapping.ListDataFrames(mxd, "Crime")[0]
updateLayer = mapping.ListLayers(mxd, "Crime Density by School District",
                                 df)[0]
sourceLayer = mapping.Layer(
    r"E:\ArcPyStudy\Data\ArcpyBook\data\CrimeDensityGradSym.lyr")
mapping.UpdateLayer(df, updateLayer, sourceLayer, True)
                for lyr in main_lyrs:
                    lyr_name = lyr.name
                    lyr_src = lyr.dataSource
                    cont_src = cont_lyr.dataSource
                    bathy_src = bathy_lyr.dataSource
                    
                    if "Sea and Lakes" == lyr_name or "Sea" == lyr_name:
                        print 'Updating %s' % lyr.name
                        mp.UpdateLayer(main_df, lyr, ref_lyr)
                        if lyr_src == cont_src:
                            pass
                        elif lyr_src == bathy_src:
                            pass
                        else:
                            print 'Inserting %s before %s' % (cont_lyr, lyr)
                            mp.InsertLayer(main_df, lyr, cont_lyr, "BEFORE")

                            print 'Inserting %s after %s' % (bathy_lyr, lyr)
                            mp.InsertLayer(main_df, lyr, bathy_lyr, "AFTER")

                            # modify transparency of Sea and Lakes layer
                            lyr.transparency = 30

                            # modify contour layer TOC name
                            cont_lyr.name = "Bathymetric Contours (250m)"
                            
                # modify legend                                          
                leg_elm = mp.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")[0]

                # remove layers from legend
                for leg_itm in leg_elm.listLegendItemLayers():
                print "Saving as %s" % backup_mxd

                #shutil.copy(mapdoc, backup_mxd)       

                # update and insert layer                                            
                main_df = mp.ListDataFrames(mxd)[1]
                main_lyrs = mp.ListLayers(mxd, "", main_df)
                                  
                for lyr in main_lyrs:
                    lyr_name = lyr.name
                    
                    if "Sea and Lakes" == lyr_name or "Sea" == lyr_name:
                        print 'Updating %s' % lyr.name
                        mp.UpdateLayer(main_df, lyr, ref_lyr)
                        print 'Inserting %s and %s' % (ins_cont, ins_bathy)
                        mp.InsertLayer(main_df, lyr, ins_cont, "BEFORE")
                        mp.InsertLayer(main_df, lyr, ins_bathy, "AFTER")
                        
                    else:
                        pass
                        #print 'no'

                #save mapdoc
                #mxd.save()

                #export map
                map_name = os.path.join(out_dir, mdoc_name)
                print "Exporting %s" % mapdoc
                mp.ExportToPNG(mxd, map_name, resolution=96)
                                    
Ejemplo n.º 5
0
disfinal.save(outPut + "/disfin")
dismap = RemapValue([[1, 1], [2, 1], [11, 0], [12, 1]])
arcpy.SetProgressorLabel(
    "The progress is recalssify disfinal Raster, please wait for several minutes..."
)
final = Reclassify(disfinal, "Value", dismap)
arcpy.SetProgressorLabel(
    "The progress is saving final Raster, please wait for several minutes...")
final.save(outPut + "/fin")
#---------------------------------------Pretreatment to Extrate regions' anea----------------------------------------------#
env.workspace = outPut
mxd = mapping.MapDocument("CURRENT")
df = mapping.ListDataFrames(mxd, "Layers")[0]
refLayer = mapping.ListLayers(mxd, "HWSD*", df)[0]
fin = mapping.Layer(r"fin")
mapping.InsertLayer(df, refLayer, fin, "BEFORE")
#--------------------------------------To extrate suitalbe reginons' area in China----------------------------------------#
# Execute SelectLayerByAttribute
arcpy.SelectLayerByAttribute_management("fin", "NEW_SELECTION", "\"VALUE\" =0")
# Execute RasterToPolygon
arcpy.RasterToPolygon_conversion("fin", "zones.shp", "NO_SIMPLIFY", "value")
# Execute IntersectAnalysis
arcpy.Intersect_analysis(["zones.shp", input1], "Intersect", "ALL", "", "")
# Execute ConversationReference
arcpy.DefineProjection_management(
    "Intersect.shp",
    "PROJCS['Sphere_Aitoff',GEOGCS['GCS_Sphere',DATUM['D_Sphere',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Aitoff'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],UNIT['Meter',1.0]]"
)
# Execute AddFileld
arcpy.CalculateAreas_stats("Intersect.shp", "IntersectAreaField.shp")
# Execute CountAreas