摘要
Locator 类可让您修改定位器并将其用于地理编码。地理编码是指将坐标对、地址或地名等位置描述转换为地球表面上某位置的过程。
地理编码模块旨在支持使用创建定位器工具所创建的定位器。使用旧版工具创建的定位器的功能可能有限,且不支持多个属性和参数。
说明
定位器是一个可移植文件,用于执行地理编码,即在地图上查找地址和位置的过程。定位器中包含用于地理编码的参考数据快照,同时还包含索引和局部编址知识,这有助于在地理编码过程中返回最佳匹配项。
定位器可以在您的门户中作为服务访问,例如 ArcGIS World Geocoding Service,将作为通过 AGS 服务器连接访问的服务或作为磁盘上的文件。
语法
Locator (path)
参数 | 说明 | 数据类型 |
path | A path to the locator. | String |
注:
如果您正在使用您的门户上的定位器,请确保您已登录系统并在 ArcGIS Pro 中将其设置为您的活动门户。 要访问除活动门户之外的门户上的定位器,您可以使用 SignInToPortal 进行身份验证:从存储在磁盘上的定位器创建 Locator 对象。
import arcpy
# Create a new Locator object from a locator on disk
locator_path = r"C:\Locators\Atlanta.loc"
locator = arcpy.geocoding.Locator(locator_path)
从 ArcGIS World Geocoding Service 创建 Locator 对象。
import arcpy
# Create a new Locator object from the ArcGIS World Geocoding Service
locator_path = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/ArcGIS World Geocoding Service"
locator = arcpy.geocoding.Locator(locator_path)
从 AGS 连接创建 Locator 对象。
import arcpy
# Create a new Locator object from a locator published to ArcGIS Server
locator_path = r"C:\AGS Files\MyAGSConnectionFile.ags\Atlanta"
locator = arcpy.geocoding.Locator(locator_path)
在您自己的 ArcGIS Enterprise 门户中从定位器项目创建 Locator 对象。
import arcpy
# Create a new Locator object from the locator on your portal
locator_path = "https://myenterpriseportal.esri.com/server/rest/services/Geocode/Atlanta/GeocodeServer/Atlanta"
locator = arcpy.geocoding.Locator(locator_path)
属性
属性 | 说明 | 数据类型 |
capabilities (只读) | 返回可作为服务共享到 ArcGIS Enterprise 或作为地理编码发布到 ArcGIS Server 的定位器可用的功能。 可用功能包括:
该属性仅可用于地理编码服务。 不受本地定位器支持,如果您尝试访问本地定位器的该属性,则会返回错误。 | String |
categories (可读写) | 通过将可以从定位器返回的类别限制为已定义的集合来控制精度。 如果您有一个支持多种地址类型的多角色定位器,则可以修改此设置以排除与某些类型的匹配。 例如,您的定位器可以支持与“点地址”级别、“街道地址”级别、“街道名称”级别和“邮政编码”级别的匹配。 您可能希望排除与“邮政编码”级别的匹配项,因为您认为该级别的匹配项对于您的目的来说太不精确。 此设置可用于控制地理编码体验的精确度。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | String |
defaultSuggestCandidates (可读写) | suggest 方法默认返回的建议候选项数。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | Integer |
endOffset (可读写) | 出于显示目的,将结果从街道要素的末端(朝向中心)偏移的距离(以米为单位)。 有关如何使用 endOffset 属性的详细信息,请参阅末端偏移。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | Double |
intersectionConnectors (可读写) | 交叉点连接符列表,可以是符号或单词,用于覆盖默认交叉点连接符。 交叉点连接符列表应为用引号括起来的逗号分隔列表,例如:"&","|","//","@"。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | String |
matchOutOfRange (可读写) | 用于控制当搜索到的街道编号略微超出构建定位器数据的路段中包含的范围时,是否返回匹配项。 要匹配路段,即使数据中的线段上不存在街道编号,但是街道编号在合理的阈值内并且可能存在,则需将属性设置为 True。 当此属性设置为 True 时,该点位于地址略微超出门牌号范围的路段末端。 这可确保您不会错过潜在的匹配,因为数据不是 100% 最新的。 matchOutOfRange 属性仅适用于支持并返回 StreetAddress 匹配的定位器。 有关 matchOutOfRange 属性的详细信息,请参阅匹配超出范围。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | Boolean |
maxCandidates (可读写) | geocode 方法返回的最大候选项数。 如果您发现地理编码花费了很长时间并且也获得了高质量匹配,请确保未将此属性设置过高。 假设您获得了不错的结果,则可以通过生成更少的结果并专注于前几条结果来提高性能。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | Integer |
maxSuggestCandidates (可读写) | suggest 方法返回的最大建议结果数。 如果您发现 suggest 方法性能较差,则可能是因为定位器生成了大量建议结果。 将此值设置为较小的数字可以提高性能。 有关 maxSuggestCandidates 属性的详细信息,请参阅最大建议候选项数。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | Integer |
minCandidateScore (可读写) | 使结果必须被视为 geocode 操作的匹配候选项的最低得分。 定位器的最低得分是一个介于 0 和 100 之间的值。仅包括达到或超过 geocode 方法返回的最小候选得分的候选项。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | Integer |
minMatchScore (可读写) | 使 geocode 方法的结果必须视为匹配的最小得分。 最低得分是一个阈值,用于控制地址与参考数据中最有可能被视为匹配项的候选项的必须匹配程度。 如果潜在候选项低于阈值,则地址与候选项不匹配。 定位器的最低匹配得分是一个介于 0 和 100 之间的值。 完全匹配的得分是 100。 如果工作流需要置信度较高的匹配地址,请将属性设置为更高的阈值。 较高的设定值可确保仅返回质量最高的匹配项。 要尽可能得到更多的可匹配地址而不介意某些地址可能存在匹配错误,则使用较低的阈值设置。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | Integer |
multilineInputFields (只读) | 用于多行地理编码的定位器字段。 此属性针对定位器的多行输入字段返回 arcpy.Field 对象列表。 对表进行地理编码时,可以将多行地理编码表字段 映射到 Field 对象的 name 属性。 | Field |
numberOfThreads (可读写) | 用于进行批量地理编码的线程数。 为了最大程度地使用此设置,请考虑使用哪台计算机进行地理编码,并确定计算机上可用于地理编码作业的可用核数。 地理编码能够利用计算机上的所有核更快地完成地理编码作业。 默认情况下,此值设置为较小的值以在任何计算机上运行(无论计算机上可用的内核数是多少),但如果您知道可用的内核数,则可以进行配置以使用更多内核。 可以将其设置为 Auto,以检测计算机上的核并优化计算机的线程数,或者如果您知道需要保留一些其他应用程序可用的其他资源,则可以选择将指定数量的核用于地理编码。 如果您计划将定位器共享至 ArcGIS Enterprise,则建议您将此属性设置为 4。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | Integer |
partialSubaddressSuggestions (可读写) | 确定当仅使用部分子地址值作为输入时,suggest 方法是否返回子地址。 有关如何使用 partialSubaddressSuggestions 属性的详细信息,请参阅针对部分子地址的建议。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | Boolean |
sideOffset (可读写) | 出于显示目的,将结果偏移到街道要素的一侧的距离(以米为单位)。 有关如何使用 sideOffset 属性的详细信息,请参阅单侧偏移。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | Double |
singleLineInputField (只读) | 用于单行地理编码的定位器字段。 此属性可返回代表定位器的单行输入字段的 arcpy.Field 对象。 对表进行地理编码时,可以将单行地理编码表字段 映射到 Field 对象的 name 属性。 | Field |
spatialReference (只读) | 定位器的空间参考。 空间参考将与用于创建定位器的数据相同。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | String |
supportedCategories (只读) | 定位器支持的类别。 有关可用于自定义构建定位器和 ArcGIS StreetMap Premium 定位器的受支持的类别的详细信息,请参阅支持的类别。 | String |
supportedCountries (只读) | 定位器支持的国家/地区。 | String |
supportedRoles (只读) | 定位器支持的角色。 | String |
reverseGeocodeFeatureTypes (可读写) | reverseGeocode 方法支持的要素类型。 有关 reverseGeocodeFeatureTypes 属性的详细信息,请参阅支持反向地理编码的要素。 对于地理编码服务,此属性是只读的。 要在已发布的定位器中更改此属性,请在本地进行修改,然后再次发布您的定位器。 注:此属性仅设置为运行时属性。 除非您使用 updateLocator 方法,否则该属性不会保存至当前会话之外的定位器。 | String |
方法概述
方法 | 说明 |
geocode (searchText, forStorage, {preferredSearchLocation}, {countryCode}, {categories}, {locationType}, {outFields}, {maxResults}, {minScore}, {outputLanguageCode}, {searchExtent}) |
以地址或位置作为输入,并返回地理编码结果候选项。结果候选项是可以在地图上显示或用作其他分析的输入的点。 |
reverseGeocode (location, forStorage, {featureTypes}, {locationType}, {outputLanguageCode}) |
以 PointGeometry 对象作为输入,并返回最接近的地址、兴趣点或与该点的交叉点。结果是反向地理编码结果,其中包含有关匹配地址或位置的信息、包括 x 坐标和 y 坐标的几何信息以及其他属性(取决于使用的 Locator)。 |
suggest (searchText, {preferredSearchLocation}, {countryCode}, {categories}, {maxResults}, {searchExtent}) | 为不完整或部分用户输入生成自动完成建议。 单个建议结果可被传递至 geocodeWithSuggest 方法,以生成可在地图上显示或用作其他分析的输入的点。 |
geocodeWithSuggest (suggestResult, forStorage, {preferredSearchLocation}, {countryCode}, {categories}, {locationType}, {outFields}, {maxResults}, {minScore}, {outputLanguageCode}, {searchExtent}) | 以单个 suggest 方法结果作为输入,并返回地理编码结果候选项。结果候选项是可以在地图上显示或用作其他分析的输入的点。 建议您将相同参数传递至在生成 suggest 方法结果时传递至 geocodeWithSuggest 的方法,这将用来获得一致的结果。 |
updateLocator () | 保留在与定位器的当前 Python 会话期间对 Locator 属性进行的更改,以便应用这些属性以供未来使用。 |
方法
geocode (searchText, forStorage, {preferredSearchLocation}, {countryCode}, {categories}, {locationType}, {outFields}, {maxResults}, {minScore}, {outputLanguageCode}, {searchExtent})
参数 | 说明 | 数据类型 |
searchText | An address or place-name to find the location of. | String |
forStorage | Specifies whether the results will be persisted. The default value is False, which indicates the results can't be stored, but they can be temporarily displayed on a map, for instance. If you store the results, in a database, for example, set this parameter to True. This parameter only applies to geocoding requests made with ArcGIS World Geocoding Service. For all other locators, the parameter is ignored. 注:Applications are contractually prohibited from storing the results of geocoding operations using ArcGIS World Geocoding Service unless they make the request by passing the forStorage parameter with a value of True. For a Locator using ArcGIS World Geocoding Service to be valid, you must log in to ArcGIS Online with a valid organizational account. ArcGIS Online service credits are deducted from the organizational account for each geocode transaction. | Boolean |
preferredSearchLocation | An origin point that is used to prefer or boost geocoding candidates based on their proximity to the location. Candidates near the location are prioritized relative to those farther away. | PointGeometry |
countryCode | A comma-delimited string of three-character country codes that limits geocoding results to the set of specified countries, which will improve the accuracy of geocoding in most cases. When no country is specified, geocoding with suggestions is performed against all countries supported by the locator. If you are using ArcGIS World Geocoding Service, refer to this list of supported countries. | String |
categories | A comma-separated list of categories that limits the types of places the locator searches, thus eliminating false positive matches and potentially speeding up the search process. See the REST API web help for details about category filtering. | String |
locationType | Specifies the preferred output location forPointAddress matches. If the preferred location does not exist in the data, the default location will be returned instead. For geocode results with Addr_type=PointAddress, the x,y attribute values describe the coordinates of the address along the street, while the DisplayX and DisplayY values describe the rooftop, or building centroid, coordinates. This argument only affects the geometry, not the attribute values.
| String |
outFields | The list of fields to be returned as part of the attributes in the result. This parameter supports a single field name or a comma-delimited string of field names (without spaces). To return the default output fields, outFields does not need to be passed. Use an asterisk ("*") to return all available output fields with the result. The output fields are described in What's included in the geocoded results. | String |
maxResults | The maximum number of locations, up to the maximum number allowed by the Locator. If not specified, all matching candidates up to the maximum specified in the Locator properties are returned. | Integer |
minScore | Limits the candidates that are returned to those with a score above the value set for this property. The value should be between 0 and 100. | Integer |
outputLanguageCode | The language in which the geocode results are returned. Since addresses and places in many countries are available in more than one language, this ensures that results are returned in the expected language. If you are using ArcGIS World Geocoding Service, refer to the list of supported countries to see what language codes are supported for those countries. | String |
searchExtent | An extent that limits the area to be searched. All results that are returned outside of the specified extent are excluded. | Extent |
数据类型 | 说明 |
List | geocode 操作的输出是字典对象的列表。 每个字典对象代表一个地理编码结果。 每个地理编码结果都包含有关匹配地址或位置的信息,包括 x 坐标和 y 坐标的几何信息以及其他属性,具体取决于所使用的 Locator 和指定的 outFields。 |
注:
如果您正在使用您的门户上的定位器,请确保您已登录系统并在 ArcGIS Pro 中将其设置为您的活动门户。 要访问除活动门户之外的门户上的定位器,您可以使用 SignInToPortal 进行身份验证:用来使用磁盘上的定位器查找地点位置或地址的地理编码。
import arcpy
# Create a new Locator object from a locator on disk
locator_path = r"C:\Locators\Atlanta.loc"
locator = arcpy.geocoding.Locator(locator_path)
# Geocode to find the location of an address
geocoding_candidates = locator.geocode("1670 W Peachtree St NE, Atlanta, GA 30309", False)
用来使用 ArcGIS World Geocoding Service 查找地点位置或地址的地理编码。
import arcpy
# Create a new Locator object from the ArcGIS World Geocoding Service
locator_path = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/ArcGIS World Geocoding Service"
locator = arcpy.geocoding.Locator(locator_path)
# Geocode to find the location of an address
geocoding_candidates = locator.geocode("1670 W Peachtree St NE, Atlanta, GA 30309", True)
用来使用通过 AGS 连接访问的定位器查找地点位置或地址的地理编码。
import arcpy
# Create a new Locator object from a locator published to ArcGIS Server
locator_path = r"C:\AGS Files\MyAGSConnectionFile.ags\Atlanta"
locator = arcpy.geocoding.Locator(locator_path)
# Geocode to find the location of an address
geocoding_candidates = locator.geocode("1670 W Peachtree St NE, Atlanta, GA 30309", False)
reverseGeocode (location, forStorage, {featureTypes}, {locationType}, {outputLanguageCode})
参数 | 说明 | 数据类型 |
location | A point for which you want to find the nearest address, point of interest, or intersection. | PointGeometry |
forStorage | Specifies whether the results will be persisted. The default value is False, which indicates the results can't be stored, but they can be temporarily displayed on a map, for instance. If you store the results, in a database, for example, set this parameter to True. This parameter only applies to geocoding requests made with ArcGIS World Geocoding Service. For all other locators, the parameter is ignored. 注:Applications are contractually prohibited from storing the results of geocoding operations using ArcGIS World Geocoding Service unless they make the request by passing the forStorage parameter with a value of True. For a Locator using ArcGIS World Geocoding Service to be valid, you must log in to ArcGIS Online with a valid organizational account. ArcGIS Online service credits are deducted from the organizational account for each geocode transaction that includes the forStorage parameter with a value of True. (默认值为 False) | Boolean |
featureTypes | Specify one or more match types to be returned. If only one value is specified, the search tolerance is adjusted. For more information on how this argument is used in ArcGIS World Geocoding Service, refer to the REST API documentation. | String |
locationType | Specifies the preferred output location. If the preferred location does not exist in the data, the default location will be returned instead. For reverse geocoding results with Addr_type=PointAddress, the x,y attribute values describe the coordinates of the address along the street, while the DisplayX and DisplayY values describe the rooftop, or building centroid, coordinates. For more information about this parameter, reference the information on the parameter in the Reverse Geocode REST API documentation. This argument only affects the geometry, not the attribute values.
| String |
outputLanguageCode | The language in which the reverse geocode results are returned. Since addresses and places in many countries are available in more than one language, this will ensure that results are returned in the expected language. If you are using ArcGIS World Geocoding Service, refer to the list of supported countries to see what language codes are supported for those countries. | String |
数据类型 | 说明 |
List | 反向地理编码结果包含有关匹配地址或位置的信息,包括 x 和 y 坐标的几何信息以及其他属性,具体取决于使用的 Locator,以及值是 PointGeometry 对象的 Shape 键。 |
注:
如果您正在使用您的门户上的定位器,请确保您已登录系统并在 ArcGIS Pro 中将其设置为您的活动门户。 要访问除活动门户之外的门户上的定位器,您可以使用 SignInToPortal 进行身份验证:通过反向地理编码以使用磁盘上的定位器查找到给定位置的最近地点或地址。
import arcpy
# Create a new Locator object from a locator on disk
locator_path = r"C:\Locators\Atlanta.loc"
locator = arcpy.geocoding.Locator(locator_path)
# Create input PointGeometry object
spatial_reference = arcpy.SpatialReference(4326)
point = arcpy.Point(-84.374, 33.797)
point_geometry = arcpy.PointGeometry(point, spatial_reference)
# Reverse geocode to find the nearest address or place to the point
reverse_geocode_result = locator.reverseGeocode(point_geometry, False)
反向地理编码以使用 ArcGIS World Geocoding Service 查找到给定位置的最近地点或地址。
import arcpy
# Create a new Locator object from the ArcGIS World Geocoding Service
locator_path = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/ArcGIS World Geocoding Service"
locator = arcpy.geocoding.Locator(locator_path)
# Create input PointGeometry object
spatial_reference = arcpy.SpatialReference(4326)
point = arcpy.Point(-84.374, 33.797)
point_geometry = arcpy.PointGeometry(point, spatial_reference)
# Reverse geocode to find the nearest address or place to the point
geocoding_candidates = locator.reverseGeocode(point_geometry, True)
通过地理编码以使用 AGS 连接查找到给定位置的最近地点或地址。
import arcpy
# Create a new Locator object from a locator published to ArcGIS Server
locator_path = r"C:\AGS Files\MyAGSConnectionFile.ags\Atlanta"
locator = arcpy.geocoding.Locator(locator_path)
# Create input PointGeometry object
spatial_reference = arcpy.SpatialReference(4326)
point = arcpy.Point(-84.374, 33.797)
point_geometry = arcpy.PointGeometry(point, spatial_reference)
# Reverse geocode to find the nearest address or place to the point
geocoding_candidates = locator.reverseGeocode(point_geometry, False)
suggest (searchText, {preferredSearchLocation}, {countryCode}, {categories}, {maxResults}, {searchExtent})
参数 | 说明 | 数据类型 |
searchText | The partial text for which you want to generate suggestions. | String |
preferredSearchLocation | An origin point that is used to prefer or boost suggestion candidates based on their proximity to the location. Candidates near the location are prioritized relative to those farther away. | PointGeometry |
countryCode | A comma-delimited string of three-character country codes that limits suggestion results to the set of specified countries, which will improve the accuracy of suggestions in most cases. When no country is specified, suggestions are generated from all countries supported by the locator. If you are using ArcGIS World Geocoding Service, refer to the list of supported countries in Geocode coverage. | String |
categories | A comma-separated list of categories that limits the types of places for which the locator generates suggestions, thus eliminating false positive matches and potentially speeding up the process. See the REST API web help for details about category filtering. | String |
maxResults | The maximum number of suggestions to be returned, up to the maximum number allowed by the Locator. If not specified, all matching suggestions up to the maximum specified in the Locator maxSuggestCandidates property are returned. | Integer |
searchExtent | An extent that limits the area to be searched. All results that are returned outside of the specified extent are excluded. | Extent |
数据类型 | 说明 |
List | suggest 方法的输出是字典对象的数组。 每个字典代表一个建议结果。 每个建议结果均包含以下关键字:text、magicKey 和 isCollection。 要使用 suggest 方法的输出,应将所需列表索引处的整个字典传递至 geocodeWithSuggest 方法。 注:要了解有关字典键值的详细信息,请参阅 REST API 文档。 |
注:
如果您正在使用您的门户上的定位器,请确保您已登录系统并在 ArcGIS Pro 中将其设置为您的活动门户。 要访问除活动门户之外的门户上的定位器,您可以使用 SignInToPortal 进行身份验证:使用磁盘上的定位器根据不完整的用户输入字符串生成建议。
import arcpy
# Create a new Locator object from a locator on disk
locator_path = r"C:\Locators\Atlanta.loc"
locator = arcpy.geocoding.Locator(locator_path)
# Generate suggestions from partial user input
suggestion_candidates = locator.suggest("1670 w peach")
使用 ArcGIS World Geocoding Service 根据不完整的用户输入字符串生成建议。
import arcpy
# Create a new Locator object from the ArcGIS World Geocoding Service
locator_path = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/ArcGIS World Geocoding Service"
locator = arcpy.geocoding.Locator(locator_path)
# Generate suggestions from partial user input
suggestion_candidates = locator.suggest("1670 w peach")
使用通过 AGS 连接访问的定位器,根据不完整的用户输入字符串生成建议。
import arcpy
# Create a new Locator object from a locator published to ArcGIS Server
locator_path = r"C:\AGS Files\MyAGSConnectionFile.ags\Atlanta"
locator = arcpy.geocoding.Locator(locator_path)
# Generate suggestions from partial user input
suggestion_candidates = locator.suggest("1670 w peach")
geocodeWithSuggest (suggestResult, forStorage, {preferredSearchLocation}, {countryCode}, {categories}, {locationType}, {outFields}, {maxResults}, {minScore}, {outputLanguageCode}, {searchExtent})
参数 | 说明 | 数据类型 |
suggestResult | The output from the suggest method is used to locate an address or place. The suggestion result is a dictionary that contains text, magicKey, and isCollection keys. To learn more about the keys included in the suggestion result dictionary objects, refer to the REST API documentation. | Dictionary |
forStorage | Specifies whether the results will be persisted. The default value is False, which indicates the results of the operation can't be stored, but they can be temporarily displayed on a map, for instance. If you store the results, in a database, for example, set this parameter to True. This parameter only applies to geocoding requests made with ArcGIS World Geocoding Service. For all other locators, the parameter is ignored. Applications are contractually prohibited from storing the results of geocoding operations using ArcGIS World Geocoding Service unless they make the request by passing the forStorage parameter with a value of True. For a Locator using ArcGIS World Geocoding Service to be valid, you must log in to ArcGIS Online with a valid organizational account. ArcGIS Online service credits are deducted from the organizational account for each geocode transaction that stores results. | Boolean |
preferredSearchLocation | An origin point that is used to prefer or boost geocoding candidates based on their proximity to the location. Candidates near the location are prioritized relative to those farther away. | PointGeometry |
countryCode | A comma-delimited string of three-character country codes that limits geocoding results to the set of specified countries, which will improve the accuracy of geocoding in most cases. When no country is specified, geocoding with suggestions is performed against all supported countries of the locator. If you are using ArcGIS World Geocoding Service, refer to this list of supported countries. | String |
categories | A comma-separated list of categories that limits the types of places the locator searches, thus eliminating false positive matches and potentially speeding up the search process. See the REST API web help for details about category filtering. | String |
locationType | Specifies the preferred output geometry forPointAddress matches. If the preferred location does not exist in the data, the default location will be returned instead. For geocode results with Addr_type=PointAddress, the x,y attribute values describe the coordinates of the address along the street, while the DisplayX and DisplayY values describe the rooftop, or building centroid, coordinates. This argument only affects the geometry, not the attribute values.
| String |
outFields | The list of fields to be returned as part of the attributes in the result. This parameter supports a single field name or a comma-delimited string of field names (without spaces). To return the default output fields, outFields does not need to be passed. Use an asterisk ("*") to return all available output fields with the result. The output fields are described in What's included in the geocoded results. | String |
maxResults | The maximum number of locations, up to the maximum number allowed by the Locator. If not specified, all matching candidates up to the maximum specified by the maxCandidate property in the Locator properties are returned. | Integer |
minScore | Limits the candidates that are returned to those with a score above the value set for this property. The value should be between 0 and 100. | Integer |
outputLanguageCode | The language in which the geocode results are returned. Since addresses and places in many countries are available in more than one language, this will ensure that results are returned in the expected language. If you are using ArcGIS World Geocoding Service, refer to the list of supported countries to see what language codes are supported for those countries. | String |
searchExtent | An extent that limits the area to be searched. All results that are returned outside of the specified extent are excluded. | Extent |
数据类型 | 说明 |
List |
geocodeWithSuggest 方法的输出是字典对象的列表。 每个字典代表一个地理编码结果。 每个地理编码结果都包含有关匹配地址或位置的信息,包括 x 坐标和 y 坐标的几何信息以及其他属性,具体取决于所使用的 Locator 和指定的 outFields。 |
注:
如果您正在使用您的门户上的定位器,请确保您已登录系统并在 ArcGIS Pro 中将其设置为您的活动门户。 要访问除活动门户之外的门户上的定位器,您可以使用 SignInToPortal 进行身份验证:根据不完整的用户输入字符串生成建议,并使用生成的建议之一作为该操作的输出来进行地理编码,以使用磁盘上的定位器查找位置。
import arcpy
# Create a new Locator object from a locator on disk
locator_path = r"C:\Locators\Atlanta.loc"
locator = arcpy.geocoding.Locator(locator_path)
# Generate suggestions from partial user input
suggestion_candidates = locator.suggest("1670 w peach")
# Geocode using one of the suggestions generated as the output of the suggest
# operation
geocoding_candidates = locator.geocodeWithSuggest(suggestion_candidates[0], False)
根据不完整的用户输入字符串生成建议,并使用生成的建议之一作为该操作的输出来进行地理编码,以使用 ArcGIS World Geocoding Service 查找位置。
import arcpy
# Create a new Locator object from the ArcGIS World Geocoding Service
locator_path = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/ArcGIS World Geocoding Service"
locator = arcpy.geocoding.Locator(locator_path)
# Generate suggestions from partial user input
suggestion_candidates = locator.suggest("1670 w peach")
# Geocode using one of the suggestions generated as the output of the suggest
# operation
geocoding_candidates = locator.geocodeWithSuggest(suggestion_candidates[0], True)
根据不完整的用户输入字符串生成建议,并使用生成的建议之一作为该操作的输出来进行地理编码,以使用通过 AGS 连接访问的定位器查找位置。
import arcpy
# Create a new Locator object from a locator published to ArcGIS Server
locator_path = r"C:\AGS Files\MyAGSConnectionFile.ags\Atlanta"
locator = arcpy.geocoding.Locator(locator_path)
# Generate suggestions from partial user input
suggestion_candidates = locator.suggest("1670 w peach")
# Geocode using one of the suggestions generated as the output of the suggest
# operation
geocoding_candidates = locator.geocodeWithSuggest(suggestion_candidates[0], False)
updateLocator ()
更新磁盘上定位器的属性,并保留更改。
import arcpy
# Create a new Locator object from a locator on disk
locator_path = r"C:\Locators\Atlanta.loc"
locator = arcpy.geocoding.Locator(locator_path)
# Update the minimum match score property on the locator
locator.minMatchScore = 95
# Persist changes to the .loc file
locator.updateLocator()