Dec 3, 2008

Mathematica 7: import ESRI Shape file

Finally, ESRI Shape file is supported in Mathematica 7: Import["dir/file.shp"]

However, I feel it is necessary to explain it in a little more detail for users who are not that familiar with Mathematica.

Let's import a  shape file from Indiana GIS Atlas which contains county boundaries.

(*import data*)
data=First@Import["http://129.79.145.7/arcims/statewide_mxd/downloads/LANDSURVEY_COUNTY_POLY_IN.zip", Data"];
(*check what is inside the data*)
data[[All, 1]]
{"LayerName", "Geometry", "Labels", "LabeledData"}
(* check the field name in attribute table *)
"Labels" /. data
{"AREA", "PERIMETER", "NAME_U", "NAME_L", "NCAPC"}
(* attribute data is stored in "LabeldData" *)
area = "AREA" /. ("LabeledData" /. data);
area = Rescale[area];
(* get all the geometry *)
geometry = "Geometry" /. data;
(* put two data together *)
mapdata = Transpose[{geometry, area}];
(* generate the thematic map *)
Graphics[{EdgeForm[{Thick, Gray}], FaceForm[ColorData["Rainbow"][#[[2]]]], #[[1]]} & /@ mapdata, Frame -> False, ImageSize -> 400]

 

importshapefile

 

With some extra efforts, a 3D version is generated.

importshapefile3D

1 comment:

José Luis Muñoz Meza said...

Maybe is a naive and outdated comment but..., anyway.
Using the last sentence:
Graphics[{EdgeForm[{Thick, Gray}],
FaceForm[ColorData["Rainbow"][#[[2]]]], #[[1]]} & /@ mapdata,
Frame -> False, ImageSize -> 400]

I got an error "Blend is not a graphic directive"....