2

I was trying to extract data from an ESRI map embedded in a website. The objective would be by introducing geographic coordinates to be able to access the values ​​present on the map.

I leave here a print of the map and the respective address. I just cannot understand which method I should use since the map is embedded in the site. What processes should I use?

*for academic purposes

https://zonamentopf.portaldasfinancas.gov.pt/simulador/default.jsp

enter image description here

1
  • 3
    The easiest way is probably to just contact the site owner and ask if you can get a copy of the data. In any case, asking if it's OK to use their data would be polite, if not actually required. The mapservice does not contain a copyright notice, but that doesn't mean it's open data
    – Berend
    Apr 20, 2021 at 10:23

1 Answer 1

5

What I usually do is look at the requests made by the browser. Press F12 to open the 'developer tools', and then select the Network tab. (I'm not sure if the names are the same in different browsers, but they all behave quite similar in any case)

When zooming around the map, you will see many requests that go to server.arcgisonline.com and services.arcgisonline.com, these are just the (imagery) background tiles and can be ignored. When you zoom in sufficiently, you will also see requests like this:

https://zonamentopf.portaldasfinancas.gov.pt/simulador/proxy.jsp?http://ags/arcgis/rest/services/SIMIMI/SIMIMI/MapServer/export?dpi=96&transparent=true&format=png8&layers=show%3A1&bbox=-946807.1692328664%2C4890281.264462542%2C-931806.4024319208%2C4901364.633563878&bboxSR=102100&imageSR=102100&size=785%2C580&f=image

There are some things to note here:

  1. A proxy is used (proxy.jsp). The actual ArcGIS service is in this case not accessible from outside, but only through this proxy. Everything you want to get from the service has to go through this
  2. This is a request used to generate a PNG image of the current map extent for this particular service (note the part that says MapServer/export). If you need the actual data, you'll need to modify the request, see below
  3. If you try to open this URL in a separate browser tab, it will give an error about an invalid 'referer'. The referer will be set by the browser to the URL of the current page. The easiest way to get around this is to use a tool such as Postman, and manually add a Referer header to the request

To get to the actual data (not an image) of this service, you need some knowledge about how to access an ArcGIS mapservice. In particular, you need to know how to query a layer: https://developers.arcgis.com/rest/services-reference/query-map-service-layer-.htm

Here's an example:

This service has 5 layers (Comércio, Habitação, Indústria, Serviços and Terrenos). Let's say you want data from the first one (index 0). A typical request would look like this: http://ags/arcgis/rest/services/SIMIMI/SIMIMI/MapServer/0/query?f=json&where=1%3D1 (Of course this needs to be prefixed with the proxy url, and properly escaped)

This example will return the data of the first layer of this service in JSON format (KMZ and geojson are also available) with a where clause of 1=1, which basically means everything, but since this parameter is required you need to set it to something. Usually the number of returned records in a single request is limited by ArcGIS Server, so you'll only get 500 or 1000 records. If you need more, you should play around with the where, e.g. one request with objectid<1000, one with objectid>=1000 and objectid<2000 etcetera.

14
  • Thank you very much, what a complete response ! When i add the Host key to Headers i can not get any response ! Why? sorry for the amount of doubts ... Apr 20, 2021 at 13:05
  • My goal is to extract the coordinates of the respective polygons and their value, but I am managing to get it, regardless of introducing the header ... Sorry for my lack of knowledge in this field! Apr 20, 2021 at 13:34
  • @JoãoSantos you should add an http header to the request with name Referer and value zonamentopf.portaldasfinancas.gov.pt/simulador/default.jsp (note, SE removes https:// from the link text, but that should be include in the value)
    – Berend
    Apr 20, 2021 at 14:32
  • With the key:Referer and Value:zonamentopf.portaldasfinancas.gov.pt/simulador/default.jsp I received: { "error": { "code": 403, "details": [ "Current proxy configuration settings do not allow requests which do not include a referer header." ], "message": "403 - Forbidden: Access is denied." } } Apr 20, 2021 at 14:36
  • I'm using the previous url/proxy -> zonamentopf.portaldasfinancas.gov.pt/simulador/proxy.jsp?http://… Apr 20, 2021 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.