Smalltalk package to read and view GIS data in ESRI Shapefile format, originally written by Hans Baveco and forked to work with Pharo.
EpMonitor disableDuring: [
Metacello new
onWarningLog;
repository: 'github://pharo-GIS/Shapes/repository';
baseline: 'Shapes';
load ].
You can try it with your own .shp files or download a sample data set from Natural Earth project using the following example:
| shpE legend urlRoot urlESRIFilePrefix urlESRIFileShp urlPath response fileRef |
" Download Shapefile resources "
urlRoot := 'https://github.com/nvkelso/natural-earth-vector/blob/master/110m_cultural/'.
urlESRIFilePrefix := 'ne_110m_populated_places'.
urlESRIFileShp := urlESRIFilePrefix , '.shp'.
urlPath := urlRoot , urlESRIFilePrefix.
#('.shx' '.dbf' '.shp' '.cpg' '.prj') do: [ : ext |
ZnClient new
url: (urlPath , ext) asZnUrl;
queryAt: 'raw' put: 'true';
numberOfRetries: 2;
enforceHttpSuccess: true;
downloadTo: urlESRIFilePrefix , ext;
get ].
" Load and display it in Morphic "
shpE := ShapeEnsemble fromFile: urlESRIFileShp.
" List data fields "
shpE dataFields inspect.
" List all shape records "
shpE shapeRecords inspect.
" Set the current attribute "
shpE attribute: 'NAME'.
legend := ColorLegend mapValuesToRandom: shpE valuesOfCurrentAttribute.
shpE legend: legend.
shpE displayMorphic.
If you already downloaded the files in your Pharo working directory:
| urlESRIFilePrefix urlESRIFileShp shpE legend |
urlESRIFileShp := FileSystem workingDirectory / 'natural-earth-vector/10m_cultural/ne_10m_admin_0_countries.shp'.
shpE := ShapeEnsemble fromFile: urlESRIFileShp.
shpE attribute: 'CONTINENT'.
legend := ColorLegend mapValuesToRandom: shpE valuesOfCurrentAttribute.
shpE legend: legend.
shpE displayMorphic
Follows some example outputs using different attributes for the NaturalEarth data set: