[mapserver-users] Length of a line calculation?

Lowell Filak lfilak at medinaco.org
Fri Feb 22 12:14:44 EST 2002


Perl MapScript example:

      #
      # Create shapefile object of existing data.
      $shpfile = new shapefileObj("data", -1);
      #
      # Create shape object.
      $shp = new shapeObj(-1);
      #
      # Retrieve shape into shape object.
      $shpfile->get(1,$shp);
      ##############################################
      #
      # How many lines in shape.
      my $num_lines = $ishp->{numlines};
      #
      # Loop through each line.
      for ( $line_num=0; $line_num<$num_lines; $line_num++ ) {
        #
        # Get line.
        my $line = new lineObj();
        $line = $ishp->get($line_num);
        print "<br>Got Line #$line_num";
        #
        # How many point in line.
        my $num_points = $line->{numpoints};
        #
        # Loop through each point.
        for ( $point_num=0; $point_num<$num_points; $point_num++ ) {
          #
          # Get the point.
          my $point = new pointObj();
          $point = $line->get($point_num);
          print "<br>Got Point #$point_num";
          $px = $point->{x};
          $py = $point->{y};
          print " X=$px Y=$py";
        }
      }
      print "<br>";
      #######################################################

Lowell F.

The following message was sent by "Azimuth, Erwin Perik" <perik at azimuth.nl> on Fri, 22 Feb 2002 14:25:40 +0100.

> Hi V,
> 
> Had about the same question to the list a couple of days ago regarding 
> getting the points of a shape.
> 
> If you found a way to get every point of a shape i'd really appreceate it ;-)
> 
> This i got from my Lowell F. :
> 
> Perl Mapscript example:
> #
> # Create shapefile object of existing data.
> $shpfile = new shapefileObj("data", -1);
> #
> # Create shape object.
> $shp = new shapeObj(-1);
> #
> # Retrieve shape into shape object.
> $shpfile->get(1,$shp);
> #
> # Get first line.
> my $line = new lineObj();
> $line = $shp>{line};
> #
> # Get the first point of line.
> my $point = new pointObj();
> $point = $line->{point};
> $px = $point->{x};
> $py = $point->{y};
> print "<br>POINT X=$px Y=$py<br>";
> Doing such for each line of a shape and each point of
> a line...
> 
> 
> 
> 
> At 16:40 21-2-02 -0500, Vinko Vrsalovic wrote:
> >On Thu, Feb 21, 2002 at 10:20:29AM -0800, Lowell Filak wrote:
> >
> >[...]
> >
> > > This can be done for each point of each line of each
> > > shape and the distance calculated betwen points of
> > > each line.
> >
> >You are absolutely right, thank you. I was hoping for a more automatic
> >method, though :-).
> >
> >--
> >V. <v at w.cl>
> 
> 
> =================
> Azimuth Geodetic
> Koldingweg 8
> 9723 HK Groningen
> tel. 050-5493454
> fax. 050-5497217
> =================
> www.azimuth.nl
> perik at azimuth.nl
> =================




More information about the mapserver-users mailing list