Discussion:
reading shapefiles & IDL objects
(too old to reply)
desertdryad
2011-12-20 23:48:59 UTC
Permalink
I'm trying to write a function that can read GIS shapefiles in IDL.
I'm new to this and to using objects in IDL; but I seem to be stuck
right at the gate for reasons I cannot fathom. Here is the snipet of
code at hte beginning of my function:

-------------------------

function readshape, filename

; test script for reading a shapefile into idl and finding data
contained w/in

myshape = obj_new('IDLffShape', filename)
help, myshape

--------------------------

Now, I know for certain that the shapefile exists whose name gets
passed as 'filename' and I've specified the path at the command line.
Yet, I get this error:

ENVI> testme = readshape('C:\\etotest\pivot6.shp')

MYSHAPE OBJREF = <NullObject>
% Stop encountered: READSHAPE 7 C:\Cyndys\Default
\readshape.pro


What on Earth am I doing wrong, here? Please advise.
David Fanning
2011-12-21 03:56:31 UTC
Permalink
Post by desertdryad
Now, I know for certain that the shapefile exists whose name gets
passed as 'filename' and I've specified the path at the command line.
ENVI> testme = readshape('C:\\etotest\pivot6.shp')
MYSHAPE OBJREF = <NullObject>
% Stop encountered: READSHAPE 7 C:\Cyndys\Default
\readshape.pro
What on Earth am I doing wrong, here? Please advise.
It looks to me like there is an extra slash in the
filename. Shouldn't the file name be this:

filename = 'C:\etotest\pivot6.shp'

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
desertdryad
2011-12-21 16:06:49 UTC
Permalink
Post by David Fanning
Post by desertdryad
Now, I know for certain that the shapefile exists whose name gets
passed as 'filename' and I've specified the path at the command line.
ENVI> testme = readshape('C:\\etotest\pivot6.shp')
MYSHAPE         OBJREF    = <NullObject>
% Stop encountered: READSHAPE           7 C:\Cyndys\Default
\readshape.pro
What on Earth am I doing wrong, here?  Please advise.
It looks to me like there is an extra slash in the
   filename = 'C:\etotest\pivot6.shp'
Yes; but it makes no difference!
David Fanning
2011-12-21 16:09:32 UTC
Permalink
Post by desertdryad
Yes; but it makes no difference!
Well, then I would say there is something wrong with
your ReadShape program. Typo?

Set a breakpoint and have a look around. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Russell
2011-12-21 16:18:38 UTC
Permalink
Are you sure that the file 'pivot6.shp' is a valid shape file?

IDLffShape will return a null pointer if the file is invalid....


Russell
Post by desertdryad
Post by David Fanning
Post by desertdryad
Now, I know for certain that the shapefile exists whose name gets
passed as 'filename' and I've specified the path at the command line.
ENVI> testme = readshape('C:\\etotest\pivot6.shp')
MYSHAPE         OBJREF    = <NullObject>
% Stop encountered: READSHAPE           7 C:\Cyndys\Default
\readshape.pro
What on Earth am I doing wrong, here?  Please advise.
It looks to me like there is an extra slash in the
   filename = 'C:\etotest\pivot6.shp'
Yes; but it makes no difference!
desertdryad
2011-12-21 18:00:04 UTC
Permalink
I am sure it's a valid file; I just checked.

And nothing happens in the procedure before the bit i posted!

Next question - is there any possibility my installation of IDL does
not have IDLffShape defined?
How could I check? I didn't install the software on my machine; it
was done before my time here where I work.
David Fanning
2011-12-21 18:10:50 UTC
Permalink
Post by desertdryad
I am sure it's a valid file; I just checked.
And nothing happens in the procedure before the bit i posted!
Next question - is there any possibility my installation of IDL does
not have IDLffShape defined?
I don't think so.

Try your program with the "states.shp" file in the IDL
distribution:

filename = Filepath(Subdir=['examples','data'], 'states.shp')

If it doesn't work with that, something is *seriously* wrong. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
desertdryad
2011-12-21 18:13:49 UTC
Permalink
Post by David Fanning
Try your program with the "states.shp" file in the IDL
Duh! Brilliant debug idea, David; why didn't I think of that.

