Select to view content in your preferred language

Draw Polygon, save it as a shapefile

7145
6
Jump to solution
05-11-2016 09:17 AM
DavidChrest
Deactivated User

Is there an example where the user simply draws a polygon and then can save/export to a named shapefile?

Thanks,

David

0 Kudos
1 Solution

Accepted Solutions
DavidChrest
Deactivated User

I believe I found something. The code sample from the broken links in js2shapefile is available in this GitHub:GitHub - borisdev/js2shapefile: Automatically exported from code.google.com/p/js2shapefile.

I forked the repo, downloaded, and this sample actually works: js2shapefile/Test_EsriDrawToShapefile.html at master · borisdev/js2shapefile · GitHub . Uses Draw Toolbar to create lines, points, and polygons and can save all at once into their shapefiles. Pretty cool!

After downloading the shapefile(s), you just need to  assign them the Web Mercator Auxiliary Sphere projection. Once you have that .prj file, you can copy and rename to match others. Tool just creates .dbf, .shp, .shx files.

Code is 4 years old and uses ArcGIS JS 2.6, but is a simple app and a good starting point to upgrade to 3.16 and rework/modify the GUI. Would be good to be able to name shapefiles you save. Also needs to "Clear Graphics" button, only way to draw and export additional shapefiles is to refresh page.

View solution in original post

Tags (1)
0 Kudos
6 Replies
thejuskambi
Frequent Contributor

There are couple of opinions out there. Take a look at below links

http://www.arcgis.com/home/item.html?id=76abc91cf91445cf957943955d35fb0c

json to shapefile in javascript - Geographic Information Systems Stack Exchange

Using shp-write to export as shapefile

If it is just for persistence and not  to use it elsewhere, I would suggest you to just save it as json file.

DavidChrest
Deactivated User

OK, I found all those you list previously.

The example links in the JS2Shapefile page just give me 404 page errors, which is really too bad, since these look good. Would really love to see "modification of the Draw Toolbar sample to let you save the results to a shapefile."

The other links you list above I checked out but I didn't get very far. All looks a bit confusing and did not see exactly where one can save data after drawing.

I LOVE the Advanced Draw tool. Just needs a Save to Shapefile button and I'd be golden. Seems like somebody out there must have done this.

Thanks,

David

0 Kudos
DavidChrest
Deactivated User

I believe I found something. The code sample from the broken links in js2shapefile is available in this GitHub:GitHub - borisdev/js2shapefile: Automatically exported from code.google.com/p/js2shapefile.

I forked the repo, downloaded, and this sample actually works: js2shapefile/Test_EsriDrawToShapefile.html at master · borisdev/js2shapefile · GitHub . Uses Draw Toolbar to create lines, points, and polygons and can save all at once into their shapefiles. Pretty cool!

After downloading the shapefile(s), you just need to  assign them the Web Mercator Auxiliary Sphere projection. Once you have that .prj file, you can copy and rename to match others. Tool just creates .dbf, .shp, .shx files.

Code is 4 years old and uses ArcGIS JS 2.6, but is a simple app and a good starting point to upgrade to 3.16 and rework/modify the GUI. Would be good to be able to name shapefiles you save. Also needs to "Clear Graphics" button, only way to draw and export additional shapefiles is to refresh page.

Tags (1)
0 Kudos
lura8800
New Contributor
  • 0557358813
0 Kudos
FC_Basson
MVP Regular Contributor

I assume you want to do this client-side?  Otherwise you could create your own server side GP service that does it for you by sending the geometries as ArcGIS JSON to the GP service and using the ArcPy tools in your GP model/script to do the convert to feature class and zip it up in a single file. That way you can "convert to shp" over and over and ensure that the data returned has projection information.  You can also do all kind of other stuff with it in the GP service e.g. add additional fields, calculate geometry properties, convert to other additional formats etc.

DavidChrest
Deactivated User

Thanks so much for your response and advice. Much appreciated. I was just seeing what was out there in terms of what other people have done. Yes, a GP service would be great and I eventually may do this ( I have coworkers who have done this already). I also happened to find an older client-side example ( see my above message with links to js2Shapefile code). Have never created a GP service before but looks like this would be a good case to learn and start. But other client-side examples would be great to see as well.

0 Kudos