◀ Back to NotesPublished on September 02, 2023

Fetching land coordinates from Romania's Geoportal

In my quest for finding a modest house to buy, I've been asking for cadastral reference numbers from sellers, which I can then lookup on a map using the Imobile eTerra website.

Sometimes I'd like to see the house or land in question on Google Maps, to see if it's close to a train track, if cycling is possible, where schools, churches and stores are in relation to it etc.

Let's take this land for example:

panorama at sunset

It's a nice plot located in Fundățica, Brașov, with cadastral reference number 102507. Let's search for it in the Geoportal map website:

Here's what the website requests from the backend, right after we click the search button, and before it zooms in to the land in question:

This seems to be the query service of the ArcGIS server. Let's play with that by translating it into a command-line request.

# Command-line requests

First, for more readable command-line requests, I'll use xh instead of the usual curl. It can be easily installed on macOS using:

brew install xh

Translating the above request for the command-line will look like this:

xhs geoportal.ancpi.ro/maps/rest/services/eterra3_publish/MapServer/1/query \
    f==json where=="INSPIRE_ID = 'RO.83.40991.102507'"

Which gives us an ArcGIS JSON response containing the polygon that delimits the land.

{
  "displayFieldName": "INSPIRE_ID",
  "fieldAliases": { "INSPIRE_ID": "INSPIRE_ID" },
  "geometryType": "esriGeometryPolygon",
  "spatialReference": { "wkid": 3844, "latestWkid": 3844 },
  "fields": [
    {
      "name": "INSPIRE_ID",
      "type": "esriFieldTypeString",
      "alias": "INSPIRE_ID",
      "length": 30
    }
  ],
  "features": [
    {
      "attributes": { "INSPIRE_ID": "RO.83.40991.102507" },
      "geometry": {
        "rings": [
          [
            [522620.43299999833, 435711.11600000039],
            [522622.72599999979, 435708.64699999988],
            [522651.29300000146, 435693.64299999923],
            [522671.28500000015, 435681.12900000066],
            [522687.2340000011, 435666.57200000063],
            [522714.81399999931, 435641.48099999875],
            [522703.13399999961, 435636.46799999848],
            [522676.69399999827, 435625.78599999845],
            [522663.50200000033, 435615.34299999848],
            [522649.26700000092, 435607.15300000086],
            [522640.06899999827, 435599.19900000095],
            [522632.24300000072, 435583.27199999988],
            [522626.99100000039, 435575.28000000119],
            [522621.45600000024, 435568.55700000003],
            [522603.33700000122, 435557.77800000086],
            [522598.81300000101, 435562.11800000072],
            [522592.8040000014, 435572.04699999839],
            [522589.21799999848, 435577.49799999967],
            [522585.74799999967, 435582.1259999983],
            [522582.19999999925, 435586.90399999917],
            [522580.39900000021, 435589.24399999902],
            [522578.21999999881, 435592.07200000063],
            [522574.91800000146, 435596.9140000008],
            [522571.15500000119, 435604.28599999845],
            [522568.70899999887, 435609.90300000086],
            [522565.28200000152, 435616.85000000149],
            [522559.05900000036, 435627.21400000155],
            [522555.69799999893, 435631.82400000095],
            [522551.21799999848, 435638.20600000024],
            [522549.47300000116, 435640.9990000017],
            [522548.69000000134, 435642.15399999917],
            [522544.66200000048, 435649.3909999989],
            [522542.36400000006, 435654.72300000116],
            [522540.39400000125, 435660.24100000039],
            [522539.04199999943, 435663.48200000077],
            [522615.60599999875, 435715.23999999836],
            [522620.43299999833, 435711.11600000039]
          ]
        ]
      }
    }
  ]
}

The polygon coordinates are local to Romania, defined in the Stereo70 projection, which is not what is used by Google Maps.

Stereo70 is a projection specific to the territory of Romania, which helps with defining coordinates without worrying about deformed angles because of the planet curvature.

