2

I need to query arcGIS map service and add this result to another feature service using ArcGIS JavaScript API. I should not use MAP object.

I did query data without map from ArcGIS sample: Now i need to post this data to feature service:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Query State Info without Map</title>

    <script src="http://js.arcgis.com/3.9/"></script>
    <script>
        require([
          "esri/tasks/query", "esri/tasks/QueryTask",
          "dojo/dom", "dojo/on", "dojo/domReady!"
        ], function (Query, QueryTask, dom, on) {

            var queryTask = new QueryTask("http://xxxx/arcgis/rest/services/REGIS/xxx/MapServer/1");

            var query = new Query();
            query.returnGeometry = true;
            query.outFields = [
              "PIN", "PDAREA "
            ];

            on(this, "load", execute);

            function execute() {
                //query.where = "PIN in (" + getParameterByName("PINS") + ")";
                query.where = "PIN in (1010027)";
                queryTask.execute(query, showResults);
            }

            function showResults(results) {
                var resultItems = [];
                var resultCount = results.features.length;
                for (var i = 0; i < resultCount; i++) {
                    newfeatGeom = JSON.stringify(results.features[i].geometry);
                    newAtt = JSON.stringify(results.features[i].attributes);
                    finalObj = newfeatGeom.concat(newAtt);
                    var featureAttributes = results.features[i].attributes;
                    for (var attr in featureAttributes) {
                        resultItems.push("<b>" + attr + ":</b>  " + featureAttributes[attr] + "<br>");
                    }
                    resultItems.push("<br>");
                }
                dom.byId("info").innerHTML = resultItems.join("");
            }

            function getParameterByName(name) {
                name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
                var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                    results = regex.exec(location.search);
                return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
            }
        });
    </script>
</head>

<body>
    US state name :
    <br />
    <div id="info" style="padding: 5px; margin: 5px; background-color: #eee;">
    </div>
</body>
</html>

Any Idea?

2
  • What have you tried/researched so far? Usually posting a snippet of your code so far which works up to where you are stuck will make it easier for potential answerers to help you.
    – PolyGeo
    Commented Jun 29, 2014 at 7:58
  • Not started yet, I didn't get the idea to implement. I need to know is this possible?
    – Chenna
    Commented Jun 29, 2014 at 8:03

2 Answers 2

6

Finally I have the answer for my Query: Here is the solution... (I am posting this; it might help someone) Thank You for your Help and Support.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Copy data from one service to another using REST API</title>

    <script src="http://js.arcgis.com/3.9/"></script>
    <script>
        var objPD = [{ "attributes": { "OBJECTID": 1, "SAM_NO": 0, "PIN": "1010027", "C_SRC": " ", "TRANS_NO": 100, "D_IN_DATE": null, "I_WORKORDER_ID": null, "TAIN_NO": null, "TAIN_YEAR": null, "PAR_AREA": 174804 }, "geometry": null }];
        require([
          "esri/tasks/query", "esri/tasks/QueryTask",
          "dojo/dom", "dojo/on", "dojo/dom-class", "dojo/_base/json",
          "esri/urlUtils", "esri/config", "esri/request", "dojo/domReady!"],
          function (Query, QueryTask, dom, on, domClass, dojoJson, urlUtils, esriConfig, esriRequest) {
              esriConfig.defaults.io.proxyUrl = "http://localhost:52896/proxy.ashx";
              var queryTask = new QueryTask("http://xxx/arcgis/rest/services/xxx/xxx/MapServer/1");
              var query = new Query();
              query.returnGeometry = true;
              query.outFields = [
                "PIN", "PDAREA "
              ];
              dom.byId("info").innerHTML = "Processing...";
              on(this, "load", execute);

              function execute() {
                  query.where = "PIN in (1010027)";
                  queryTask.execute(query, showResults);
              }

              function showResults(results) {
                  var resultItems = [];
                  var resultCount = results.features.length;
                  var today = new Date();                 
                  for (var i = 0; i < resultCount; i++) {
                      objPD[0].geometry = results.features[i].geometry;
                      objPD[0].attributes.PIN = results.features[i].attributes.PIN;
                      objPD[0].attributes.PAR_AREA = results.features[i].attributes.PDAREA;
                      newAtt = JSON.stringify(objPD);
                      dom.byId("info").innerHTML = "Copying PIN: " + objPD[0].attributes.PIN;
                      var requestHandle = esriRequest({
                           "url": "http://xxxx/arcgis/rest/services/xxxx/xxxx/FeatureServer/2/addFeatures",                         
                          "content": {
                              "features": newAtt,
                              "f": "json"}}, {"usePost": true});
                      requestHandle.then(requestSucceeded, requestFailed);
                  }

              }

              function getParameterByName(name) {
                  name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
                  var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                      results = regex.exec(location.search);
                  return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
              }
              function requestSucceeded(response, io) {
                  dom.byId("info").innerHTML = dojoJson.toJson(response, true);
              }
              function requestFailed(error, io) {
                  dom.byId("info").innerHTML = dojoJson.toJson(error, true);

              }
          });
    </script>
</head>

<body>

    <div id="info" style="padding: 5px; margin: 5px; background-color: #eee;">
    </div>
</body>
</html>
1
  • Super helpful, I was trying to do exactly this. Thank a million
    – Rob
    Commented Sep 14, 2015 at 17:02
1

Since you have not started, I suggest trying to use the Query data without a map developer sample for the ArcGIS API for JavaScript first:

This sample demonstrates that you can query data from a map service without displaying the service. Most map services contain datasets with attribute information that can be queried and displayed in a simple list or table.

Once you get that working you will be in a better position to research/ask separately about adding the result of this to another(?) feature service.

2
  • Yes, I completed the query data. can you give me an idea on posting the data to a feature service.
    – Chenna
    Commented Jun 29, 2014 at 8:14
  • @Chenna I'll need to leave that to someone more familiar than me with this part of the ArcGIS Platform. From your original question it was not clear whether you had reviewed any documentation before posing your question.
    – PolyGeo
    Commented Jun 29, 2014 at 8:36

Your Answer

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

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