Re: [gdal-dev] cropping a tif with lat/lon

2011-04-22 Thread Chaitanya kumar CH
Dan,

Can you tell what your error message was?

On Thu, Apr 21, 2011 at 1:41 AM, spalt d...@nac.net wrote:

 Hi there!

 Please forgive this terribly newbie question.  Been searching all day and I
 just don't get it.

 I have a geotiff VFR image from the FAA with the following coordinates as
 reported by gdalinfo:

 Upper Left  ( -143411.876,   94058.326) ( 78d44'4.05W, 39d49'53.24N)
 Lower Left  ( -143411.876,  -93607.521) ( 78d41'40.46W, 38d 7'55.46N)
 Upper Right (  111698.876,   94058.326) ( 75d44'16.70W, 39d50'10.29N)
 Lower Right (  111698.876,  -93607.521) ( 75d46'8.55W, 38d 8'12.11N)
 Center  (  -15856.500, 225.403) ( 77d14'2.52W, 38d59'36.84N)

 I would like to crop the file as follows:
 West_Bounding_Coordinate: -78.734457
 East_Bounding_Coordinate: -75.737971
 North_Bounding_Coordinate: 39.843493
 South_Bounding_Coordinate: 38.132073

 I guess the problem is I need to convert the -78.734457 into paramaters for
 gdal_translate, but when I run this it gives an error:

 gdal_translate -projwin -78.734457 39.843493 -75.737971 38.132073 in.tif
 out.tif

 What am I missing?  Thanks!!

 -Dan

 --
 View this message in context:
 http://osgeo-org.1803224.n2.nabble.com/cropping-a-tif-with-lat-lon-tp6292065p6292065.html
 Sent from the GDAL - Dev mailing list archive at Nabble.com.
 ___
 gdal-dev mailing list
 gdal-dev@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/gdal-dev




-- 
Best regards,
Chaitanya kumar CH.
/tʃaɪθənjə/ /kʊmɑr/
+91-9494447584
17.2416N 80.1426E
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

[gdal-dev] Extract Extent or Bounding Box for a subset of shapes for a shapefile

2011-04-22 Thread Matthew Pettis
Hi All,

I think this is the right list for the question below, as I cannot find a
different list that matches my question better.

I'm using ogr2ogr and ogrinfo (v1.4), and I want to extract the extent from
the result of a subsetting where argument.  I have a solution here that
works but I'm wondering if I'm missing some more obvious solution.  In a
bash script, I do the following (the core snippet only, as I took out the
shebang and option-getting/setting code:)

---
rm -rf /tmp/tmpshpfile.*

ogr2ogr -where $WHERECLAUSE /tmp/tmpshpfile.shp $FILE

ogrinfo -ro -so -al /tmp/tmpshpfile.shp | \
grep Extent | \
tr -d '[:alpha:]:() -' | \
tr ',' ' '

rm -rf /tmp/tmpshpfile.*
---

I can use it as follows:

---
$ ./bbox.sh -f /path/to/shp/shp_counties.shp -w COUNTY_NAME='Yellow
Medicine'
226206.484375 4934737.00313007.25 4979500.50
---

Where the argument to '-w' is put into the '$WHERECLAUSE' variable in the
script.

This works.  As I wrote, though, am I missing something obvious in
command-line switches to either of these programs that would simplify this
so I wouldn't have to use this script?  Or is there some other, better way
of doing this?  Also, is there a way to pipe the output of ogr2ogr on stdout
directly to the stdin of ogrinfo?

Thanks,
Matt
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Re: [gdal-dev] Extract Extent or Bounding Box for a subset of shapes for a shapefile

2011-04-22 Thread Chaitanya kumar CH
Sig,

ogrinfo doesn't force the recomputation of extent. It is considered as a
costly operation. ogrinfo just reports the stored extent.
Whereas in ogr2ogr, creating a new file automatically computes the extents.

