# ESRI shape files

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.

-
To clarify, it is the rendering of the Graphics that you find slow, correct? Does this effect all (large) files some more than others? –  Mr.Wizard Aug 18 '12 at 7:58
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. –  Gustavo Delfino Aug 18 '12 at 12:20
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. –  Yves Klett Aug 20 '12 at 11:11

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:

SetOptions[\$FrontEndSession,
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:

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


Credit to Szabolcs for this trick.

-
thanks for the insights –  ubpdqn Aug 19 '12 at 11:33