GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  SHAPE (3)

.ds Aq ’

NAME

Shape - Perl extension for reading and writing ArcView(c) shapefiles

CONTENTS

SYNOPSIS



    use Shape;



or



    use Shape qw/:all/;

    my $shape = new Shape;
    foreach my $i (0..10) {
        push @{$shape->{Shapes}},{SHPType=>POINT,
                                  ShapeID=>$i++,
                                  NParts=>0,
                                  NVertices=>1,
                                  Vertices=>[[$i,$i,0,0]]
                                 };
      }



DESCRIPTION

This is a library for reading, creating, and writing ArcView(c) shapefiles using Perl. The Perl code uses Frank Warmerdam’s Shapefile C Library. Get it from http://gdal.velocet.ca/projects/shapelib/index.html

Currently no methods exist for populating an empty Shape. You need to do it in your own code. This is the HOWTO:

First you create the Shape object:



    $shape = new Shape;



the set its attributes:



    $shape->{Name} to be the name (path) of the shapefile, it may contain
    an extension. You may also use the argument in the save method.

    $shape->{Shapetype} to be the (integer) denoting the shapetype. Look
    into this file or some other doc for the numbers.



don’t care about these attributes:



    $shape->{NShapes} the number of shapes in your Shape. Shape is in
    fact a collection of shapes. This is automatically deduced from
    the Shapes array.

    $shape->{MinBounds}

    $shape->{MaxBounds}



then create shapes and put them into the shape, note again that shape is not a Shape ;)



    for many times {
        make $s, a new shape
        push @{$shape->{Shapes}}, $s;
    }



how to create $s? It is a hash.

set



    $s->{SHPType} to be the type of the shape (this needs to be the
    same as the type of the shape, i.e., of the object?)

    $s->{ShapeId} this is probably best to let be an integer which you
    increment each time by one starting from zero

    $s->{NParts} to be the number of how many parts want into this
    shape, may be zero

    $s->{Parts} this is a reference to an array of arrays of two
    values, one for each part: the index of the first vertex in the
    vertex array, i.e. the number of vertices in all previous parts in
    this shape; and the type of the part (not the shapetype): Ring if
    the shape is not Multipatch?

    $s->{NVertices} to be the number of how many vertices there are in
    your shape (point has only one vertex), at least one

    $s->{Vertices} this is a reference to an array of arrays of four
    values, one for each vertex: x, y, z, and m of the vertex



Then you need to have at least some data assigned to each shape.



    $self->{FieldNames} is a reference to the names of the data items,
    i.e., an array.

    $self->{FieldTypes} is a reference to the types of the data items,
    i.e., and array. Type is either Integer, Double, or String.



populate the data table:



    for my $i (0..$self->{NShapes}-1) {
        $self->{ShapeRecords}->[$i] = [item1,item2,item3,...];
    }



That’s all. Then save it and start your ArcView(c) to look at the result.

An example:



    $shape = new Shape;

    $shape->{Shapetype} = 1;

    $shape->{FieldNames} = [ID,Station];
    $shape->{FieldTypes} = [Integer,String];

    $i = 0;
    while (<DATA>) {
        chomp;
        ($station,$x,$y) = split /\|/;
        push @{$shape->{Shapes}}, {
                SHPType=>1,
                ShapeId=>$i,
                NParts=>0,
                NVertices=>1,
                Vertices=>[[$x,$y]]
        };
        push @{$shape->{ShapeRecords}}, [$i,$station];
        $i++;
    }

    $shape->save(stations);

    __DATA__
    Helsinki-Vantaan Lentoasema|3387419|6692222
    Helsinki Kaisaniemi        |3385926|6675529
    Hyvinkaäe Mutila            |3379813|6722622
    Nurmijaervi Rajamaeki        |3376486|6715764
    Vihti Maasoja              |3356766|6703481
    Porvoo Jaernboele            |3426574|6703254
    Porvoon Mlk Bengtsby       |3424354|6684723
    Orimattila Kaekelae          |3432847|6743998
    Tuusula Ruotsinkylae        |3388723|6696784



EXPORT

None by default. The following export tags are defined.
:constants This exports constant functions for the individual types of shapefile Types and shapefile part types. They all return scalar (integer) values. The shapetype functions: POINT, ARC, POLYGON, MULTIPOINT, POINTZ, ARCZ, POLYGONZ, MULTIPOINTZ, POINTM, ARCM, POLYGONM, MULTIPOINTM, MULTIPATCH are defined. The shapefile part types: TRISTRIP, TRIFAN, OUTERRING, INNERRING, FIRSTRING, RING are defined.
:types Exports two hashs: %ShapeTypes, %PartTypes which map the shapelib type integers to string values.
:all All possible exports are included.

CONSTRUCTORS

This one reads in an existing shapefile:



    $shape = new Shape "myshapefile";



This one creates a new, blank Perl Shape object:



    $shape = new Shape;



METHODS

    Saving the Shape



    $shape->save($shapefile);



The argument $shapefile is optional, the internal attribute ($shape->{Name}) is used if $shapefile is not specified.

    Dump

$shape->dump($to);

$to can be undef (then dump uses STDOUT), filename, or reference to a filehandle (e.g., \*DUMP).

    SQL Database methods

OpenGIS Simple Features Specification for SQL compliant database methods to come! :)

AUTHOR

Ari Jolma, ajolma@water.hut.fi

LIMITATIONS

SEE ALSO

perl(1).

POD ERRORS

Hey! <B>The above document had some coding errors, which are explained below:B>
Around line 213: Non-ASCII character seen before =encoding in ’Hyvinkaäe’. Assuming ISO8859-1
Around line 493: =cut found outside a pod block. Skipping to next block.
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 SHAPE (3) 2003-03-04

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.