On Fri, Apr 22, 2011 at 7:44 PM, Luca Sigfrido Percich
sigfr...@tiscali.itwrote:


 Hi Matthew,

 Your question is interesting. ogrinfo -where seemed to be the answer,
 but...

 I tried ogrinfo with the -where sql where option with both MapInfo and
 PostGIS layers. In your case it should be:

 ogrinfo -ro -so -al -where $WHERECLAUSE whole_shapefile.shp

 The returned extent is always the same, regardless of the presence or
 composition of the -where clause, so it refers to the whole layer rather
 than to the selected features.
 (I'm using GDAL 1.9 dev)

 Is this the expected behaviour of ogrinfo -where ...? Or sould -where
 affect the returned Extent too?

 Thank you all

 Sig

 Il giorno ven, 22/04/2011 alle 08.22 -0500, Matthew Pettis ha scritto:
  Hi All,
 
 
  I think this is the right list for the question below, as I cannot
  find a different list that matches my question better.
 
 
  I'm using ogr2ogr and ogrinfo (v1.4), and I want to extract the extent
  from the result of a subsetting where argument.  I have a solution
  here that works but I'm wondering if I'm missing some more obvious
  solution.  In a bash script, I do the following (the core snippet
  only, as I took out the shebang and option-getting/setting code:)
 
 
  ---
  rm -rf /tmp/tmpshpfile.*
 
 
  ogr2ogr -where $WHERECLAUSE /tmp/tmpshpfile.shp $FILE
 
 
  ogrinfo -ro -so -al /tmp/tmpshpfile.shp | \
  grep Extent | \
  tr -d '[:alpha:]:() -' | \
  tr ',' ' '
 
 
  rm -rf /tmp/tmpshpfile.*
  ---
 
 
  I can use it as follows:
 
 
  ---
  $ ./bbox.sh -f /path/to/shp/shp_counties.shp -w COUNTY_NAME='Yellow
  Medicine'
  226206.484375 4934737.00313007.25 4979500.50
  ---
 
 
  Where the argument to '-w' is put into the '$WHERECLAUSE' variable in
  the script.
 
 
  This works.  As I wrote, though, am I missing something obvious in
  command-line switches to either of these programs that would simplify
  this so I wouldn't have to use this script?  Or is there some other,
  better way of doing this?  Also, is there a way to pipe the output of
  ogr2ogr on stdout directly to the stdin of ogrinfo?
 
 
  Thanks,
  Matt
  ___
  gdal-dev mailing list
  gdal-dev@lists.osgeo.org
  http://lists.osgeo.org/mailman/listinfo/gdal-dev

 ___
 gdal-dev mailing list
 gdal-dev@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/gdal-dev




-- 
Best regards,
Chaitanya kumar CH.
/tʃaɪθənjə/ /kʊmɑr/
+91-9494447584
17.2416N 80.1426E
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Re: [gdal-dev] Extract Extent or Bounding Box for a subset of shapes for a shapefile

2011-04-22 Thread Luca Sigfrido Percich
Thank you Chaitanya.

I think that this makes great sense when dealing with a summary of the
whole layer, especially because a lot of formats store the extent in the
layer metadata/header.

But if I need to dump all the features, or to get a dump or summary of a
filtered set of features (in which case I presume ogr will scan all the
features to apply the filter), checking for boundary limits shouldn't
add much cost to the already expensive operation.

Probably this goes beyond the intended scope of ogrinfo. And Matthew's
workaround works fine.

Thanks again

Sig



Il giorno ven, 22/04/2011 alle 20.20 +0530, Chaitanya kumar CH ha
scritto:
 Sig,
 
 ogrinfo doesn't force the recomputation of extent. It is considered as
 a costly operation. ogrinfo just reports the stored extent.
 Whereas in ogr2ogr, creating a new file automatically computes the
 extents.

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev


[gdal-dev] Polygonize from C# ?

2011-04-22 Thread Jay Jennings
Hi list,
Can anyone point to any guidance or (preferably) examples on using 
GDAL.Polygonize() with C# bindings ?  I see what the interface is, but there 
are some unexplained parameters, e.g. string[] options.

My eventual goal is to open a raster and produce a WKT POLYGON string enclosing 
the good (non-NoData) area of the raster.  Thanks.

.
Jay Jennings
Senior Software Developer
(NASDAQ: GEOY)
jennings@geoeye.com




___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Re: [gdal-dev] Polygonize from C# ?

2011-04-22 Thread Even Rouault
Selon Jay Jennings jennings@geoeye.com:

Generally, refering to the C/C++ doc is a good way of finding the info :

See http://gdal.org/gdal__alg_8h.html#3f522a9035d3512b5d414fb4752671b1

 Hi list,
 Can anyone point to any guidance or (preferably) examples on using
 GDAL.Polygonize() with C# bindings ?  I see what the interface is, but there
 are some unexplained parameters, e.g. string[] options.

 My eventual goal is to open a raster and produce a WKT POLYGON string
 enclosing the good (non-NoData) area of the raster.  Thanks.

 .
 Jay Jennings
 Senior Software Developer
 (NASDAQ: GEOY)
 jennings@geoeye.com







___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] gdal2tiles.py issue

