AnsweredAssumed Answered

JSON  Shapefile

Question asked by alex.gole_ELDORADOCOUNTY on Nov 7, 2017

Hi all,

 

I am trying to write JSON to a shapefile from my JS app.  I am using two third party libs here.

1. Terraformer to parse JSON to GeoJSON

2. GitHub - mapbox/shp-write: create and write to shapefiles in pure javascript 

 

 

 

 <script src="http://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
    crossorigin="anonymous"></script>
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
    crossorigin="anonymous"></script>
    <script>
            var dojoConfig = {
              parseOnLoad: true,
              packages: [{
                "name": "shpwrite",
                "location": location.pathname.replace(/\/[^/]+$/, "") + '/js'
              }]
            };
    </script>
    <script src="https://unpkg.com/terraformer@1.0.7/terraformer.js"></script>
    <script src="https://unpkg.com/terraformer-arcgis-parser@1.0.5/terraformer-arcgis-parser.js"></script>
    <script src="js/shpwrite.js"></script>
    <script src="https://js.arcgis.com/3.22/"></script>
   
    <script>
      var map;
      var AOI;
      var gp;
      var DrawToolbar;

      var options = {
        folder: 'myshapes',
        types: {
            point: 'mypoints',
            polygon: 'mypolygons',
            line: 'mylines'
        }
    }
....



DrawToolbar.on("draw-end", function(e) {
            DrawToolbar.deactivate();
            var symbol = new SimpleFillSymbol(
              "solid",
              new SimpleLineSymbol("dash", new Color([255,0,0]), 2),
              new Color([255,255,0,0.25])
            );
            var graphic = new Graphic(e.geometry, symbol);
            var json = graphic.toJson();
            // parse an ArcGIS Geometry to GeoJSON
            var Areas = Terraformer.ArcGIS.parse(json);
            console.log((Areas));
            shpwrite.download({
            type: 'FeatureCollection',
            features: Areas
            }, options);
           
            map.graphics.add(graphic);
        });

I get this error: 

 

Any idea?

Outcomes