首页 > 编程语言 >[922] Implementation of zooming to selected features by Python

[922] Implementation of zooming to selected features by Python

时间:2023-10-20 14:34:30浏览次数:36  
标签:function product features Python list reduce Implementation numbers aprx

ref: ArcPy.mp Get Selected Features Extent

ref: Python/ArcPy classes/Geometry


# Set the path to your project file (.aprx)
project_file = r"Map 1.3 Heritage.aprx"
 
# Reference the project
aprx = arcpy.mp.ArcGISProject(project_file)
 
# get the sitebuffer layer
m = aprx.listMaps()[0]
lyr = m.listLayers()[3]
 
# selete the features
with arcpy.da.SearchCursor(lyr, "SHAPE@", "distance = 500") as cur:
    fullExtent = reduce(arcpy.Geometry.union, [row[0] for row in cur]).extent

# get the Map element of the layout
lyt = aprx.listLayouts()[0]
mf = lyt.listElements()[-1]
 
# set the extent to the selected features' extent
mf.camera.setExtent(fullExtent)
 
# export to PDF
lyt.exportToPDF(lyt.name)

del aprx

Some methods...


The reduce function in Python, which is part of the functools module, is used to iteratively apply a function to the elements of an iterable in a cumulative way. It returns a single accumulated result. 

Here's a simple example using the reduce function to find the product of all elements in a list:

from functools import reduce

# Define a function to multiply two numbers
def multiply(x, y):
    return x * y

# Create a list of numbers
numbers = [1, 2, 3, 4, 5]

# Use reduce to find the product of all numbers in the list
product = reduce(multiply, numbers)

print("Product of the numbers:", product)

In this example, the reduce function applies the multiply function cumulatively to the elements of the numbers list. The result will be the product of all the numbers in the list.

标签:function,product,features,Python,list,reduce,Implementation,numbers,aprx
From: https://www.cnblogs.com/alex-bn-lee/p/17777050.html

相关文章

  • Python + Selenium + Firefox 使用代理 auth 的用户名密码授权
    Python+Firefox+插件(closeproxy.xpi)其中,closeproxy.xpi文件,需要Google、Bing搜下都能搜到下载地址完整的测试代码如下: fromseleniumimportwebdriverfromselenium.webdriver.firefox.firefox_binaryimportFirefoxBinaryfromselenium.webdriver.common.proxyimp......
  • 关于Python的打包与编译
    1、nuitka编译成一个so文件nuitka3--module--include-module=target_file_or_dirtarget_file_or_dir2、compileall编译成pycpython3-mcompileall-b<dir>#删除相关的py文件find<dir>-name'*.py'-typef-print-execrm{}\;3、bdist_wheel打包whl文......
  • Python3+selenium3+Firefox 设置浏览器headless模式运行+下载文件
    设置Firefoxheadless模式   defsetUp(self):#Firefoxheadless模式运行options=webdriver.FirefoxOptions()options.add_argument('-headless')self.driver=webdriver.Firefox(options=options)self.driver.implicitly_wait(30)......
  • Windows Python 访问达梦数据库(环境配置)
    WindowsPython访问达梦数据库(环境配置) 一、前提条件本篇博客以访问本地达梦数据库(DM8)为基础进行演示。(前提:本地已经安装了DM8数据库!)关于Windows安装达梦数据库,请参考博客:Windows安装达梦数据库关于Docker安装达梦数据库,请参考博客:Docker安装达梦数据库关于JD......
  • 【Python&RS】基于Python批量镶嵌拼接遥感影像/栅格数据
    ​    我之前分享过【Python&RS】基于GDAL镶嵌拼接遥感影像,但是没有加入批量处理的代码。最近正好有这个需求,所以就对原来的代码进行了优化加入了批量拼接的代码。现在只需输入一个文件夹即可将其中的影像全部镶嵌起来。 一、导入GDAL库fromosgeoimportgdal二......
  • Python猴子补丁
    Python猴子补丁介绍猴子补丁是一种替换方法的方式。因为python是动态语言,所以我们在方法执行之前,可以将方法替换,以达到我们期望的结果。需要理解的是,python的方法在加上括号之前,代表的的只是方法的内存,可以被当做一个变量进行传递。使用#示例classTest:  a=1 ......
  • [920] Copy the font style from one cell in a table of a Word document to another
    TocopythefontstylefromonecellinatableofaWorddocumenttoanothercellusingPythonandthepython-docxlibrary,youcanaccessthefontpropertiesofthesourcecellandapplythemtothetargetcell.Here'showyoucandoit:First,ma......
  • [915] Implementation of zooming to layer and exporting to PDF in arcpy
    ref:Camera-ArcGISProref:Introductiontoarcpy.mp#Setthepathtoyourprojectfile(.aprx)project_file=r"Map1.3Heritage.aprx"#Referencetheprojectaprx=arcpy.mp.ArcGISProject(project_file)#getthesitebufferlayerm=aprx......
  • python中json模块
    importjsonstring='{"name":"xxx","age":18,"object":[{"数学":100,"语文":90,"英语":70}]}'print(string)print(type(string))#将json字符串转为python字典data_dic=json.loads(string)print......
  • python sys.path介绍
    pythonsys.path介绍介绍当我们导入模块时,python解释器会通过sys.path中的环境变量搜索。sys.path是一个列表,里面包含已添加到环境变量中的路径。使用sys.path.append({路径})可以往里面添加自定义的环境变量。使用当我们想要导入某个文件中的文件失败时,可以将其文件夹路......