2011-04-22 Thread Jerl Simpson
Thank you thank you thank you,  GREATLY appreciated!

Typed with thumbs...
On Apr 22, 2011 12:25 PM, Klokan Petr Pridal klo...@klokan.cz wrote:
 Hi Jerl,

 please read this issue report:

 http://code.google.com/p/maptiler/issues/detail?id=6

 It gives you also explanation and also workaround for this problem

 Best regards,

 Petr alias Klokan

 On Thu, Apr 21, 2011 at 5:50 PM, Jerl Simpson jsimp...@wxtrends.com
wrote:
 Hi guys:

 I posted a similar question a week or so ago, but have slightly
 different information that might help me reach a solution.

 I'm using gdal2tiles.py to tile up an image for google maps.  It works
 great right up to the 180th meridian.  That's where it introduces a
 transparent strip on the edge of the image.
 Here's the original image:  http://maps.craniumjuice.com/TMXF.png
 Here's a screen shot showing the gap:
http://maps.craniumjuice.com/gap.png

 If I slice up the original file using imagemagick, there's no gap at
 the border. It takes forever and I didn't get a screen shot.  Plus the
 Y values are flipped so it doesn't overlay properly, it was just a
 proof of concept that the full image is really there, it definitely
 is.

 Any ideas what could be causing the transparent strip at the end?

 This gdal2tiles.py command gives me the gap from the screen shot:
 gdal2tiles.py -s EPSG:4326 -z 2 TMXF.png .

 I also tried treating it as just a raster file and got really bizarre
results:
 gdal2tiles.py -p raster -z 2 TMXF.png .

 If I use an image that's the size of the original data, I don't get
 all the images.

 If I use gdal_translate to make it a 4096x4096 image, it gives me all
 the tiles, but they're not right either.  That gives me a 64x64 image
 with the rest of the 256x256 of the image transparent.
 http://maps.craniumjuice.com/1.png

 I'm sure there's some setting or something I can do to get the full
 image tiled up with out adding these transparent stripes around the
 tile, I just can't find it.

 I'm using GDAL 1.8.0, released 2011/01/12

 I appreciate any insight you might be able to give.

 Thanks

 Jerl
 ___
 gdal-dev mailing list
 gdal-dev@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/gdal-dev




 --
 http://blog.klokan.cz/
 http://www.maptiler.org/
 http://www.oldmapsonline.org/
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

RE: [gdal-dev] Polygonize from C# ?

2011-04-22 Thread Jay Jennings
I see, thanks.  But since I have satellite images, this part of the doc is 
alarming: ...For non-thematic raster data (such as satellite images) 
the result will essentially be one small polygon per pixel, and memory and 
output layer sizes will be substantial. The algorithm is primarily 
intended for relatively simple thematic imagery, masks, and classification 
results.

I just want one polygon enclosing the non-zero pixels (or alternatively, 
enclosing the zero pixels, then I could do a geometric 
difference).  Is there any way to trick the method into doing that, to maybe 
avoid the heavy resource needs ?


-Original Message-
From: Even Rouault [mailto:even.roua...@mines-paris.org] 
Sent: Friday, April 22, 2011 11:45 AM
To: Jay Jennings
Cc: gdal-dev@lists.osgeo.org
Subject: Re: [gdal-dev] Polygonize from C# ?

Selon Jay Jennings jennings@geoeye.com:

Generally, refering to the C/C++ doc is a good way of finding the info :

