[gdal-dev] Reading the points from shp file

Djordje Spasic issworld2000 at yahoo.com
Mon Jan 11 16:26:37 PST 2016


Thank you Mike.
I have no doubt this code will be useful to somebody looking for a Perl solution.

Kind regards,
Djordje

      From: Mike Flannigan <mikeflan at att.net>
 To: issworld2000 at yahoo.com 
 Sent: Tuesday, January 12, 2016 1:26 AM
 Subject: Re: [gdal-dev] Reading the points from shp file
   

It appears not, but I paste the synopsis below
for your review.  Feel free to post to the list
if you want to.


Mike



=head1 NAME

Geo::ShapeFile - Perl extension for handling ESRI GIS Shapefiles.

=head1 SYNOPSIS

  use Geo::ShapeFile;

  my $shapefile = new Geo::ShapeFile("roads");

  for(1 .. $shapefile->shapes()) {
    my $shape = $shapefile->get_shp_record($_);
    # see Geo::ShapeFile::Shape docs for what to do with $shape

    my %db = $shapefile->get_dbf_record($_);
  }

=head1 ABSTRACT

The Geo::ShapeFile module reads ESRI ShapeFiles containing GIS mapping
data, it has support for shp (shape), shx (shape index), and dbf (data
base) formats.

=head1 DESCRIPTION

The Geo::ShapeFile module reads ESRI ShapeFiles containing GIS mapping
data, it has support for shp (shape), shx (shape index), and dbf (data
base) formats.

=head1 METHODS

=over 4

=item new($filename_base)

Creates a new shapefile object, the only argument it takes is the basename
for your data (don't include the extension, the module will automatically
find the extensions it supports).  For example if you have data files called
roads.shp, roads.shx, and roads.dbf, use 'new Geo::ShapeFile("roads");' to
create a new object, and the module will load the data it needs from the
files as it needs it.

=item type_is($numeric_type)

Returns true if the major type of this data file is the same as the type
passed to type_is().

=item get_dbf_record($record_index)

Returns the data from the dbf file associated with the specified record 
index
(shapefile indexes start at 1).  If called in a list context, returns a 
hash,
if called in a scalar context, returns a hashref.

=item x_min() x_max() y_min() y_max()

=item m_min() m_max() z_min() z_max()

Returns the minimum and maximum values for x, y, z, and m fields as 
indicated
in the shp file header.

=item upper_left_corner() upper_right_corner()

=item lower_left_corner() lower_right_corner()

Returns a Geo::ShapeFile::Point object indicating the respective corners.

=item height() width()

Returns the height and width of the area contained in the shp file. Note 
that
this likely does not return miles, kilometers, or any other useful 
measure, it
simply returns x_max - x_min, or y_max - y_min.  Whether this data is a 
useful
measure or not depends on your data.

=item corners()

Returns a four element array consisting of the corners of the area contained
in the shp file.  The corners are listed clockwise starting with the upper
left.
(upper_left_corner, upper_right_corner, lower_right_corner, 
lower_left_corner)

=item area_contains_point($point,$x_min,$y_min,$x_max,$y_max)

Utility function that returns true if the Geo::ShapeFile::Point object in
point falls within the bounds of the rectangle defined by the area
indicated.  See bounds_contains_point() if you want to check if a point 
falls
within the bounds of the current shp file.

=item bounds_contains_point($point)

Returns true if the specified point falls within the bounds of the current
shp file.

=item file_version()

Returns the ShapeFile version number of the current shp/shx file.

=item shape_type()

Returns the shape type contained in the current shp/shx file.  The ESRI spec
currently allows for a file to contain only a single type of shape (null
shapes are the exception, they may appear in any data file).  This returns
the numeric value for the type, use type() to find the text name of this
value.

=item shapes()

Returns the number of shapes contained in the current shp/shx file. This is
the value that allows you to iterate through all the shapes using
'for(1 .. $obj->shapes()) {'.

=item records()

Returns the number of records contained in the current data.  This is 
similar
to shapes(), but can be used even if you don't have shp/shx files, so 
you can
access data that is stored as dbf, but does not have shapes associated 
with it.

=item shape_type_text()

Returns the shape type of the current shp/shx file (see shape_type()), but
as the human-readable string type, rather than an integer.

=item get_shx_record($record_index)
=item get_shx_record_header($record_index)

Get the contents of an shx record or record header (for compatibility with
the other get_* functions, both are provided, but in the case of shx data,
they return the same information).  The return value is a two element array
consisting of the offset in the shp file where the indicated record begins,
and the content length of that record.

=item get_shp_record_header($record_index)

Retrieve an shp record header for the specified index.  Returns a two 
element
array consisting of the record number and the content length of the record.

=item get_shp_record($record_index)

Retrieve an shp record for the specified index.  Returns a
Geo::ShapeFile::Shape object.

=item shapes_in_area($x_min,$y_min,$x_max,$y_max)

Returns an array of integers, consisting of the indices of the shapes that
overlap with the area specified.  Currently this is a very oversimplified
function that actually finds shapes that have any point that falls within
the specified bounding box.  Currently it may miss some shapes that actually
do overlap with the specified area, if there are two points outside the area
that cause an edge to pass through the area, but neither of the end points
of that edge actually fall within the area specified.  Patches to make this
function more useful would be welcome.

=item 
check_in_area($x1_min,$y1_min,$x1_max,$y1_max,$x2_min,$x2_max,$y2_min,$y2_max)

Returns true if the two specified areas overlap.

=item bounds()

Returns the bounds for the current shp file.
(x_min, y_min, x_max, y_max)

=item shx_handle() shp_handle() dbf_handle()

Returns the file handles associated with the respective data files.

=item type($shape_type_number)

Returns the name of the type associated with the given type id number.

=item find_bounds(@shapes)

Takes an array of Geo::ShapeFile::Shape objects, and returns a hash, with
keys of x_min,y_min,x_max,y_max, with the values for each of those ranges.

=back

=head1 REPORTING BUGS

Please send any bugs, suggestions, or feature requests to
  E<lt>geo-shapefile-bugs at jasonkohles.comE<gt>.

=head1 SEE ALSO

Geo::ShapeFile::Shape
Geo::ShapeFile::Point

=head1 AUTHOR

Jason Kohles, E<lt>email at jasonkohles.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright 2002,2003 by Jason Kohles

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut




On 1/11/2016 7:54 AM, gdal-dev-request at lists.osgeo.org wrote:
> Date: Mon, 11 Jan 2016 10:11:06 +0000 (UTC)
> From: Djordje Spasic<issworld2000 at yahoo.com>
> To: Mike Flannigan<mikeflan at att.net>,"gdal-dev at lists.osgeo.org"
>     <gdal-dev at lists.osgeo.org>
> Subject: Re: [gdal-dev] Reading the points from shp file
> Message-ID:
>     <1670137557.3284629.1452507066766.JavaMail.yahoo at mail.yahoo.com>
> Content-Type: text/plain; charset="utf-8"
>
> Thank you for the reply Mr. Flannigan,
>
> Sadly I have no knowledge of Perl.
> If its "Geo::ShapeFile" module uses the same C# GDAL bindings (or is based on them), then I might try to take a look at your Perl code.
> If not, then I guess I can not make use of it.
>
> I respect the intention to help, though.
>
> Kind regards,
> Djordje Spasic



  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20160112/198592e7/attachment.html>


More information about the gdal-dev mailing list