1

I'd like to be able to programmatically query a feature service api and pull the attribute data (I don't really need the geometry for this) into a google sheet. It seems like it ought to be simple but maybe I'm just missing something. I've been playing around with the code at this link here gist and below but so far haven't been able to get it to work, and it seems like it might be out of date.

I'm currently stuck at the code below. When I run the debugger, it looks like while dataAll is populating correctly, the feature variable is not. It looks like 'dataAll[i]' isn't working. Does anyone know why or how to fix it?

function pullJSON() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheets = ss.getSheets(); var sheet = ss.getActiveSheet();

var url="http://your url here"; // Paste your JSON URL here
 var response = UrlFetchApp.fetch(url); // get feed

   var dataAll = JSON.parse(response); //   Logger.log(dataAll)
for (i = 0; i<30; i++) {
  feature = dataAll[i];
  name = feature.NAME;
  Logger.log (name)
}
  • For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. There is an edit button beneath your question which will enable you to do that and a {} button that enables you to format any highlighted code nicely. – PolyGeo Jun 14 '18 at 8:12
  • There is no example to the data, but it looks like it you want to query the properties of the features, My guess (again - based on standard api) is you can get the properties with let name = feature.properties.NAME – NettaB Jun 29 '18 at 20:26
1

It would probably help if you posted a sample of the raw GeoJSON that you are receiving, but I would assume that it looks like a typical geoJSON, like this:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [102.0, 0.5]
      },
      "properties": {
        "prop0": "value0"
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
        ]
      },
      "properties": {
        "prop0": "value0",
        "prop1": 0.0
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
            [100.0, 1.0], [100.0, 0.0]
          ]
        ]
      },
      "properties": {
        "prop0": "value0",
        "prop1": { "this": "that" }
      }
    }
  ]
}

Source

Your "NAME" attribute should be found in the properties object in the features list, so you would grab their info like this:

for (i = 0; i<30; i++) {
  feature = dataAll.features[i];
  name = feature.properties.NAME;
  Logger.log (name)
}
  • *For an ESRI response json, "properties" will be "attributes." – Carl May 3 at 13:18
  • Ah yes, ESRI will be ESRI... – wfgeo May 3 at 13:44
0

You can do with with OGR2OGR it supports reading WFS or ESRI Feature Service and Read/Write Google Sheet/Fusion Tables. ogr2ogr -f GFT "GFT:email=john.doe@example.com password=secret_password" URL to service http://www.gdal.org/drv_gft.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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