See http://gdal.org/gdal__alg_8h.html#3f522a9035d3512b5d414fb4752671b1

 Hi list,
 Can anyone point to any guidance or (preferably) examples on using
 GDAL.Polygonize() with C# bindings ?  I see what the interface is, but there
 are some unexplained parameters, e.g. string[] options.

 My eventual goal is to open a raster and produce a WKT POLYGON string
 enclosing the good (non-NoData) area of the raster.  Thanks.

 .
 Jay Jennings
 Senior Software Developer
 (NASDAQ: GEOY)
 jennings@geoeye.com







___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] Polygonize from C# ?

2011-04-22 Thread Elijah Robison
Jay, do you basically want a footprint shape of the useful data in the 
Sat images (say, without the collar), or is the problem more complex, 
where perhaps you have a mosaic of several images and, like swiss 
cheese, there are no-data holes within the image?


It sounds to me like you just want a footprint of the collarless area; 
is this correct? 


/Elijah

Jay Jennings wrote:
I see, thanks.  But since I have satellite images, this part of the doc is alarming: ...For non-thematic raster data (such as satellite images) 
the result will essentially be one small polygon per pixel, and memory and output layer sizes will be substantial. The algorithm is primarily 
intended for relatively simple thematic imagery, masks, and classification results.


I just want one polygon enclosing the non-zero pixels (or alternatively, enclosing the zero pixels, then I could do a geometric 
difference).  Is there any way to trick the method into doing that, to maybe avoid the heavy resource needs ?



-Original Message-
From: Even Rouault [mailto:even.roua...@mines-paris.org] 
Sent: Friday, April 22, 2011 11:45 AM

To: Jay Jennings
Cc: gdal-dev@lists.osgeo.org
Subject: Re: [gdal-dev] Polygonize from C# ?

Selon Jay Jennings jennings@geoeye.com:

Generally, refering to the C/C++ doc is a good way of finding the info :

See http://gdal.org/gdal__alg_8h.html#3f522a9035d3512b5d414fb4752671b1

  

Hi list,
Can anyone point to any guidance or (preferably) examples on using
GDAL.Polygonize() with C# bindings ?  I see what the interface is, but there
are some unexplained parameters, e.g. string[] options.

My eventual goal is to open a raster and produce a WKT POLYGON string
enclosing the good (non-NoData) area of the raster.  Thanks.

.
Jay Jennings
Senior Software Developer
(NASDAQ: GEOY)
jennings@geoeye.com









___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

  

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev


RE: [gdal-dev] Polygonize from C# ?

2011-04-22 Thread Jay Jennings
Correct, we just need the footprint of the good (non-NODATA) area, which will 
often approximate a simple 4-point polygon with no holes.

-Original Message-
From: Elijah Robison [mailto:eli...@villagis.com] 
Sent: Friday, April 22, 2011 2:07 PM
To: Jay Jennings
Cc: gdal-dev@lists.osgeo.org
Subject: Re: [gdal-dev] Polygonize from C# ?

Jay, do you basically want a footprint shape of the useful data in the 
Sat images (say, without the collar), or is the problem more complex, 
where perhaps you have a mosaic of several images and, like swiss 
cheese, there are no-data holes within the image?

It sounds to me like you just want a footprint of the collarless area; 
is this correct? 

/Elijah

Jay Jennings wrote:
 I see, thanks.  But since I have satellite images, this part of the doc is 
 alarming: ...For non-thematic raster data (such as satellite images) 
 the result will essentially be one small polygon per pixel, and memory and 
 output layer sizes will be substantial. The algorithm is primarily 
 intended for relatively simple thematic imagery, masks, and classification 
 results.

 I just want one polygon enclosing the non-zero pixels (or alternatively, 
 enclosing the zero pixels, then I could do a geometric 
 difference).  Is there any way to trick the method into doing that, to maybe 
 avoid the heavy resource needs ?


 -Original Message-
 From: Even Rouault [mailto:even.roua...@mines-paris.org] 
 Sent: Friday, April 22, 2011 11:45 AM
 To: Jay Jennings
 Cc: gdal-dev@lists.osgeo.org
 Subject: Re: [gdal-dev] Polygonize from C# ?

 Selon Jay Jennings jennings@geoeye.com:

 Generally, refering to the C/C++ doc is a good way of finding the info :

 See http://gdal.org/gdal__alg_8h.html#3f522a9035d3512b5d414fb4752671b1

   
 Hi list,
 Can anyone point to any guidance or (preferably) examples on using
 GDAL.Polygonize() with C# bindings ?  I see what the interface is, but there
 are some unexplained parameters, e.g. string[] options.

 My eventual goal is to open a raster and produce a WKT POLYGON string
 enclosing the good (non-NoData) area of the raster.  Thanks.

 .
 Jay Jennings
 Senior Software Developer
 (NASDAQ: GEOY)
 jennings@geoeye.com





 


 ___
 gdal-dev mailing list
 gdal-dev@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/gdal-dev

   
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] Polygonize from C# ?

