<div>Hi Trond,</div>
<div>&nbsp;</div>
<div>thanks for your example code. I&#39;ve coded a <a href="http://VB.NET">VB.NET</a> utility for tile index file, it should work well. Just one thing for you, don&#39;t forget to destroy&nbsp;every shapeObject after having added it to shape file, at the end to close the shape file and the attribute table.
</div>
<div>&nbsp;</div>
<div>Cheers</div>
<div>&nbsp;</div>
<div>Zhonghai<br>&nbsp;</div>
<div><span class="gmail_quote">On 9/26/07, <b class="gmail_sendername">Trond Michelsen</b> &lt;<a href="mailto:trondmm-mapserver@crusaders.no">trondmm-mapserver@crusaders.no</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">On Wed, Sep 26, 2007 at 10:35:36AM +0200, Zhonghai Wang wrote:<br>&gt; thanks you for your clues for creating the index file, I am looking forword
<br>&gt; to sharing your experience of creating the utility programmatically.<br>&gt; Actually, I create more often MapInfo seamless layer programmatically, but I<br>&gt; am not very familar with the ESRI index file format, so I am just not sure
<br>&gt; how I should use the ShapeLib to create the index file.<br><br>My initial tests were successful, and it turned out to be very easy to<br>create a tileindex for rasterimages. It&#39;s basically exactly the same<br>
as a tileindex for shapefiles.<br><br>I need to clean it up a bit, and make it possible to choose<br>outputfilename, but for now, here&#39;s a simple example:<br><br>--8&lt;--<br>#!/usr/bin/perl<br><br>use strict;<br>use warnings;
<br>use Geo::Shapelib &#39;:constants&#39;;<br><br>my $tileindex = Geo::Shapelib-&gt;new();<br><br>$tileindex-&gt;{Shapetype}&nbsp;&nbsp;= POLYGON;<br>$tileindex-&gt;{FieldNames} = [&quot;Location&quot;];<br>$tileindex-&gt;{FieldTypes} = [&quot;String:255&quot;];
<br><br>for my $filename (@ARGV) {<br>&nbsp;&nbsp; my ($xmin, $ymin, $xmax, $ymax) = get_coordinates($filename);<br>&nbsp;&nbsp; push @{$tileindex-&gt;{Shapes}}, {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SHPType&nbsp;&nbsp;=&gt; POLYGON,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Vertices =&gt; [[$xmin, $ymin],<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[$xmax, $ymin],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[$xmax, $ymax],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[$xmin, $ymax],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[$xmin, $ymin]]<br>&nbsp;&nbsp; };<br>&nbsp;&nbsp; push @{$tileindex-&gt;{ShapeRecords}}, [$filename];<br>
}<br><br>$tileindex-&gt;save(&#39;tileindex&#39;);<br><br>sub get_coordinates {<br>&nbsp;&nbsp; my $filename = shift;<br>&nbsp;&nbsp; my ($bbox) = $filename =~ /ec_world_(.*)\.png/;<br>&nbsp;&nbsp; return split &quot;,&quot; =&gt; $bbox;<br>}<br>__END__
<br>--8&lt;--<br><br>This program will take a list of files as arguments, and create a<br>tileindex, which is saved as tileindex.* in the current directory. The<br>subroutine get_coordinates() figures out what xmin, xmax, ymin and
<br>ymax is for the current rasterimage. In my case, the bbox is embedded<br>in the filename, but you might have to read a worldfile or do<br>something else for your images.<br><br>Speaking of worldfiles. The tileindex only tells mapserver which files
<br>to load for a given view. Mapserver still need the worldfiles to<br>figure out where and how each of the pictures it opens should be<br>positioned.<br><br>Anyway - just like with a tileindex for shapefiles, mapserver<br>
interprets the &quot;Location&quot; value as relative to shapepath if you use<br>relative paths. So I think it&#39;s better to use absolute paths when you<br>run the program.<br><br>To use this tileindex in a mapfile, you just include something like this:
<br><br>LAYER<br>&nbsp;&nbsp;NAME &quot;tiled_raster&quot;<br>&nbsp;&nbsp;STATUS ON<br>&nbsp;&nbsp;TILEINDEX &quot;tileindex&quot;<br>&nbsp;&nbsp;TILEITEM &quot;Location&quot;<br>&nbsp;&nbsp;TYPE RASTER<br>END<br><br><br>--<br>Trond Michelsen<br></blockquote></div><br>