And it works. (sigh) Back to the drawing board.....
desertdryad
2011-12-21 19:04:07 UTC
Permalink
Ok, I've managed to read in my shapefile (I seemed to have to put my
shapefile where the 'states.shp' file was, at lest for now). But I'm
not sure how to so what I want to do with it! I want to correlate the
location of the entities in my shapefile with an image that covers the
same geographic extent. In other words, I want to know what the
coordinates of the entities are so that I can extract the date in the
image that they overlay - I don't need to draw the shapefile on the
image/map, but I do need to know where on the map its entities are.
I'm not seeing an obvious way to do that?
David Fanning
2011-12-21 20:12:24 UTC
Permalink
Post by desertdryad
Ok, I've managed to read in my shapefile (I seemed to have to put my
shapefile where the 'states.shp' file was, at lest for now).
This suggests to me that your "shape" file doesn't have all
the other pieces that a shape file needs. In other words,
the *.shx and *.dbf files have to be in the same directory
as the *.shp file, or the shape file ain't a shape file!
Post by desertdryad
But I'm
not sure how to so what I want to do with it! I want to correlate the
location of the entities in my shapefile with an image that covers the
same geographic extent. In other words, I want to know what the
coordinates of the entities are so that I can extract the date in the
image that they overlay - I don't need to draw the shapefile on the
image/map, but I do need to know where on the map its entities are.
I'm not seeing an obvious way to do that?
The simplest way is just to march through the entities
and keep track of the entities's bounds. This is how
cgDrawShapes works, when you set the AutoDraw keyword.

FOR j=0,N_Elements(*entities)-1 DO BEGIN
thisEntity = (*entities)[j]
entityMinX[j] = thisEntity.bounds[0]
entityMaxX[j] = thisEntity.bounds[4]
entityMiny[j] = thisEntity.bounds[1]
entityMaxY[j] = thisEntity.bounds[5]
ENDFOR
xrange = [Min(entityMinX), Max(entityMaxX)]
yrange = [Min(entityMinY), Max(entityMaxY)]
cgPlot, xrange, yrange, ....

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
desertdryad
2011-12-21 21:16:53 UTC
Permalink
Post by David Fanning
The simplest way is just to march through the entities
and keep track of the entities's bounds. This is how
cgDrawShapes works, when you set the AutoDraw keyword.
       FOR j=0,N_Elements(*entities)-1 DO BEGIN
          thisEntity = (*entities)[j]
          entityMinX[j] =  thisEntity.bounds[0]
          entityMaxX[j] =  thisEntity.bounds[4]
          entityMiny[j] =  thisEntity.bounds[1]
          entityMaxY[j] =  thisEntity.bounds[5]
       ENDFOR
       xrange = [Min(entityMinX), Max(entityMaxX)]
       yrange = [Min(entityMinY), Max(entityMaxY)]
       cgPlot, xrange, yrange, ....
Cheers,
David
I think I get that. Thanks, David!!
desertdryad
2011-12-21 21:27:27 UTC
Permalink
Post by David Fanning
The simplest way is just to march through the entities
and keep track of the entities's bounds. This is how
cgDrawShapes works, when you set the AutoDraw keyword.
       FOR j=0,N_Elements(*entities)-1 DO BEGIN
          thisEntity = (*entities)[j]
          entityMinX[j] =  thisEntity.bounds[0]
          entityMaxX[j] =  thisEntity.bounds[4]
          entityMiny[j] =  thisEntity.bounds[1]
          entityMaxY[j] =  thisEntity.bounds[5]
       ENDFOR
       xrange = [Min(entityMinX), Max(entityMaxX)]
       yrange = [Min(entityMinY), Max(entityMaxY)]
       cgPlot, xrange, yrange, ....
Cheers,
David
I think I get that.  Thanks, David!!
PS - all the pieces are in the same directory.. I know GIS better than
I know IDL :)
k***@gmail.com
2012-06-28 21:40:41 UTC
Permalink
Post by desertdryad
Post by David Fanning
The simplest way is just to march through the entities
and keep track of the entities's bounds. This is how
cgDrawShapes works, when you set the AutoDraw keyword.
       FOR j=0,N_Elements(*entities)-1 DO BEGIN
          thisEntity = (*entities)[j]
          entityMinX[j] =  thisEntity.bounds[0]
          entityMaxX[j] =  thisEntity.bounds[4]
          entityMiny[j] =  thisEntity.bounds[1]
          entityMaxY[j] =  thisEntity.bounds[5]
       ENDFOR
       xrange = [Min(entityMinX), Max(entityMaxX)]
       yrange = [Min(entityMinY), Max(entityMaxY)]
       cgPlot, xrange, yrange, ....
Cheers,
David
I think I get that.  Thanks, David!!
PS - all the pieces are in the same directory.. I know GIS better than
I know IDL :)
Did you ever figure out why moving your shapefile to the directory with 'states.shp' was necessary? I'm having the same problem with my shapefile, but I'm not permitted to save files to the IDL distribution directories. Thanks for the help!
David Fanning
2012-06-28 22:00:15 UTC
Permalink
Post by k***@gmail.com
Did you ever figure out why moving your shapefile to the directory with 'states.shp' was necessary? I'm having the same problem with my shapefile, but I'm not permitted to save files to the IDL distribution directories.
There is not a single valid reason why someone would
have to move their shapefile to an IDL-supplied
directory, unless it is part of some mystical
religious incantation that is similar to
crossing your eyes and sticking your tongue
out in the secular world.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Loading...