Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Geo::Shapefile::Writer help

by u65 (Chaplain)
on Jan 28, 2016 at 16:22 UTC ( #1153891=note: print w/replies, xml ) Need Help??


in reply to Geo::Shapefile::Writer help

Welcome, kjslover! As tangent showed, it is easy to input arrays of any size. It should be possible to generate the required data with a suitable tool with the data output to a format easily read by your script and fed to the shape generator.

Replies are listed 'Best First'.
Re^2: Geo::Shapefile::Writer help
by kjslover (Initiate) on Jan 28, 2016 at 19:57 UTC

    Thanks to both tangent and u65. While the ease of inputting the numbers into the $shape object makes sense, how might I do this with an array that I am creating? I currently have an @coords array that I am placing my x,y values in. How do I transform this into the $shape object that tangent has referenced?
    I apologize if this is a basic question... I am self-taught in the ways of Perl and learn mainly from the O'Reilly books and online resources

      How do I transform this into the $shape object that tangent has referenced?

      If @coords is created as:
      @coords = ([$x1, $y1], [$x2, $y2], [$x3, $y3], ....);
      then it's just a matter of doing:
      $shape = \@coords;
      Cheers,
      Rob
      If just one array of (x1,y1,x2,y2...) the easiest way would be to use List::Util
      use List::Util qw(pairmap); my @coords = (86.925, 27.988, 86.5278, 27.744, 86.43, 27.365); my @pairs = pairmap { [ $a, $b ] } @coords; $shp_writer->add_shape( \@pairs, @attributes );

        tangent, thank you, that makes perfect sense. I have tried the following code and am now getting an error regarding "Can't use string ("0") as an ARRAY ref while "strict refs" in use at <path to writer.pm> line 141". I have tried adding the use strict; and declaring $x/$y/$dummy, but did not help.
        The following code is what I am using to try to get it to work:

        use Geo::Shapefile::Writer; use List::Util qw(pairmap); $shape = Geo::Shapefile::Writer->new("Temp", 'POLYGON', [COL1 => 'C', +10],); my @coords = (0, 0, 0, 1, 1, 1, 1, 0, 0, 0); my @pairs = pairmap { [ $a, $b ] } @coords; # Checking to make sure pairs look correct foreach $dummy (@pairs) { ($x, $y) = @$dummy; print "$x, $y\n"; } $shape->add_shape(\@pairs, {Col1 => "Dumb1"}); $shape->finalize();

      I'm sorry I can't say more without knowing more about the format of the shapefiles which I don't have the time to look into at the moment, but it looks like your @coords array will have to be a part of the "add_shape" subroutines argument somehow. I have dealt with shapefiles long ago and I remember it was ugly. You probably have shapefile help around, but here is a link that I would have to start with.

      -Tom

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1153891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2021-04-20 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?