Using Shapefiles in PyFerret
Question:
Can I use Shapefiles in Ferret or PyFerret?
Solution:
PyFerret has a set of SHAPEFILE* functions to read and write shapefiles. (Try SHOW FUNCTION or SHOW FUNCTION/DETAILS for more information).
yes? show function/brief shape* SHAPEFILE_READXY(SHAPEFILE,MAXPTS) SHAPEFILE_READXYVAL(SHAPEFILE,VALNAME,MAXPTS) SHAPEFILE_READXYZ(SHAPEFILE,MAXPTS) SHAPEFILE_READXYZVAL(SHAPEFILE,VALNAME,MAXPTS) SHAPEFILE_WRITEVAL(SHAPEFILE,VALUE,VALNAME,MAPPRJ) SHAPEFILE_WRITEXYVAL(SHAPEFILE,GRIDX,GRIDY,VALUE,VALNAME,MAPPRJ) SHAPEFILE_WRITEXYZVAL(SHAPEFILE,GRIDX,GRIDY,GRIDZ,VALUE,VALNAME,MAPPRJ)
These use the PyShp Python package, so you will need to make sure that PyShp is installed. The PyShp package (see: https://pypi.org/project/pyshp/ ) is pure Python code and can be installed using "pip" or possibly through your system's package manager (We have seen it under the package names pyshp and python-pyshp).
Example:
tl_2010_us_county10.prj
tl_2010_us_county10.shp
tl_2010_us_county10.shp.xml
tl_2010_us_county10.shx
Read and work with this shapefile using these commands from PyFerret's "ferret" command line:
yes? set mem /size=500 yes? let uscounties = shapefile_readxy("tl_2010_us_county10", 7560000) yes? load /perm uscounties yes? let uscounties_poslon = if uscounties ge 0.0 then uscounties else 360.0 + uscounties yes? plot /line=7 /vs /hlimits=235:250 /vlimits=42:50 uscounties_poslon[j=1],uscounties[j=2]