It has a Well Known ID (WKID) of 3844.

World coordinates are usually defined in the WGS84 projection where:

  • latitude goes from -90° to 90°
  • longitude goes from -180° to 180°
  • WKID is 4326

To get the same polygon in global coordinates that we can use in Google Maps, it's enough to do the same request with the f==geojson parameter instead of f==json:

xhs geoportal.ancpi.ro/maps/rest/services/eterra3_publish/MapServer/1/query \
    f==geojson where=="INSPIRE_ID = 'RO.83.40991.102507'"
{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [ 25.287531829092149, 45.420803656524832 ],
                        [ 25.287470332276598, 45.420840926634618 ],
                        [ 25.28648952561111, 45.420377597283412 ],
                        [ 25.286506655001162, 45.420348386206918 ],
                        [ 25.286531577836683, 45.420298663249824 ],
                        [ 25.286560700726216, 45.420250603640277 ],
                        [ 25.286611844506226, 45.420185344155705 ],
                        [ 25.286621797812103, 45.420174924452724 ],
                        [ 25.286643969799059, 45.420149732494529 ],
                        [ 25.286700928711532, 45.420092153024541 ],
                        [ 25.286743668675413, 45.420050556791701 ],
                        [ 25.28682271923968, 45.419957084876486 ],
                        [ 25.286866195449967, 45.419894454519003 ],
                        [ 25.286897196111994, 45.419843825178624 ],
                        [ 25.286944946481018, 45.419777359147687 ],
                        [ 25.28698692143271, 45.41973367682953 ],
                        [ 25.287014637618551, 45.419708155816224 ],
                        [ 25.287037545627463, 45.419687038771002 ],
                        [ 25.287082667032362, 45.419643924452878 ],
                        [ 25.287126798471856, 45.419602162566434 ],
                        [ 25.287172374503797, 45.419552990288409 ],
                        [ 25.287248708881314, 45.419463439785865 ],
                        [ 25.287306322385597, 45.419424235673638 ],
                        [ 25.287538360704634, 45.419520656555903 ],
                        [ 25.287609401468654, 45.419580981651023 ],
                        [ 25.287676884155996, 45.419652736280781 ],
                        [ 25.287777624892041, 45.419795819060639 ],
                        [ 25.287895532854858, 45.419867103943105 ],
                        [ 25.288077820654202, 45.419940349537939 ],
                        [ 25.288246883870791, 45.420033904614328 ],
                        [ 25.288585257686936, 45.420129180785878 ],
                        [ 25.288734749902495, 45.420173916614992 ],
                        [ 25.288383453615673, 45.420400618735343 ],
                        [ 25.288180306407561, 45.420532141910058 ],
                        [ 25.287925397519455, 45.420645409479448 ],
                        [ 25.287561018878264, 45.420781362534932 ],
                        [ 25.287531829092149, 45.420803656524832 ]
                    ]
                ]
            },
            "properties": {
                "INSPIRE_ID": "RO.83.40991.102507"
            }
        }
    ]
}

GeoJSON is a standard format for defining geographic features, well supported by most databases and mapping libraries. Such a JSON can be pasted into GeoJSON.io for previewing it on a map, or inserted into PostGIS/ArcGIS for further processing.

We don't need any of that though, we just need one point from the coordinates of the polygon, which we can extract using jq. We'll delimit the numbers with a comma and output a Google Maps link for easy access:

xhs geoportal.ancpi.ro/maps/rest/services/eterra3_publish/MapServer/1/query \
    f==geojson where=="INSPIRE_ID = 'RO.83.40991.102507'" \
    | jq -r '.features[0].geometry.coordinates[0][0] | "\(.[1]),\(.[0])"' \
    | xargs -I% open "https://www.google.com/maps/search/?api=1&query=%"

Et voila, we're presented with a satellite view of Google Maps at the location of the land. The pin is placed on a corner of the land, but that's ok, enough for us to figure out where the land is and how the zone looks.