comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » reading shapefiles & IDL objects
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
reading shapefiles & IDL objects [message #78778] Tue, 20 December 2011 15:48 Go to next message
desertdryad is currently offline  desertdryad
Messages: 39
Registered: August 2011
Member
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.
Re: reading shapefiles & IDL objects [message #78842 is a reply to message #78778] Wed, 21 December 2011 13:27 Go to previous messageGo to next message
desertdryad is currently offline  desertdryad
Messages: 39
Registered: August 2011
Member
On Dec 21, 2:16 pm, desertdryad <dry...@gmail.com> wrote:
>> 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 :)
Re: reading shapefiles & IDL objects [message #78844 is a reply to message #78778] Wed, 21 December 2011 13:16 Go to previous messageGo to next message
desertdryad is currently offline  desertdryad
Messages: 39
Registered: August 2011
Member
> 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!!
Re: reading shapefiles & IDL objects [message #78849 is a reply to message #78778] Wed, 21 December 2011 12:12 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
desertdryad writes:

> 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!

> 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.")
Re: reading shapefiles & IDL objects [message #78850 is a reply to message #78778] Wed, 21 December 2011 11:04 Go to previous messageGo to next message
desertdryad is currently offline  desertdryad
Messages: 39
Registered: August 2011
Member
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?
Re: reading shapefiles & IDL objects [message #78852 is a reply to message #78778] Wed, 21 December 2011 10:13 Go to previous messageGo to next message
desertdryad is currently offline  desertdryad
Messages: 39
Registered: August 2011
Member
> Try your program with the "states.shp" file in the IDL
> distribution:

Duh! Brilliant debug idea, David; why didn't I think of that.

And it works. (sigh) Back to the drawing board.....
Re: reading shapefiles & IDL objects [message #78854 is a reply to message #78778] Wed, 21 December 2011 10:10 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
desertdryad writes:

> 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.")
Re: reading shapefiles & IDL objects [message #80605 is a reply to message #78778] Thu, 28 June 2012 15:00 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
kristen234@gmail.com writes:

> 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.")
Re: reading shapefiles & IDL objects [message #84682 is a reply to message #78842] Thu, 28 June 2012 14:40 Go to previous message
kristen234 is currently offline  kristen234
Messages: 1
Registered: June 2012
Junior Member
On Wednesday, December 21, 2011 2:27:27 PM UTC-7, desertdryad wrote:
> On Dec 21, 2:16 pm, desertdryad <dry...@gmail.com> wrote:
>>> 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!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Widget Object graphics code crashes V8.2
Next Topic: Re: IDL/ENVI Attempt to call undefined procedure/function - ENVI_PROJ_CREATE

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 16:04:53 PDT 2025

Total time taken to generate the page: 0.00675 seconds