ESRI shape files (shp): importing the polygon data can yield a very large list. It is computationally intensive rendering the polygon. I have been trying to convert to GraphicsComplex by extracting all the vertices, indexing them and then specifying the polygon by the vertex index.

However, the computational effort of removing duplicates (shared borders) seems to be computationally worse than the original issue (for the large input size of the list of vertices).

Can someone advise me if there is a better way to work with these files?

I am able to use them but not efficiently.

  • $\begingroup$ To clarify, it is the rendering of the Graphics that you find slow, correct? Does this effect all (large) files some more than others? $\endgroup$
    – Mr.Wizard
    Aug 18, 2012 at 7:58
  • $\begingroup$ I have the same problem. I was also thinking about using GraphicsComplex and have some ideas about how to remove the duplicates but I haven't tried these yet. $\endgroup$ Aug 18, 2012 at 12:20
  • $\begingroup$ Do you use single polygons Polygon[pts] or the multi-primitive syntax Polygon[{pts1,pts2}]? Using the latter you can speed up rendering quite a bit. $\endgroup$
    – Yves Klett
    Aug 20, 2012 at 11:11

1 Answer 1


Depending on your needs it may be helpful to know that a significant amount of time is spent converting a Graphics expression to output Box forms. Example:

graphics = Import["http://exampledata.wolfram.com/usamap.zip", "Graphics"];

Timing[cell = Cell[BoxData@ToBoxes@graphics, "Output"];]

{1.466, Null}

It is now significantly faster to print this pre-converted Cell expression than it is to print graphics:

  EvaluationCompletionAction -> "ShowTiming"]

CellPrint[cell] (* 0.52 second *)

graphics  (* 1.75 seconds *)

Although I doubt it is robust and options are likely to be fragile, at least with version 7 one may leverage that fact in this particular case by doing a similar Graphics to GraphicsBox conversion manually, bypassing the internal ToBoxes routine:

   graphics /. {Graphics -> GraphicsBox, Line -> LineBox, Polygon -> PolygonBox}
  ], "Output"] // CellPrint  (* 0.52 second *)

Credit to Szabolcs for this trick.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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