[mapserver-users] Problems..

Lowell.Filak lfilak at medinaco.org
Tue Apr 2 13:34:44 PST 2002


Hmmm... Good point.
Attached is an update to the dump.pl in the mapscript/perl/examples
directory that prints the bounding rectangle at the end of the printout.
Note: If your running it on a big shapefile and are interested in more
than just the final extent make sure to send the output to a file.
perl dump.pl -file=<shapefilename_without_ext> > shapefile.dump

On Tue, 2 Apr 2002, Paul Peterson wrote:

> It works... I was able to determine the extents and unit with ArcExplore 3.1
>
> I'm still very new with Shapefiles and GIS in general.  I was hoping shpinfo
> or shpdump would present whatever information contained in a file in an easy
> to read/understand tabular layout.
>
> Thanks for the info.
>
> Thanks.
>
> -----Original Message-----
> From: Steffen_Macke at dorsch.com.jo [mailto:Steffen_Macke at dorsch.com.jo]
> Sent: Monday, April 01, 2002 10:55 PM
> To: Paul Peterson; mapserver
> Subject: RE: [mapserver-users] Problems..
>
>
>
> Paul,
>
> try to switch on the scalebar in ArcExplorer, this shoul allow you to
> determine the
> extents of the map.
>
> Steffen
>
>
-------------- next part --------------
#!/usr/bin/perl

use mapscript;
use Getopt::Long;

%types = ( '1' => 'point',
	   '3' => 'arc',
	   '5' => 'polygon',
	   '8' => 'multipoint'
	 );

my $shapeminx = 0,
my $shapeminy = 0;
my $shapemaxx = 1;
my $shapemaxy = 1;

&GetOptions("file=s", \$file);
if(!$file) {
  print "Syntax: dump.pl -file=[filename]\n";
  exit 0;
}

$shapefile = new shapefileObj($file, -1) or die "Unable to open shapefile $file";

print "Shapefile opened (type=". $types{$shapefile->{type}} .") with ".
$shapefile->{numshapes} ." shape(s)\n";

$shape = new shapeObj(-1);

for($i=0; $i<$shapefile->{numshapes}; $i++) {
    
    $shapefile->get($i, $shape);

    print "Shape $i has ". $shape->{numlines} ." part(s) - ";
    
    #
    # Get the bounds.
    my $minx = $shape->{bounds}->{minx};
    my $miny = $shape->{bounds}->{miny};
    my $maxx = $shape->{bounds}->{maxx};
    my $maxy = $shape->{bounds}->{maxy};    

    printf "bounds (%f,%f) (%f,%f)\n", $minx, $miny, $maxx, $maxy;

    #
    # Is this the first shape.
    if ( $i == 0 ) {
      #
      # Set the initial bounds.
      $shapeminx = $minx;
      $shapeminy = $miny;
      $shapemaxx = $maxx;
      $shapemaxy = $maxy;
    }
     else {
      #
      # Create compounded shapefile extent.
      if ($minx < $shapeminx) {
        $shapeminx = $minx;
      }
      if ($miny < $shapeminy) {
        $shapeminy = $miny;
      }
      if ($maxx > $shapemaxx) {
        $shapemaxx = $maxx;
      }
      if ($maxy > $shapemaxy) {
        $shapemaxy = $maxy;
      }
     }

    for($j=0; $j<$shape->{numlines}; $j++) {
        $part = $shape->get($j);
        print "Part $j has ". $part->{numpoints} ." point(s)\n";

        for($k=0; $k<$part->{numpoints}; $k++) {
            $point = $part->get($k);
            print "$k: ". $point->{x} .", ". $point->{y} ."\n";
        }
    }
}

#
# Print the shapefiles bounding rectangle.
print "$file\'s Bounding Rectangle is $shapeminx, $shapeminy, $shapemaxx, $shapemaxy\n";


More information about the MapServer-users mailing list