You are on page 1of 4

shapele - Automate SHP to JPG creation - Geographic Informa...

http://gis.stackexchange.com/questions/62613/automate-shp-to-...

Geographic Information Systems Stack Exchange works best with JavaScript enabled
sign up log in tour help

Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Take the 2-minute tour

Automate SHP to JPG creation


Does anyone know of a way to batch convert shapeles to jpegs or another common image format? edit: I should have claried that I would like to apply a styling to each shapele, and then export the shapele with that styling to an image. For example, I have census tracts in a county, and I want an image of each individual tract highlighted while the other tracts are all the same color.
shapele convert jpg

edited Jun 4 '13 at 13:23

asked Jun 3 '13 at 20:07 camdenl 35 4

Do you have any particular software in mind? An application that you use regularly? Or do you just any way possible? RyanDalton Jun 3 '13 at 20:47 I use Arc and Q pretty regularly and am getting more familiar with arcpy, but am really just looking for any way to do this, even another third party software package camdenl Jun 3 '13 at 21:49

So for clarication, you are basically just looking to generate thumbnails (or larger) of the shapele, no styling, no colors, no labels, etc right? RyanDalton Jun 3 '13 at 22:21 I started thinking about this last night, and I see that my original question might be misleading. I would like to apply a styling and then export the map over 100+ times for each indiviual shapele with the applied styling. camdenl Jun 4 '13 at 13:19

5 Answers
There are many free tools like: gdal rasterize Map Tyler it is easy to do with Python and modules like Shapely and a simple for loop:

But in Python, the reference is Mapnik and Getting Started In Python You create a map (width and height in pixels, background color, etc) You create Styles which determines how the data is rendered You add a datasource (shapele, etc.) and create a layer from it. You render the map the same map and styles parameters can be applied to multiple les (via an XML le)

1 of 4

1/7/14 6:59 PM

shapele - Automate SHP to JPG creation - Geographic Informa...

http://gis.stackexchange.com/questions/62613/automate-shp-to-...

Geographic Information Systems Stack Exchange works best with JavaScript enabled
Simple Rendered images from TM_WORLD_BORDERS-0.3.shp

selection of a country (Angola) in the shapele:

Another example from Mapniks Maps

edited Jun 4 '13 at 10:53

answered Jun 4 '13 at 7:08

2 of 4

1/7/14 6:59 PM

shapele - Automate SHP to JPG creation - Geographic Informa...

http://gis.stackexchange.com/questions/62613/automate-shp-to-...

Geographic Information Systems Stack Exchange works best with JavaScript enabled
6,964 5 18

You could add all of the layers to a mxd, then loop through them and run
arcpy.mapping.ExportToJPEG(map_document, out_jpeg, {data_frame}, {df_export_width}, {df_export_height}, {resolution}, {world_file}, {color_mode}, {jpeg_quality}, {progressive})

for each layer in the map.


answered Jun 3 '13 at 20:17 Hotpepper 413 8

Just to add to this solution, you could use arcpy.da.walk to generate an initial list of input data: resources.arcgis.com/en/help/main/10.1/index.html#// scw Jun 4 '13 at 8:00

This similar question has answers that use FME to convert DWG to JPG. The process will be similar for converting shapeles. This example has example workspaces you can download. FME is well suited to handling batch processes. For example, you can point the reader to a folder and it will include all shapeles in the folder. I created a simple workow which reads all the shapeles in a folder and writes them out to separate JPGs.

answered Jun 4 '13 at 4:07 Fezter 5,099 4 11 40

Oh, I did this yesterday with counties in Montana! Is it too late to answer? Assuming you've already used Split to make a shapele for each census tract, I found that it was easy (lazy) to handle them in a Group Layer. Assuming that's the only Group Layer in your document, don't be shy about opening up the ArcPy window and entering:
# Setup, defining a variable for the map document, the data frame, # and a list of layers: mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] layers = arcpy.mapping.ListLayers(mxd) # To copy symbology to all subLayers in the group layer, # using a template, any normal polygon shapefile will do: # (datum conflict warnings are irrelevant) for layer in layers: if layer.isGroupLayer: for subLayer in layer: arcpy.ApplySymbologyFromLayer_management(subLayer, "templatelayer") # Export one map with each county/tract highlighted, toggling visibility # of each sublayer before and after: for layer in layers: if layer.isGroupLayer: for subLayer in layer: print "Exporting " + str(subLayer.name)

3 of 4

1/7/14 6:59 PM

shapele - Automate SHP to JPG creation - Geographic Informa...

http://gis.stackexchange.com/questions/62613/automate-shp-to-...

slfile = "C:\\YourPathHere\\Subdir\\Etc\\" + str(subLayer.name) + ".png" arcpy.mapping.ExportToPNG(mxd, slfile, df, df_export_width=640, df_export_height=480, transparent_color="255, 255, 255") subLayer.visible = False

Geographic Information Systems Stack Exchange works best with JavaScript enabled

Export to jpg is similar, but jpgs are kinda yucky. This was my rst ArcPy experience, so I'm sure there are more elegant ways to do this.
answered Jun 21 '13 at 23:22 Branden 21 1

You did do the exact same thing eh? Glad you gured it out, thanks for the response camdenl Jun 25 '13 at 1:37

Instead, just load the shp le into ArcMaps and congure it how you like. Then use either Alt + Print Screen or the Snipping Tool to get a screenshot. Then you will have a jpg or png that looks exactly like how the shape le was rendered.
answered Nov 25 '13 at 19:40 mike 1

I don't think that addresses the key component of the question which is how to automate the process. RyanDalton Nov 25 '13 at 19:49

4 of 4

1/7/14 6:59 PM

You might also like