Re: IDL - Extracting data from within boundary defined by shapefile [message #73760] |
Mon, 29 November 2010 23:01  |
katie
Messages: 3 Registered: November 2010
|
Junior Member |
|
|
Thanks for your timely advice! I've never dealt with objects in IDL,
so it took me a while to figure out what you meant, and a while longer
to put it all together, but I think I've got it for the most part.
However, I'm still being held up with the ContainsPoints part. What I
have so far is below.
mrb_shapefile = 'mrb.shp'
mrb_shape = obj_new('IDLffShape',mrb_shapefile)
mrb_shape->IDLffShape::GetProperty, N_ENTITIES=num_ent,
ENTITY_TYPE=ent_type,$
ATTRIBUTE_INFO=attr_info
for i = 0L, (num_ent-1) do begin
ent = mrb_shape -> IDLffShape::GetEntity(i)
x = (*ent.vertices)[0,*]
y = (*ent.vertices)[1,*]
endfor
mrb_roi = obj_new('IDLanROI',x,y)
mrb_points = mrb_roi->IDLanROI::ContainsPoints(lon,lat)
obj_destroy,mrb_shape
obj_destroy,mrb_roi
When I run this, I get the error, "IDLANROI::CONTAINSPOINTS: Number of
LON does not match number of LAT."
The terms lon and lat are the longitudes and latitudes associated with
the soil moisture for the entire globe. There are 64 lat's and 128
lon's. So yes, they do not match, but I'm not sure what else I should
be using in the ContainsPoints function.
Another possible conflict I see here is that the longitudes within x
are negative (for being West), but the longitudes of my soil moisture
data are 0 to 360. Although, when I used MAP_SET to plot my soil
moisture data, and plot the mrb shapefile (using David Fanning's
DRAWSHAPES function) on top of it, it came out fine.
Any suggestions for the lat/lon confusion here?
Many thanks,
Katie
On Nov 27, 6:41 am, Paulo Penteado <pp.pente...@gmail.com> wrote:
> If you mean to select the points that fall into the boundary, you
> could create an IDLanROI, defined by the vertices from the shapefile.
> Then use its containspoints() method to find those inside it. That is,
> assuming that Earth's curvature is not relevant. If it is, you might
> have to change the data from lat/lon to some suitable projection.
>
> On Nov 27, 10:04 am, katie <katie.l.pi...@gmail.com> wrote:
>
>> Hello all,
>
>> I am using IDL 6.1, and was wondering if it's possible to extract data
>> (defined by lat and long gridpoints) from within a boundary defined by
>> a shapefile. For example, I have a contour map of global soil
>> moisture, but would only like to look at the data within the
>> Mississippi River Basin. I have the shapefile for this basin, and have
>> overplotted it onto the contour map so I can see the basin outline and
>> note that it is properly projected on top of my data, but I do not
>> know where to go from there.
>
>> Any advice would be great!
>> Thanks,
>> Katie
|
|
|
Re: IDL - Extracting data from within boundary defined by shapefile [message #73794 is a reply to message #73760] |
Sat, 27 November 2010 06:41   |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
If you mean to select the points that fall into the boundary, you
could create an IDLanROI, defined by the vertices from the shapefile.
Then use its containspoints() method to find those inside it. That is,
assuming that Earth's curvature is not relevant. If it is, you might
have to change the data from lat/lon to some suitable projection.
On Nov 27, 10:04 am, katie <katie.l.pi...@gmail.com> wrote:
> Hello all,
>
> I am using IDL 6.1, and was wondering if it's possible to extract data
> (defined by lat and long gridpoints) from within a boundary defined by
> a shapefile. For example, I have a contour map of global soil
> moisture, but would only like to look at the data within the
> Mississippi River Basin. I have the shapefile for this basin, and have
> overplotted it onto the contour map so I can see the basin outline and
> note that it is properly projected on top of my data, but I do not
> know where to go from there.
>
> Any advice would be great!
> Thanks,
> Katie
|
|
|
Re: IDL - Extracting data from within boundary defined by shapefile [message #73856 is a reply to message #73760] |
Tue, 30 November 2010 06:46  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Nov 30, 5:01 am, katie <katie.l.pi...@gmail.com> wrote:
Also, this loop is pointless:
> for i = 0L, (num_ent-1) do begin
> ent = mrb_shape -> IDLffShape::GetEntity(i)
> x = (*ent.vertices)[0,*]
> y = (*ent.vertices)[1,*]
> endfor
You are just overwriting x and y, and out of the loop you will only
have the x and y from the last entity.
|
|
|
Re: IDL - Extracting data from within boundary defined by shapefile [message #73857 is a reply to message #73760] |
Tue, 30 November 2010 06:36  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
katie writes:
> When I run this, I get the error, "IDLANROI::CONTAINSPOINTS: Number of
> LON does not match number of LAT."
>
> The terms lon and lat are the longitudes and latitudes associated with
> the soil moisture for the entire globe. There are 64 lat's and 128
> lon's. So yes, they do not match, but I'm not sure what else I should
> be using in the ContainsPoints function.
You actually have 64*128 points that you want to check,
so you have to make that many lats and lons:
latpts = Rebin(Reform(lat, 1, 64), 128, 64)
lonpts = Rebin(lon, 128, 64)
>
> Another possible conflict I see here is that the longitudes within x
> are negative (for being West), but the longitudes of my soil moisture
> data are 0 to 360. Although, when I used MAP_SET to plot my soil
> moisture data, and plot the mrb shapefile (using David Fanning's
> DRAWSHAPES function) on top of it, it came out fine.
>
> Any suggestions for the lat/lon confusion here?
They should be consistent, although some mapping routines,
not all, will recognize the problem and do the conversion for
you. But here is an article that describes how to covert
longitude coordinates that are in 0 to 360 to -180 to 180.
It is not as straightforward as I might appear at first
glance. :-)
http://www.dfanning.com/map_tips/lonconvert.html
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|