Cannot see the Points on the map in ArcGIS Online, data imported via REST

1512
7
Jump to solution
06-08-2017 07:40 AM
IonutPlesca
New Contributor II

Hi people,

I'm having some troubles seeing the Points on a Layer under a Feature Service - for some reason, although all the steps below go without error, I'm not able to see anything on the map, though the data is there. Probably I'm doing something wrong with the syntax needed for the ArcGIS REST API. Can anyone go over them and give me a helping hand? Much appreciated!

What I'm trying to achieve is: push data to a layer and view it within a map in ArcGIS Online. My steps, using REST calls are like these:

1. Create a hosted feature service

(note: [username], [token] and [identifier] are replaced with proper values)

URL:

POST https://www.arcgis.com/sharing/rest/content/users/[username]/createService

PHP DATA:

array (
  'token'      => '[token]',
  'f'          => 'json',
  'outputType' => 'featureService',
  // json encoded below
  'createParameters' => '{
        "name":"Good test",
        "serviceDescription":"GeoPal assets",
        "description":"Assets imported through GeoPal assets",
        "hasStaticData":false,
        "supportedQueryFormats":"JSON",
        "capabilities":"Create,Delete,Query,Update,Editing",
        "units":"esriMeters",
        "spatialReference":{
            "wkt":"WGS_1984_Web_Mercator"
        },
        "initialExtend":{
            "type":"extent",
            "xmin":-8591193.02146,
            "ymin":4686637.93832,
            "xmax":-8560023.56404,
            "ymax":4726686.26299,
            "spatialReference":{
                "wkt":"WGS_1984_Web_Mercator"
            }
        },
        "xssPreventionInfo":{
            "xssPreventionEnabled":true,
            "xssPreventionRule":"InputOnly",
            "xssInputRule":"rejectInvalid"
        }
    }',
)

2. Create a layer under the above Feature Service

URL:

POST https://services6.arcgis.com/[identifier]/arcgis/rest/admin/services/Good%20test/FeatureServer/addTo...

PHP DATA

array (
  'token' => '[token]',
  'f'     => 'json',
  // json encoded
  'addToDefinition' => '{
      "layers":[{
          "units":"esriDecimalDegrees",
          "name":"GeoPal assets layer",
          "type":"Feature Layer",
          "displayField":"NAME",
          "description":"Imported GeoPal assets",
          "copyrightText":"",
          "defaultVisibility":true,
          "relationships":[],
          isDataVersioned":false,
          "supportsRollbackOnFailureParameter":true,
          "supportsAdvancedQueries":true,
          "geometryType":"esriGeometryPoint",
          "minScale":0,
          "maxScale":0,
          "extent":{
              "type":"extent",
              "xmin":-8591193.02146,
              "ymin":4686637.93832,
              "xmax":-8560023.56404,
              "ymax":4726686.26299,
              "spatialReference":{
                  "wkt":"WGS_1984_Web_Mercator"
              }
          },
          "drawingInfo":{
              "transparency":0,
              "labelingInfo":null,
              "renderer":{
                  "type":"simple",
                  "symbol":{
                      "color":[76,129,205,255],
                      "size":5,
                      "angle":0,
                      "xoffset":0,
                      "yoffset":0,
                      "type":"esriSMS",
                      "style":"esriSMSSquare",
                      "outline":{
                          "color":[80,80,80,255],
                          "width":3,
                          "type":"esriSMS",
                          "style":"esriSMSCircle"
                      }
                  }
              }
          },
          "allowGeometryUpdates":true,
          "hasAttachments":true,
          "htmlPopupType":"esriServerHTMLPopupTypeNone",
          "hasM":false,
          "hasZ":false,
          "objectIdField":"OBJECTID",
          "globalIdField":"OBJECTID",
          "fields":[{
              "name":"OBJECTID",
              "alias":"Object ID",
              "type":"esriFieldTypeOID",
              "nullable":false,
              "editable":false,
              "domain":null,
              "defaultValue":null
          }, {
              "name":"NAME",
              "alias":"Asset name",
              "nullable":false,
              "editable":true,
              "domain":null,
              "defaultValue":null,
              "type":"esriFieldTypeString"
          }],
          "indexes":[],
          "types":[],
          "templates":[],
          "supportedQueryFormats":"JSON,geoJSON",
          "hasStaticData":true,
          "maxRecordCount":1000,
          "capabilities":"View,Query,Editing,Create,Update,Delete"
      }]
  }',
)

3. Push data to the layer

URL

POST https://services6.arcgis.com/[identifier]/arcgis/rest/services/Good%20test/FeatureServer/0/addFeatur...

PHP DATA