2011-04-22 Thread Elijah Robison
Hi Jay, you might want to review the following thread (Get extent from 
rasters).  Based on a cursory read of his advice, I believe Trent offers 
a solution that might accommodate your task:  
http://lists.maptools.org/pipermail/fwtools/2010-October/001886.html


/Elijah


Jay Jennings wrote:

Correct, we just need the footprint of the good (non-NODATA) area, which will 
often approximate a simple 4-point polygon with no holes.

-Original Message-
From: Elijah Robison [mailto:eli...@villagis.com] 
Sent: Friday, April 22, 2011 2:07 PM

To: Jay Jennings
Cc: gdal-dev@lists.osgeo.org
Subject: Re: [gdal-dev] Polygonize from C# ?

Jay, do you basically want a footprint shape of the useful data in the 
Sat images (say, without the collar), or is the problem more complex, 
where perhaps you have a mosaic of several images and, like swiss 
cheese, there are no-data holes within the image?


It sounds to me like you just want a footprint of the collarless area; 
is this correct? 


/Elijah

Jay Jennings wrote:
  
I see, thanks.  But since I have satellite images, this part of the doc is alarming: ...For non-thematic raster data (such as satellite images) 
the result will essentially be one small polygon per pixel, and memory and output layer sizes will be substantial. The algorithm is primarily 
intended for relatively simple thematic imagery, masks, and classification results.


I just want one polygon enclosing the non-zero pixels (or alternatively, enclosing the zero pixels, then I could do a geometric 
difference).  Is there any way to trick the method into doing that, to maybe avoid the heavy resource needs ?



-Original Message-
From: Even Rouault [mailto:even.roua...@mines-paris.org] 
Sent: Friday, April 22, 2011 11:45 AM

To: Jay Jennings
Cc: gdal-dev@lists.osgeo.org
Subject: Re: [gdal-dev] Polygonize from C# ?

Selon Jay Jennings jennings@geoeye.com:

Generally, refering to the C/C++ doc is a good way of finding the info :

See http://gdal.org/gdal__alg_8h.html#3f522a9035d3512b5d414fb4752671b1

  


Hi list,
Can anyone point to any guidance or (preferably) examples on using
GDAL.Polygonize() with C# bindings ?  I see what the interface is, but there
are some unexplained parameters, e.g. string[] options.

My eventual goal is to open a raster and produce a WKT POLYGON string
enclosing the good (non-NoData) area of the raster.  Thanks.

.
Jay Jennings
Senior Software Developer
(NASDAQ: GEOY)
jennings@geoeye.com






  

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

  



  

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] Polygonize from C# ?

2011-04-22 Thread Luiz Motta
Jay,

I made the plugin for QGIS, where, calculate the  boundary of image
with pixel value upper to zero, i believe is what you want,
footprint shape.

The plugin read all images of directories and create one vector layer
with all boundary of images.

For calculate, the background of image need have pixel value equal a zero.

I wrote the program with  Python, but, i called the GDAL  functions
for calculus.

The name of plugin is Image Boundary, and you can install inside
QGIS(contributed repository), or read the source by
http://spatialserver.net/pyqgis_1.0/contributed/imgboundary.zip

Regards,
Luiz Motta

