How to access shapefile attributes?

Camden Daily cdaily at GMAIL.COM
Tue Jan 11 11:31:46 EST 2005


In order to show addresses on your map, you're going to need to use
geocoding (which is not a part of mapserver).  The best module I've
found so far for that is the perl module Geo::Coder::US.  You'll need
to download it from CPAN and get it running first.

Secondly, you'll need a database for your geocoding.  This database
can be built from tiger data, but it is very very large and it takes a
long time to construct.  It's probably best to just grab the files you
need for your particular area.  You can get the tiger data files you
need here:
http://www2.census.gov/geo/tiger/tgrcd108/

Once you have them, you don't need to unzip them. Just use the
import_tiger_zip.pl script that came with the Geo::Coder::US source. Use the
command "perl import_tiger_zip.pl geocoder.db *.zip" to construct a database
named geocoder.db from all of the zip files. This process can take a very, very
long time.  (I don't know how to do this in windows, but that's how
you can do it in linux).

Now, if you're using PHP mapscript, you'll need a way for PHP to talk
to Perl.  The best way I've found is via the command line on a linux
box.  I wrote a little helper Perl script called geocode.pl that looks
like this:

====================================
#!/usr/bin/perl
use Geo::Coder::US;
Geo::Coder::US->set_db( "/web_system/data/tiger/geocoder.db" );
my $address = $ARGV[0];
my ($return) = Geo::Coder::US->geocode( $address );
print $return->{lat};
print "\n";
print $return->{long};
print "\n";
=====================================

Then, in my PHP, I geocode addresses like this:
($address holds the address string I'm geocoding)

=====================================
exec("/web_system/geocode.pl \"$address\"", $results);
$latitude = $results[0];
$longitude = $results[1];
=====================================

That should get you started.  Once you have the $latitude and
$longitude values for each address, you can plot them out as points on
your map.

This is really a very simple implementation of the Geo::Coder::US
module that doesn't take into account some of it's more advanced
features, but it's a good enough start.

-Camden


On Mon, 10 Jan 2005 16:25:23 -0500, Jeff Portwine <jdport at veritime.com> wrote:
> I'm just learning how to use mapscript for displaying my maps, and I am
> trying to figure out how you would access the attribute data in your
> shapefiles?    I have a layer of roads, and I'm using the Tiger data which
> has fields for street names, address ranges, and zipcodes.    Eventually
> what I'd like to do is to be able to read a list of addresses and place a
> marker on the map at each of those addresses.
>
> I'm not exactly sure how to do that even when I learn how to access the
> data.... there was some code posted to this list sometime back for getting
> the coordinates of a street address and I could possibly use that, but it
> requires a specific set of fields to be present in the shape file and I'd
> have to do some manipulation of the fields I actually have to use that code
> and that might be just as tricky as writing the code myself :)
>
> Thanks for any pointers,
>
> Jeff
>



More information about the mapserver-users mailing list