array (
    'token' => '[token]',
    'f'     => 'json',
    // json encoded
    'features' => '[{
        "geometry":{
            "x":"53.32712320000000",
            "y":"-6.38504700000000"
        },
        "attributes":{
            "OBJECTID":" TMP:6011T2EWFQ",
            "NAME":"Asset # TMP:6011T2EWFQ"
        }
    }, {
        "geometry":{
            "x":"-6.16427469253540",
            "y":"39.19896697998047"
        },
        "attributes":{
            "OBJECTID":" TMP:6SFDKNX48O",
            "NAME":"Asset # TMP:6SFDKNX48O"
        }
    }, {
        "geometry":{
            "x":"34.02233442402884",
            "y":"-118.28009672462940"
        },
        "attributes":{
            "OBJECTID":" TMP:9M911WXZEO",
            "NAME":"set from script"
        }
    }]',
)
0 Kudos
1 Solution

Accepted Solutions
IonutPlesca
New Contributor II

In the end, the full issue was comprised of a wrong SR and wrong values for the coordinates (coming from Google).

Leaving the default wkid and converting coordinates with the PHP function below did the trick.

/**
 * Converts Google/Bing coordinates to WGS 1984 Web Mercator coordinates
 *
 * @param $lat Latitude
 * @param $lon Longitude
 * @return array ['x', 'y']
 */
 private function GoogleBingtoWGS84Mercator($lat, $lon)
 {
     $y = log(tan(($lat / (180/M_PI) + M_PI/2) / 2)) / (M_PI/180);
     $y = ($y / 180) * 20037508.34;
     $x = ($lon / 180) * 20037508.34;

     return [
         'x' => $x,
         'y' => $y
     ];
 }

View solution in original post

0 Kudos
7 Replies
HemingZhu
Occasional Contributor III

Most likely it is the issue of the JSON format of the feature collection you try to push to the featurelayer. Usually the format of feature collection includes featureSet and layerdefinition. You can make a query on one of the service(through the rest services directories on json format and see what all what the format really looks like. I have done creating a polyline featurelayer on feature collection and I knew that was where my problems. 

IonutPlesca
New Contributor II

Hey,

Indeed, I noticed that the format of a Feature Service (when queried) contains 'featureSets'. Alas, when creating a new feature layer, seems there is no such option to be defined.

I've followed the example described here and that's what got me through. Still, the points aren't showing and I'm assuming it has to do with either the spatialReferenceunits or something similar in defining the "visual aspect".

Thanks for the lead - I'll keep trying/validating the schema.

0 Kudos
HemingZhu
Occasional Contributor III

JS API3.x has a sample you can look at. it shows how to create a featurelayer using featurec ollection. Feature collection | ArcGIS API for JavaScript 3.20 

0 Kudos
IonutPlesca
New Contributor II

If I'm not mistaken, this is for rendering maps/layers using JS (creating your own map app). In my scenario, I'm only creating and populating feature services/layers via REST strictly and not planning to use/access the data from outside ArcGIS Online.

__

As a side note, I think my "points not showing" issue is related to the wrong spatialReference system, where my original coordinates come from Google. Found more info here.

My quest lead me to find a way of converting this type of coords (Google, WGS_1984_Web_Mercator)...

geometryPoint:
X: -6.1642746925354
Y: 39.198966979980469

... to this type (WGS_1984_Web_Mercator_Auxiliary_Sphere):

geometryPoint:
X: -928111.36816533119
Y: 7133180.2069284255
0 Kudos
HemingZhu
Occasional Contributor III

just try to point you a place while you can look at the format of feature collection. I am glad that you find the issue. Having worked on google map API for a while while you will notice that all the google API methods us long/at (4326)while its maps display in Web_Mercator(102100). when i add Google Maps as one of the base map layers for ESRI JS api, I had to deal with this issue while watch mapview's extent. 

0 Kudos
HemingZhu
Occasional Contributor III

forget to mention. I would using WKID instead of WKT. It is simple not prone to mistake like type.

0 Kudos
IonutPlesca
New Contributor II

In the end, the full issue was comprised of a wrong SR and wrong values for the coordinates (coming from Google).

Leaving the default wkid and converting coordinates with the PHP function below did the trick.

/**
 * Converts Google/Bing coordinates to WGS 1984 Web Mercator coordinates
 *
 * @param $lat Latitude
 * @param $lon Longitude
 * @return array ['x', 'y']
 */
 private function GoogleBingtoWGS84Mercator($lat, $lon)
 {
     $y = log(tan(($lat / (180/M_PI) + M_PI/2) / 2)) / (M_PI/180);
     $y = ($y / 180) * 20037508.34;
     $x = ($lon / 180) * 20037508.34;

     return [
         'x' => $x,
         'y' => $y
     ];
 }
0 Kudos