reading shapefiles & IDL objects [message #78778] |
Tue, 20 December 2011 15:48  |
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   |
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   |
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   |
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 #80605 is a reply to message #78778] |
Thu, 28 June 2012 15:00  |
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  |
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!
|
|
|