2011/4/22 Jay Jennings jennings@geoeye.com:
 Correct, we just need the footprint of the good (non-NODATA) area, which 
 will often approximate a simple 4-point polygon with no holes.

 -Original Message-
 From: Elijah Robison [mailto:eli...@villagis.com]
 Sent: Friday, April 22, 2011 2:07 PM
 To: Jay Jennings
 Cc: gdal-dev@lists.osgeo.org
 Subject: Re: [gdal-dev] Polygonize from C# ?

 Jay, do you basically want a footprint shape of the useful data in the
 Sat images (say, without the collar), or is the problem more complex,
 where perhaps you have a mosaic of several images and, like swiss
 cheese, there are no-data holes within the image?

 It sounds to me like you just want a footprint of the collarless area;
 is this correct?

 /Elijah

 Jay Jennings wrote:
 I see, thanks.  But since I have satellite images, this part of the doc is 
 alarming: ...For non-thematic raster data (such as satellite images)
 the result will essentially be one small polygon per pixel, and memory and 
 output layer sizes will be substantial. The algorithm is primarily
 intended for relatively simple thematic imagery, masks, and classification 
 results.

 I just want one polygon enclosing the non-zero pixels (or alternatively, 
 enclosing the zero pixels, then I could do a geometric
 difference).  Is there any way to trick the method into doing that, to maybe 
 avoid the heavy resource needs ?


 -Original Message-
 From: Even Rouault [mailto:even.roua...@mines-paris.org]
 Sent: Friday, April 22, 2011 11:45 AM
 To: Jay Jennings
 Cc: gdal-dev@lists.osgeo.org
 Subject: Re: [gdal-dev] Polygonize from C# ?

 Selon Jay Jennings jennings@geoeye.com:

 Generally, refering to the C/C++ doc is a good way of finding the info :

 See http://gdal.org/gdal__alg_8h.html#3f522a9035d3512b5d414fb4752671b1


 Hi list,
 Can anyone point to any guidance or (preferably) examples on using
 GDAL.Polygonize() with C# bindings ?  I see what the interface is, but there
 are some unexplained parameters, e.g. string[] options.

 My eventual goal is to open a raster and produce a WKT POLYGON string
 enclosing the good (non-NoData) area of the raster.  Thanks.

 .
 Jay Jennings
 Senior Software Developer
 (NASDAQ: GEOY)
 jennings@geoeye.com








 ___
 gdal-dev mailing list
 gdal-dev@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/gdal-dev


 ___
 gdal-dev mailing list
 gdal-dev@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/gdal-dev

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] Extract Extent or Bounding Box for a subset of shapes for a shapefile

2011-04-22 Thread Marius Jigmond
Luca,

You can also loop through the features with relatively simple Python
code to get the extents. See sample below (adapt at will):

def findPoints(geometry, results):
  for i in range(geometry.GetPointCount()):
x,y,z = geometry.GetPoint(i)
if results['north'] == None or results['north'][1]  y:
  results['north'] = (x,y)
if results['south'] == None or results['south'][1]  y:
  results['south'] = (x,y)
if results['east'] == None or results['east'][0]  x:
  results['east'] = (x,y)
if results['west'] == None or results['west'][0]  x:
  results['west'] = (x,y)
  for i in range(geometry.GetGeometryCount()):
findPoints(geometry.GetGeometryRef(i), results)

inSHP = 'test.shp'
shapefile = osgeo.ogr.Open(inSHP)
layer = shapefile.GetLayer(0)
for feat in range(layer.GetFeatureCount()):
feature = layer.GetFeature(feat)
geometry = feature.GetGeometryRef()
results = {'north' : None, 'south' : None, 'east' : None, 'west' :
None}
findPoints(geometry, results)

-marius

On Fri, 2011-04-22 at 17:39 +0200, Luca Sigfrido Percich wrote:
 Thank you Chaitanya.
 
 I think that this makes great sense when dealing with a summary of the
 whole layer, especially because a lot of formats store the extent in the
 layer metadata/header.
 
 But if I need to dump all the features, or to get a dump or summary of a
 filtered set of features (in which case I presume ogr will scan all the
 features to apply the filter), checking for boundary limits shouldn't
 add much cost to the already expensive operation.
 
 Probably this goes beyond the intended scope of ogrinfo. And Matthew's
 workaround works fine.
 
 Thanks again
 
 Sig
 
 
 
 Il giorno ven, 22/04/2011 alle 20.20 +0530, Chaitanya kumar CH ha
 scritto:
  Sig,
  
  ogrinfo doesn't force the recomputation of extent. It is considered as
  a costly operation. ogrinfo just reports the stored extent.
  Whereas in ogr2ogr, creating a new file automatically computes the
  extents.
 
 ___
 gdal-dev mailing list
 gdal-dev@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/gdal-dev
 

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev