Well, it appears that simple direct downloading does not download the real shapefile. Taking care to actually get a shapefile, the result loads without problems.
ne_110m_populated_places.shp is a PointShape with 243 shapes (points). If you display it on a Form (#displayMorphic) you won���t see much (243 hardly visible dots).
��
With an application for vector graphics (Roassal?) that can read & display the vector data we would get much nicer maps...
��
Hans
��
From: Baveco, Hans <hans.baveco@wur.nl>
Sent: vrijdag 5 juni 2020 12:44
To: Any question about pharo is welcome <pharo-users@lists.pharo.org>
Subject: [Pharo-users] shape file reading��
Hi Hernan
��
I downloaded this shapefile directly via the browser. Indeed it won���t load, the type of shape file returned is
self longAt: 33 bigEndian: false -> 577660194
��
��
where it should have answered an Integer between 0 and 31
��
shapeType
���������������� "position 32, Integer between 0 and 31, Little Endian"
��
���������������� ^shpBytes longAt: 33 bigEndian: false
��
��
No idea what could be the cause ��� apparently the header of the file (the first 100 bytes) is not ok...
��
Hans
��
��
��
��
You mean some types are missing? Because I get this error when I try to read some SHP files: "Types > 20 are not yet accounted for"
��
I wrote this script to reproduce:
��
��| 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') do: [ : ext |
| url |
url := ��(urlPath , ext , '?raw=true') asZnUrl.
(response := ZnEasy get: url) isSuccess
ifFalse: [ self error: 'Cannot download file' ].
fileRef := FileSystem disk workingDirectory / (urlESRIFilePrefix , ext).
fileRef writeStreamDo: [ : stream |
stream nextPutAll: ((ZnByteEncoder newForEncoding: 'koi8r') decodeBytes: response contents ) ] ].��
Once downloaded:
��
| urlESRIFilePrefix urlESRIFileShp shpE |
urlESRIFilePrefix := 'ne_110m_populated_places'.
urlESRIFileShp := urlESRIFilePrefix , '.shp'.
" Load and display it in Morphic "
shpE := ShapeEnsemble fromFile: urlESRIFileShp.��
Maybe it's related with the fact they are encoded as koi8r?
I checked with Zinc downloading first from the browser:
��
| shpFile | �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� ��
shpFile := 'ne_110m_admin_0_countries.shp' asFileReference.
[ shpFile binaryReadStreamDo: [ : in |
�� �� �� �� �� �� �� �� (ZnCharacterEncoder detectEncoding: in upToEnd) identifier ] ]
�� �� �� �� on: ZnCharacterEncodingError
�� �� �� �� do: [ nil ].��
��
Cheers,
��
Hern��n
��
��