[Thread Prev][Thread Next][Index]

Re: [ferret_users] SHAPEFILE_READXY



Hi Josh,

Do you have the PyShp Python package installed in the Python being used by PyFerret?
The SHAPEFILE_... functions use this package to do the actual reading and writing of the shapefile files.
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 (I have seen the packages names pyshp and python-pyshp)

The following is to help clarify using the SHAPEFILE_READXY function.  I downloaded the 2010 US Counties shapefile, which actually is the following files:
    tl_2010_us_county10.dbf
    tl_2010_us_county10.prj
    tl_2010_us_county10.shp
    tl_2010_us_county10.shp.xml
    tl_2010_us_county10.shx

I am able to read and work with this shapefile using the ferret commands.
    set mem /size=500
    let uscounties = shapefile_readxy("tl_2010_us_county10", 7560000)
    load /perm uscounties
    let uscounties_poslon = if uscounties ge 0.0 then uscounties else 360.0 + uscounties
    plot /line=7 /vs /hlimits=235:250 /vlimits=42:50 uscounties_poslon[j=1],uscounties[j=2]
    frame /file=uscounties_test.png

I happen to know there are no more that 7560000 coordinates so the function call returns immediately (without reading anything).  Iif you did not know the count, you can use -1 and it will do an initial read of the shapefile to get the number of coordinates (so it will take awhile to do the initial read).  You may need to increase the amount of allowed memory (as was done here) if you are reading a large shapefile.  Note that shapefile coordinates are just numbers, not necessarily longitude and latitude.  The .prj file is there to explain these numbers, but I do not know how much the PyShp package makes use of this file.  The returned value is an array of X,Y coordinates, where X values are at [J=1] and Y values are at [J=2].  The plot in this example is just an ordinary X-Y plot (after adjusting the X values - which happen to be longitudes in this case - to positive values).

Karl


On Tue, Jul 16, 2019 at 2:49 AM JoshAB1995@xxxxxxxxxxx <JoshAB1995@xxxxxxxxxxx> wrote:

Hi everyone.

 

I’ve been trying to read in a shapefile to PyFerret with which I want to create a mask using the shapefiles that it contains. I’ve tried following the instructions on the website to using this code:

 

SHAPEFILE_READXY(SHAPEFILE, MAXPTS)

Returns X, Y coordinates of shapes from shapefile. Missing value separates shapes.

However I keep getting errors:

 

yes? SHAPEFILE_READXY("./ospar_polygon_wdpa_simplified.shp",100000)

**ERROR: command syntax: SHAPEFILE_READXY("./ospar_polygon_wdpa_simplified.shp",100000)

 

yes? let MPA = SHAPEFILE_READXY("./ospar_polygon_wdpa_simplified.shp",100000)

**ERROR: command syntax: SHAPEFILE_READXY("./ospar_polygon_wdpa_simplified.shp",100000)

          unknown function "SHAPEFILE_READXY"

 

Does anyone know why this is happening, is it something that I need to manually add to PyFerret or should it find the function itself?

 

Many thanks,

Josh

 

Sent from Mail for Windows 10

 



--
Karl M. Smith, Ph.D.
JISAO Univ. Wash. and PMEL NOAA
"The contents of this message are mine personally and do
not necessarily reflect any position of the Government
or the National Oceanic and Atmospheric Administration."

[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement