CGDRAWSHAPES
This program draws the entities in a shapefile, containing latitude and
longitude polygons or polylines, on a map projection. To draw the shapefile
entities automatically, no matter what kind of values the polygon vertices
have, and without a map projection, set the AUTODRAW keyword.
It is assumed a map projection command has been issued and is in effect at
the time this program is called. Alternatively, you can use a cgMap object,
which will set up the map coordinate space and provide the map structure required
for plotting in that XY map coordinate space.
If the ATTRVALUES keyword is undefined, all entities are drawn, but only a single value
for COLORS, FCOLORS, FILL, LINESTYLE, and THICK is allowed.
Categories
Graphics, Map Projections
Author
FANNING SOFTWARE CONSULTING::
David W. Fanning
1645 Sheely Drive
Fort Collins, CO 80526 USA
Phone: 970-221-0438
E-mail: [email protected]
Coyote's Guide to IDL Programming: http://www.idlcoyote.com
Examples
Example using cgMap_Set to set up the map projection space::
shapefile = Filepath(subdir=['examples','data'], 'states.shp')
cgDisplay, 800, 700
cgMap_Set, 40.0, -117.5, /Albers, /IsoTropic, Limit=[30, -125, 50, -108], $
Position=[0.05, 0.05, 0.95, 0.95]
cgDrawShapes, shapefile, AttrName='STATE_ABBR', $
AttrValues=['CA', 'OR', 'WA', 'AZ', 'UT', 'ID', 'NV'], Thick=1, $
FColors=['firebrick', 'grn4', 'pur4', 'tan4', 'steel blue', 'org4', 'yellow'], $
Fill = Replicate(1, 7), Colors='charcoal'
cgMap_Grid, LatDel = 2.0, LonDel = 2.0, /Box_Axes, Color='charcoal'
Example using cgMap to set up the map projection space::
shapefile = Filepath(subdir=['examples','data'], 'states.shp')
cgDisplay, 800, 700, WID=1
mapCoord = Obj_New('cgMap', 'Albers Equal Area', Limit=[30, -125, 50, -108], $
Position=[0.2, 0.05, 0.8, 0.95], CENTER_LATITUDE=40.0, $
CENTER_LONGITUDE=-117, STANDARD_PAR1=40, STANDARD_PAR2=-39)
cgDrawShapes, shapefile, AttrName='STATE_ABBR', $
AttrValues=['CA', 'OR', 'WA', 'AZ', 'UT', 'ID', 'NV'], Thick=1, $
FColors=['firebrick', 'grn4', 'pur4', 'tan4', 'steel blue', 'org4', 'yellow'], $
Fill = Replicate(1, 7), Colors='charcoal', MapCoord=mapCoord, /USELIMIT
cgMap_Grid, /Box_Axes, Color='charcoal', Map_Structure=mapCoord
Example drawing the states.shp file automatically, without a map projection::
shapefile = Filepath(subdir=['examples','data'], 'states.shp')
cgDrawShapes, shapefile, /Autodraw
Example using cgMap to set up the map projection space in a resizeable graphics window::
shapefile = Filepath(subdir=['examples','data'], 'states.shp')
cgWindow, WAspect=800.0/700
mapCoord = Obj_New('cgMap', 'Albers Equal Area', LIMIT=[30, -125, 45, -108], $
Position=[0.05, 0.05, 0.95, 0.95], CENTER_LATITUDE=37.5, $
CENTER_LONGITUDE=-117, STANDARD_PAR1=40, STANDARD_PAR2=-39)
mapCoord -> AddCmd
cgDrawShapes, shapefile, AttrName='STATE_ABBR', $
AttrValues=['CA', 'OR', 'WA', 'AZ', 'UT', 'ID', 'NV'], Thick=1, $
FColors=['firebrick', 'grn4', 'pur4', 'tan4', 'steel blue', 'org4', 'yellow'], $
Fill = Replicate(1, 7), Colors='charcoal', MapCoord=mapCoord, /AddCmd
cgMap_Grid, LatDel = 2.0, LonDel = 2.0, /Box_Axes, Color=cgColor('charcoal'), $
Map_Structure=mapCoord, /AddCmd
History
Modification History
Written by David W. Fanning by modifiying DrawStates to be more
general, 13 May 2010. DWF.
Added the AUTODRAW keyword for automatic drawing. 15 May 2010. DWF.
Added COMPILE_OPT idl2 to make sure all loop variables are longs. 5 July 2010. DWF.
Corrected an aspect ratio problem with AUTODRAW and upgraded to Coyote Graphics.
3 January 2011. DWF.
Previous method of freeing entity pointers took 10 times times longer than freeing
pointers as I go. Also added MinNumVerts keyword to screen out the drawing of
small polygons. 6 October 2011. DWF.
Wrong string case for discovering particular attributes caused them not to be drawn. 27 Oct 2011. DWF.
Added the ability to draw point shapefiles. Changed default color to "opposite". 20 Aug 2012. DWF.
Made sure a window is open when the default color is chosen. 29 Aug 2012. DWF.
Added a DrawMapCoord keyword so that shapes in a different map projection can be drawn on
a map correctly. 29 Nov 2013. DWF.
Changed the default value of the USELIMIT keyword to 1. Mostly, because I've been burned too many
times to think a default value of 0 makes sense. 29 Nov 2013. DWF.
Copyright
Copyright (c) 2011-2013, Fanning Software Consulting, Inc.