Import Upstream version 0.22

parents
Revision history for Perl extension Geo::Shapelib.
0.01 Thu Aug 24 13:48:52 2000
- original version; created by h2xs 1.20 with options
-n Shape shapelib-1.2.8/shapefil
0.02 Fri Aug 25 14:29:26 EEST 2000
- save implemented
0.03 released Sep 13. 2001
- changes from Quinn Hart <qjhart@ucdavis.edu>, see README.Debian
- included the debian files into MANIFEST
0.04 released Mar 4 2003
- changes from Leif Pedersen <pedersen@meridian-enviro.com>
0.05 released Oct 20 2003
- as Geo::Shapelib in CPAN
- removed the debian files, sorry
0.06 released Oct 22 2003
- included Shapelib-1.2.10 tree into the distro
0.07 released Jan 14 2004
- change suggested by Stephen Woodbridge <woodbri@swoodbridge.com>
("it would be nice to be able to define the size of the the DBF fields")
- changes to shputils.c (#include <stdlib.h>,int findunit(char *unit);)
0.08 released May 14 2004
- notes on installation in Windows from daniel.babault@mbda.fr
0.09 released May 27 2004
- DBFWrite.. bugs fixed (thanks Joaquin Ferrero)
0.10 released August 20 2004
- ForceStrings and other options for the new method (thanks Massimiliano )
- save bails out if shape is empty
0.11 released November 15 2004
- ShapeID, NParts, NVertices optional (they are set in save method)
- Removed the DB method
0.12 released January 8 2005
- bug fix: $self->{Options} gets set in all cases
- Fieldwidths in dbf files are used
- rewrote if($self->{Options}{UnhashFields}) in new method
- set_sizes method
- failure of DBFWriteAttribute gets correctly tested
- many bug fixes in dump method
- brush up of the man page
- new parameters for the constructor
- SHPType optional
- test.pl rewritten
0.13 released Feb 8 2005
- changes to Shapelib.xs to make it compile with gcc 2.96 (as
suggested by Greg Machala)
0.14 released Apr 11 2005
- use Tree:R, optionally build a R-tree of the shapes
- new methods: clear_selections, select_vertices, move_selected_vertices
- use $shapefile instead of $shape in the docs, $shapefile is
the whole object, $shape is either and individual shape or an index
to an individual shape
0.15 released Apr 11 2005
- fixed small bugs in 0.14
0.16 released Apr 21 2005
- select_vertices more options (all, one shape, vertices)
- Rtree handling in move_selected_vertices
0.17 released May 26 2005
- LoadRecords to control whether load records into Perl vars or not
- fixed a bug which made open, save fail
0.18 released June 11 2005
- fixed bugs pointed out by Ethan Alpert:
- in xs: in _CreateObject parts and vertices were not read correctly always, wrote tests for these
- edited pod, Parts, CombineVertices
- new method set_bounds
0.19 released Jan 15 2006
- new constructor options: Like, Load
- get_record_hashref
- create, add, close
- lengths
0.20 released Jan 15 2006
- some bugfixes related to NShapes
0.21 released Sep 15 2015
- remove shapelib from the distribution
- add quadtree support
0.22 released Jan 26 2017
- fix error https://rt.cpan.org/Public/Bug/Display.html?id=119994
- do not run file size comparison tests
\ No newline at end of file
The Artistic License 2.0
Copyright (c) 2015 Ari Jolma
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
This license establishes the terms under which a given free software
Package may be copied, modified, distributed, and/or redistributed.
The intent is that the Copyright Holder maintains some artistic
control over the development of that Package while still keeping the
Package available as open source and free software.
You are always permitted to make arrangements wholly outside of this
license directly with the Copyright Holder of a given Package. If the
terms of this license do not permit the full use that you propose to
make of the Package, you should contact the Copyright Holder and seek
a different licensing arrangement.
Definitions
"Copyright Holder" means the individual(s) or organization(s)
named in the copyright notice for the entire Package.
"Contributor" means any party that has contributed code or other
material to the Package, in accordance with the Copyright Holder's
procedures.
"You" and "your" means any person who would like to copy,
distribute, or modify the Package.
"Package" means the collection of files distributed by the
Copyright Holder, and derivatives of that collection and/or of
those files. A given Package may consist of either the Standard
Version, or a Modified Version.
"Distribute" means providing a copy of the Package or making it
accessible to anyone else, or in the case of a company or
organization, to others outside of your company or organization.
"Distributor Fee" means any fee that you charge for Distributing
this Package or providing support for this Package to another
party. It does not mean licensing fees.
"Standard Version" refers to the Package if it has not been
modified, or has been modified only in ways explicitly requested
by the Copyright Holder.
"Modified Version" means the Package, if it has been changed, and
such changes were not explicitly requested by the Copyright
Holder.
"Original License" means this Artistic License as Distributed with
the Standard Version of the Package, in its current version or as
it may be modified by The Perl Foundation in the future.
"Source" form means the source code, documentation source, and
configuration files for the Package.
"Compiled" form means the compiled bytecode, object code, binary,
or any other form resulting from mechanical transformation or
translation of the Source form.
Permission for Use and Modification Without Distribution
(1) You are permitted to use the Standard Version and create and use
Modified Versions for any purpose without restriction, provided that
you do not Distribute the Modified Version.
Permissions for Redistribution of the Standard Version
(2) You may Distribute verbatim copies of the Source form of the
Standard Version of this Package in any medium without restriction,
either gratis or for a Distributor Fee, provided that you duplicate
all of the original copyright notices and associated disclaimers. At
your discretion, such verbatim copies may or may not include a
Compiled form of the Package.
(3) You may apply any bug fixes, portability changes, and other
modifications made available from the Copyright Holder. The resulting
Package will still be considered the Standard Version, and as such
will be subject to the Original License.
Distribution of Modified Versions of the Package as Source
(4) You may Distribute your Modified Version as Source (either gratis
or for a Distributor Fee, and with or without a Compiled form of the
Modified Version) provided that you clearly document how it differs
from the Standard Version, including, but not limited to, documenting
any non-standard features, executables, or modules, and provided that
you do at least ONE of the following:
(a) make the Modified Version available to the Copyright Holder
of the Standard Version, under the Original License, so that the
Copyright Holder may include your modifications in the Standard
Version.
(b) ensure that installation of your Modified Version does not
prevent the user installing or running the Standard Version. In
addition, the Modified Version must bear a name that is different
from the name of the Standard Version.
(c) allow anyone who receives a copy of the Modified Version to
make the Source form of the Modified Version available to others
under
(i) the Original License or
(ii) a license that permits the licensee to freely copy,
modify and redistribute the Modified Version using the same
licensing terms that apply to the copy that the licensee
received, and requires that the Source form of the Modified
Version, and of any works derived from it, be made freely
available in that license fees are prohibited but Distributor
Fees are allowed.
Distribution of Compiled Forms of the Standard Version
or Modified Versions without the Source
(5) You may Distribute Compiled forms of the Standard Version without
the Source, provided that you include complete instructions on how to
get the Source of the Standard Version. Such instructions must be
valid at the time of your distribution. If these instructions, at any
time while you are carrying out such distribution, become invalid, you
must provide new instructions on demand or cease further distribution.
If you provide valid instructions or cease distribution within thirty
days after you become aware that the instructions are invalid, then
you do not forfeit any of your rights under this license.
(6) You may Distribute a Modified Version in Compiled form without
the Source, provided that you comply with Section 4 with respect to
the Source of the Modified Version.
Aggregating or Linking the Package
(7) You may aggregate the Package (either the Standard Version or
Modified Version) with other packages and Distribute the resulting
aggregation provided that you do not charge a licensing fee for the
Package. Distributor Fees are permitted, and licensing fees for other
components in the aggregation are permitted. The terms of this license
apply to the use and Distribution of the Standard or Modified Versions
as included in the aggregation.
(8) You are permitted to link Modified and Standard Versions with
other works, to embed the Package in a larger work of your own, or to
build stand-alone binary or bytecode versions of applications that
include the Package, and Distribute the result without restriction,
provided the result does not expose a direct interface to the Package.
Items That are Not Considered Part of a Modified Version
(9) Works (including, but not limited to, modules and scripts) that
merely extend or make use of the Package, do not, by themselves, cause
the Package to be a Modified Version. In addition, such works are not
considered parts of the Package itself, and are not subject to the
terms of this license.
General Provisions
(10) Any use, modification, and distribution of the Standard or
Modified Versions is governed by this Artistic License. By using,
modifying or distributing the Package, you accept this license. Do not
use, modify, or distribute the Package, if you do not accept this
license.
(11) If your Modified Version has been derived from a Modified
Version made by someone other than you, you are nevertheless required
to ensure that your Modified Version complies with the requirements of
this license.
(12) This license does not grant you the right to use any trademark,
service mark, tradename, or logo of the Copyright Holder.
(13) This license includes the non-exclusive, worldwide,
free-of-charge patent license to make, have made, use, offer to sell,
sell, import and otherwise transfer the Package with respect to any
patent claims licensable by the Copyright Holder that are necessarily
infringed by the Package. If you institute patent litigation
(including a cross-claim or counterclaim) against any party alleging
that the Package constitutes direct or contributory patent
infringement, then this Artistic License to you shall terminate on the
date that such litigation is filed.
(14) Disclaimer of Warranty:
THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL
LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Changes
LICENSE
MANIFEST
README.md
typemap
Makefile.PL
t/00.t
lib/Geo/Shapelib.pm
Shapelib.xs
example/xyz.dbf
example/xyz.sbn
example/xyz.sbx
example/xyz.shp
example/xyz.shx
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
{
"abstract" : "Perl extension for reading and writing shapefiles as defined by ESRI(r)",
"author" : [
"Ari Jolma <https://github.com/ajolma>"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150005",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Geo-Shapelib",
"no_index" : {
"directory" : [
"t",
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"Tree::R" : "0.01"
}
}
},
"release_status" : "stable",
"resources" : {
"repository" : {
"type" : "git",
"url" : "https://github.com/ajolma/Geo-Shapelib.git",
"web" : "https://github.com/ajolma/Geo-Shapelib"
}
},
"version" : "0.22",
"x_serialization_backend" : "JSON::PP version 2.27400"
}
---
abstract: 'Perl extension for reading and writing shapefiles as defined by ESRI(r)'
author:
- 'Ari Jolma <https://github.com/ajolma>'
build_requires:
ExtUtils::MakeMaker: '0'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150005'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Geo-Shapelib
no_index:
directory:
- t
- inc
requires:
Tree::R: '0.01'
resources:
repository: https://github.com/ajolma/Geo-Shapelib.git
version: '0.22'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
use strict;
use ExtUtils::MakeMaker;
use File::Basename qw(fileparse);
# The location of shapelib (libshp) can be given as a command line
# param or as an env var.
my %ARGV;
for (@ARGV) {
$ARGV{$1} = $2 if /^--(.*?)\=(.*)/;
$_ = '' if /^--shapelib/;
}
$ARGV{shapelib} = $ENV{PERL_SHAPELIB} unless defined $ARGV{shapelib};
# If not given, search.
unless (defined $ARGV{shapelib}) {
# scan known possible locations in the order of preference:
my @locs;
for (qw(/usr/lib /usr/lib64 /usr/lib/x86_64-linux-gnu /usr/local/lib /usr/local/lib64)) {
# prefer a shared lib
my $lib = $_ . '/libshp.so';
$lib = $_ . '/libshp.a' unless -e $lib;
push @locs, $lib if -e $lib;
}
if (@locs) {
print "Found shapelib(s): '",join("', '", @locs),"'.\n";
$ARGV{shapelib} = $locs[0];
print "Will use '$ARGV{shapelib}'.\n";
}
}
die "Can't find shapelib.\n".
"Please install a development version of shapelib or\n".
"specify the location of libshp.a or libshp.so with\n".
"command line parameter --shapelib= or with environment\n".
"variable PERL_SHAPELIB.\n".
"You can get shapelib from http://download.osgeo.org/shapelib/."
unless -e $ARGV{shapelib};
# Does the shapelib define SHPSearchDiskTree?
my $HAS_SEARCH_DISK_TREE;
if ($ARGV{shapelib} =~ /\.a$/) {
my @ret = `nm $ARGV{shapelib} | grep SHPSearchDiskTree`;
$HAS_SEARCH_DISK_TREE = $ret[0] ne '';
} else {
my @ret = `readelf -Ws $ARGV{shapelib} | grep SHPSearchDiskTree`;
$HAS_SEARCH_DISK_TREE = $ret[0] ne '';
}
warn "Warning: Shapelib is old version. You will not be able to save quadtree index." unless $HAS_SEARCH_DISK_TREE;
my ($file, $path, $suffix) = fileparse($ARGV{shapelib});
my $libs;
my $inc;
my $define;
if ($HAS_SEARCH_DISK_TREE) {
$libs = ["-L$path -lshp"];
$inc = "-I$path";
$define = '-DHAS_SEARCH_DISK_TREE';
} else {
$libs = ["-L$path -lshp"];
$inc = "-I$path";
$define = undef;
}
WriteMakefile(
NAME => 'Geo::Shapelib',
VERSION_FROM => 'lib/Geo/Shapelib.pm',
PREREQ_PM => {'Tree::R' => 0.01}, # e.g., Module::Name => 1.1
ABSTRACT_FROM => 'lib/Geo/Shapelib.pm',
LIBS => $libs,
DEFINE => $define,
INC => $inc,
clean => {'FILES' => 'stations.* example/test.*'},
AUTHOR => 'Ari Jolma <https://github.com/ajolma>',
LICENSE => 'perl_5',
META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
repository => {
type => 'git',
web => 'https://github.com/ajolma/Geo-Shapelib',
url => 'https://github.com/ajolma/Geo-Shapelib.git',
},
},
}
);
Perl extension Geo::Shapelib
===================
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DEPENDENCIES
Geo::Shapelib.pm requires Shapefile C Library from
http://shapelib.maptools.org/
Chances are that you can install it with sudo apt-get install
libshp-dev or something similar.
COPYRIGHT AND LICENSE
Copyright (c) 2000- Ari Jolma.
This library is free software; you can redistribute it and/or modify
it under the terms of The Artistic License 2.0.
ACKNOWLEDGEMENTS
The example shapefile set is taken from the Shapelib examples. The following
people have sent comments and/or bug fixes
Massimiliano Galanti
Leif Pedersen
Daniel Babault
woodbri
This diff is collapsed.
File added
File added
File added
File added
File added
This diff is collapsed.
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
BEGIN { $| = 1; }
END {print "not ok 1\n" unless $loaded;}
use Geo::Shapelib qw /:all/;
use Test::More tests => 12;
$loaded = 1;
######################### End of black magic.
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
my $shape = new Geo::Shapelib {
Shapetype => POLYLINE,
};
for (0..0) {
push @{$shape->{Shapes}}, {
Vertices=>[[0,0],[1,1]]
};
}
for (0..0) {
$s = $shape->get_shape($_);
@l = $shape->lengths($s);
ok(abs($l[0] - sqrt(2)) < 0.00001,'lengths');
}
my $test;
my $shapefile = 'test_shape';
my $shape = new Geo::Shapelib {
Name => $shapefile,
Shapetype => POINT,
FieldNames => ['Name','Code','Founded'],
FieldTypes => ['String:50','String:10','Integer:8']
};
while (<DATA>) {
chomp;
($station,$code,$founded,$x,$y) = split /\|/;
push @{$shape->{Shapes}}, {
Vertices=>[[$x,$y]]
};
push @{$shape->{ShapeRecords}}, [$station,$code,$founded];
}
ok($shape, 'new from data');
$rec = $shape->get_record_hashref(0);
ok($rec->{Founded} == 19780202, "get_record_hashref, $rec->{Founded} == 19780202");
$shape->dump("$shapefile.dump");
ok(1, 'dump');
$shape->save();
ok(1, "save");
{
my $shape2 = new Geo::Shapelib $shapefile, {Rtree=>1};
ok(ref($shape2->{Rtree}) eq 'Tree::R', "Rtree");
$test = $shape->{Shapes}->[2]->{Vertices}->[0]->[1] ==
$shape2->{Shapes}->[2]->{Vertices}->[0]->[1] and
$shape->{Shapes}->[2]->{Vertices}->[0]->[1] == 6722622;
ok($test, 'Rtree seems to work');
is_deeply ($shape2->query_within_rect(
[3382750, 6690570, 3394250, 6698260]), [0, 8], "Quadtree spatial query" );
ok ($shape2->create_spatial_index, "Create Quadtree index");
}
$example = "example/xyz";
{
$shape = new Geo::Shapelib $example, {Load=>0};
my $rec = $shape->get_record_hashref(0);
my $y = sprintf("%.2f", $rec->{Y});
ok($y == 4235332.51, "get_record_hashref (unloaded rec) $rec->{Y} ~ 4235332.51");
$shape->save($shapefile);
#for ('.shp','.dbf') {
# @stat1 = stat $example.$_;
# @stat2 = stat $shapefile.$_;
# ok($stat1[7] == $stat2[7], "cmp $_ files, expected $stat1[7] got $stat2[7]");
#}
}
$shape = new Geo::Shapelib $example, {Load=>0};
$shape2 = new Geo::Shapelib {
Name => $shapefile,
Like => $shape
};
$shape2->create();
for (0..$shape->{NShapes}-1) {
$s = $shape->get_shape($_);
$r = $shape->get_record($_);
$shape2->add($s,$r);
}
$shape2->close();
#for ('.shp','.dbf') {
# @stat1 = stat $example.$_;
# @stat2 = stat $shapefile.$_;
# ok($stat1[7] == $stat2[7], "cmp $_ files, expected $stat1[7] got $stat2[7]");
#}
$shape = new Geo::Shapelib "example/xyz", {UnhashFields => 0};
$shape->save($shapefile);
#for ('.shp','.dbf') {
# @stat1 = stat $example.$_;
# @stat2 = stat $shapefile.$_;
# ok($stat1[7] == $stat2[7], "cmp $_ files after unhash=0, expected $stat1[7] got $stat2[7]");
#}
$shape = new Geo::Shapelib "example/xyz", {LoadRecords => 0};
$shape->save($shapefile);
#for ('.shp','.dbf') {
# @stat1 = stat $example.$_;
# @stat2 = stat $shapefile.$_;
# ok($stat1[7] == $stat2[7], "cmp $_ files after loadrecords=0, expected $stat1[7] got $stat2[7]");
#}
$shape = new Geo::Shapelib "example/xyz", {LoadRecords => 0, UnhashFields => 0};
$shape->save($shapefile);
#for ('.shp','.dbf') {
# @stat1 = stat $example.$_;
# @stat2 = stat $shapefile.$_;
# ok($stat1[7] == $stat2[7], "cmp $_ files after loadrecords=0,unhash=0, expected $stat1[7] got $stat2[7]");
#}
# thanks to Ethan Alpert for this test
$shape = new Geo::Shapelib;
$shape->{Name};
$shape->{Shapetype}=5;
$shape->{FieldNames}=['ID','Name'];
$shape->{FieldTypes}=['Integer','String'];
push @{$shape->{ShapeRecords}},[0,$shapefile];
push @{$shape->{Shapes}}, {
SHPType=>5,
ShapeId=>0,
NParts=>2,
Parts=>[[0,5,'Ring'],[5,5,'Ring']],
NVertices=>10,
Vertices=>[[-1,1,0,0],[1,1,0,0],[1,-1,0,0],[-1,-1,0,0],[-1,1,0,0],[-.1,.1,0,0],[-.1,-.1,0,0],[.1,-.1,0,0],[.1,.1,0,0],[-.1,.1,0,0]]
};
$shape->set_bounds;
$shape->save($shapefile);
#$shape->dump;
$shape = new Geo::Shapelib $shapefile;
#$shape->dump;
#use Data::Dumper;
#print Dumper($shape->{Shapes}[0]);
ok($shape->{Shapes}[0]->{Vertices}[4][0] == -1, 'save multipart, vertices');
ok($shape->{Shapes}[0]->{Parts}[1][0] == 5, 'save multipart, parts');
END {
foreach ( 'shp', 'shx', 'dbf', 'qix', 'dump' ) {
unlink "$shapefile.$_";
}
}
__DATA__
Helsinki-Vantaan Lentoasema|HVL|19780202|3387419|6692222
Helsinki Kaisaniemi |HK|19580201|3385926|6675529
Hyvink Mutila |HM|19630302|3379813|6722622
Nurmijrvi Rajamki |HR|19340204|3376486|6715764
Vihti Maasoja |VM|19230502|3356766|6703481
Porvoo Jrnble |PJ|19450202|3426574|6703254
Porvoon Mlk Bengtsby |PMB|19670202|3424354|6684723
Orimattila Kkel |OK|19560202|3432847|6743998
Tuusula Ruotsinkyl |TR|19750402|3388723|6696784
TYPEMAP
SHPHandle T_PTROBJ
DBFHandle T_PTROBJ
SHPObject * T_PTROBJ
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment