ArcGIS Server从入门到精通
生产环境的部署
测试环境的部署
开发环境的部署
ArcGIS Server类似于一个Tomcat服务器或者是Jetty服务器,它可以和它们同时运行 发布服务接口 如REST服务 Feature Service服务 WMS服务 Mapping服务。。矢量服务 栅格服务 等等。
如何获取Fields?:
MapService:https://developers.arcgis.com/rest/services-reference/map-service.htm
REST Domain查询&REST Fields查询
2.查询图层属性字段:/arcgis/rest/services/LightweightProduct/轻量级管网产品/MapServer/layers?f=pjson
https://developers.arcgis.com/rest/services-reference/all-layers-and-tables.htm
https://developers.arcgis.com/labs/rest/search-for-an-address/
Search for an address
Find addresses and places with the ArcGIS World Geocoding Service.
Overview
You will learn: how to find addresses and places with the ArcGIS World Geocoding Service.
The ArcGIS World Geocoding Service can find addresses, places, convert addresses to coordinates, and perform batch geocoding. If you would like to create an application that can find the coordinates (latitude and longitude) for one or more addresses, you can use the ArcGIS REST API to call the findAddressCandidates
operation. All you need to do is pass in an address e.g. "380 New York St., Redlands, CA" and the service will return a set of candidates. Once you have candidates, you can add them to a map, create a route, or integrate them further into your application. You can also geocode many addresses at once with the geocodeAddresses
operation. To learn more about the capabilities of the geocoding service, please visit the documentation.
In this tutorial you will use the ArcGIS REST API to access the ArcGIS World Geocoding Service to find the coordinates for an address.
Before you begin
Install Postman to execute HTTP requests. Go to this tutorial if you need an access token.
Steps
Create a request to access the geocoding service
-
Open Postman and click [+] in the tab bar to create a new request.
-
In the new tab, set the following:
- HTTP Method:
GET
- Request URL:
https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates
Add parameters to define the address and data fields to return
-
Click on Params next to the URL and the following:
f
: json
singleLine
: 4730 Crystal Springs Dr, Los Angeles, CA 90027
outFields
: Match_addr,Addr_type
Execute the request to geocode the address and get the coordinate candidates
-
Click Send to run the request.
-
In the response window, click Pretty > JSON and it should look something like this:
{
"spatialReference": {
"wkid": 4326,
"latestWkid": 4326
},
"candidates": [
{
"address": "4730 Crystal Springs Dr, Los Angeles, California, 90027",
"location": {
"x": -118.27393677823306,
"y": 34.123473000000004
},
"score": 100,
"attributes": {
"Match_addr": "4730 Crystal Springs Dr, Los Angeles, California, 90027",
"Addr_type": "PointAddress"
},
"extent": {
"xmin": -118.27486,
"ymin": 34.122473000000006,
"xmax": -118.27285999999999,
"ymax": 34.124473000000002
}
},
{
"address": "4730 Crystal Springs Rd, Los Angeles, California, 90027",
"location": {
"x": -118.29234632205821,
"y": 34.140621986664307
},
"score": 98.040000000000006,
"attributes": {
"Match_addr": "4730 Crystal Springs Rd, Los Angeles, California, 90027",
"Addr_type": "StreetAddress"
},
"extent": {
"xmin": -118.29334632205821,
"ymin": 34.139621986664309,
"xmax": -118.2913463220582,
"ymax": 34.141621986664305
}
}
]
}
-
Go to the top of the response and find the spatialReference
and candidates
properties. The spatialReference
is 4326 and tells you that the coordinates given in candidates
will be latitude/longitude coordinates (y/x). This is the default spatial reference.
{
"spatialReference": {
"wkid": 4326,
"latestWkid": 4326
},
...
-
Find the candidates
property. This is an array of possible matches for the address. Each match consists of:
address
: The address of this match.
location
: The x/y coordinates of this match. Note that x is longitude and y is latitude.
score
: The confidence level of the geocoder in this match, on a scale of 1-100.
attributes
: Any additional fields requested by the outFields
parameter.
extent
: a rectangular bounding box around the location
given as a pair of x/y coordinates.
"candidates": [
{
"address": "4730 Crystal Springs Dr, Los Angeles, California, 90027",
"location": {
"x": -118.27393677823306,
"y": 34.123473000000004
},
"score": 100,
"attributes": {
"Match_addr": "4730 Crystal Springs Dr, Los Angeles, California, 90027",
"Addr_type": "PointAddress"
},
"extent": {
"xmin": -118.27486,
"ymin": 34.122473000000006,
"xmax": -118.27285999999999,
"ymax": 34.124473000000002
}
},
...
- In Postman click Code below the Send button. Select a programming language and use Postman to generate sample code for your application to run this request.
Congratulations, you're done!
You have successfully found a set of candidates with coordinates for an address.
Challenge
Use geocoding suggestions
You can use the Esri World Geocoding Service to build an auto-completing, suggestion-based UX by adding a special parameter called magicKey
to findAddressCandidates
instead of an address. To obtain a value for magicKey
, refer to the documentation for the suggest endpoint.
Try bulk geocoding
If you need to geocode many addresses in bulk, you can use the geocode addresses endpoint.
Find latitude/longitude of intersections
findAddressCandidates
can also return the coordinates of intersections if the address is in the proper format. For more information, see searching for intersections and try changing the value of singleLine
to "Grasswood Ave & Cliffside Dr, Malibu, CA, 90265, USA"
Get started
To successfully use the ArcGIS REST API, you must understand how to construct a URL and interpret the response. All resources and operations exposed by the ArcGIS Services portion of the REST API are accessible through a hierarchy of endpoints for each GIS service published with ArcGIS Server.
Determine the well-known endpoint
When using the REST API, you must know the well-known endpoint, which represents a server catalog.
For ArcGIS Server, the default endpoint is as follows:
https://<host>/<site>/rest/services/<folder>/<serviceName>/<serviceType>
Where:
- https://<host> is the ArcGIS Server host name.
- /<site> is the site name. The default value is "/arcgis/". ArcGIS Server accepts a site name specified in a URL as lowercase (arcgis) or camel case (ArcGIS). Using an all lowercase site name is recommended.
- rest/services indicates the REST services endpoint. You'll see a list of all services in the root directory along with any folders. This part of the URL is case sensitive and should be specified in all lowercase.
- /<folder> lists all services included in this folder. Folder names are case sensitive and should be specified in the case in which it was created.
- /<serviceName>/<serviceType> represents the name of the service and its type (for example, PopulationDensity/MapServer). The service name is case sensitive and should be specified in the case in which it was created. The service type should always be specified in a mixed case format as defined for each service in the REST API reference (for example, MapServer, GeocodeServer, and GPServer).
For example, to get to the root directory of Sample Server 1 on ArcGIS Online services, the URL is as follows:
https://sampleserver1.arcgisonline.com/arcgis/rest/services
When using the REST API, you need to construct URLs. The Services Directory can help you generate URLs that include the reference to a resource as well as any parameters. A URL with parameters will have the following syntax:
https://<resource-url>/<operation>?<parameter1=value1>&<parameter2=value2>
Where:
- https://<resource-url> is the URL to a given resource. If the resource is a server object extension or a geoprocessing service task, the resource name is case sensitive.
- <Operation> represents the name of an operation supported on a resource. The operation name is not case sensitive, but it's recommended that you use the operation name as specified in the REST API.
- ? denotes the beginning of a parameter list.
- parameter1=value1 is a name-value pair. The parameter values are case sensitive if the value is JSON or enumeration.
Almost all resources have an f parameter. This parameter determines the output format. For more information, see Output formats.
To retrieve information about a map service in a JSON object, you would use a URL similar to the following:
https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer?f=json
The JSON response looks similar to the following:
In another example, you can request to export a map. In this case, you would use the map service export operation. For this operation, you need to include the bbox parameter. Some parameters are optional and some are required. These requirements are noted in the documentation. An example URL is as follows:
https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/export?bbox=-185.3,-28.8,-59.5,118.1
The above URL returns the response in HTML format, and you see an image along with its width, height, extent, and scale. If you want the same information returned in a JSON object, you need to include the fparameter:
https://myserver/arcgis/rest/services/maps/world/MapServer/export?bbox=-197.99999664046,-131.792384313038,197.99999664046,125.388423131397&f=json
The response looks similar to the following:
{"href":"https://sampleserver1.arcgisonline.com/arcgisoutput/_ags_map77043d465f5547f09c5b.png",
"width":400,
"height":400,
"extent":{"xmin":-195.85,"ymin":-28.8,"xmax":-48.95,"ymax":118.1,"spatialReference":{"wkid":4269}},
"scale":154341679.023927}
If you want the JSON object response to be more readable, you can use pjson. This option should only be used for debugging purposes, since it takes longer to process the response.
https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/export?bbox=-185.3,-28.8,-59.5,118.1 &f=pjson
{
"href" : "https://sampleserver1.arcgisonline.com/arcgisoutput/_ags_mape8e1ca53a24a477380c7c9940e7b073d.png",
"width" : 400,
"height" : 400,
"extent" : {
"xmin" : -195.85,
"ymin" : -28.8,
"xmax" : -48.95,
"ymax" : 118.1,
"spatialReference" : {
"wkid" : 4269
}
},
"scale" : 154341679.023927
}
上面的mapserver就是动态地图服务的意思。生成动态栅格地图。export表示输出操作。
Use the Services Directory dialog boxes to generate parameter values in the URL
The Services Directory includes dialog boxes for all valid operations with a resource. These dialog boxes allow you to input values for URL parameters for testing purposes. The response includes the results and an encoded URL.
As an example, view the find dialog box for a USA service on sampleserver1:
https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/find
When you provide this URL or browse to this URL in the Services Directory, you'll see the following dialog box:
对话框中的每个字段都是find操作的URL参数之一。Find主题包含对每个参数有效的示例值。在下面的示例中,在美国地图服务的states图层上执行查找操作。搜索文本是纽约。只搜索图层1(状态),并请求返回几何图形。查找结果以HTML格式返回。
点击find(GET)按钮之后,注意浏览器地址栏的地址:你会发现,之前你在对话框中输入的值在URL中显示为字段=参数。
https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/find?searchText=New+York&contains=true&searchFields=&sr=&layers=1&layerdefs=&returnGeometry=true&maxAllowableOffset=&f=HTML
请求的许多字符必须在URL中编码。编码用十六进制值替换某些特殊字符。Services目录(作为一个基于浏览器的应用程序)对URL进行编码,但是您需要在你的应用中自己进行编码。如下的示例显示了一个URL,其中对许多空格、逗号、花括号、冒号和其他字符进行了编码:
https://myserver/arcgis/rest/services/maps/world/MapServer/identify?geometryType=esriGeometryPoint&geometry=%7Bx%3A+-104%2C+y%3A+35.6%7D&sr=&layers=&tolerance=&mapExtent=-104%2C35.6%2C-94.32%2C41&imageDisplay=600%2C400%2C96&returnGeometry=true
注意,除非另有说明,restapi文档中的URL示例以未编码的形式显示,以提高可读性。
Understand options for sending long JSON objects in a request(了解在请求中发送长JSON对象的选项)
当使用REST API时,通常在表单中使用HTML GET方法。当你使用GET时,整个请求都被编码在URL中。这是尽可能使用的首选方法。但是,在这种模式下,URL被限制为1024个字符,具体取决于浏览器。因此,如果请求中包含一个长JSON对象,则需要使用POST方法。
A second option, when using certain geometry service and geoprocessing service operations, is to continue to use GET and to specify a URL to the input JSON object contained in a file on a public server.
第二种情况,当你使用某些几何服务和地理处理服务操作时,仍然使用GET并且指定一个JSON对象文件的URL。
Syntax: geometries={ "url" : "<URL to file>" }
Example: geometries={ "url" : "https://myserver/mygeometries/afile.txt" }
https://myserver/arcgis/rest/services/Geometry/GeometryServer/project?inSR=4326&outSR=54004&geometries={ "url" : "https://myserver/mygeometries/afile.txt" }
例如:http://localhost:8080/arcgis_js_api/政府.txt
When making a POST request to an operation that involves uploading a file, such as addAttachment for feature services, specify the content type as multipart/form-data. For all other POST requests, specify the content type as application/x-www-form-urlencoded.
当对涉及到上传文件操作发送POST请求时,例如addAttachment,指定内容类型为multipart/form-data。对于其他的POST请求,指定内容类型为application/x-www-form-urlencoded。
What's new in the ArcGIS REST API(ArcGIS REST API的新增功能)