How to access shapefile attributes?

Jeff Portwine jdport at VERITIME.COM
Wed Jan 12 08:45:32 EST 2005


Thanks very much for the great information and the pointer to this geocoder
perl code.   I've been able to get it working somewhat, but I have a couple
of questions for you.

When I trie to use import_tiger_zip.pl   I get an error:
Bareword "AZ_OK" not allowed while "strict subs" in use at
./import_tiger_zip.pl line 21.
Execution of ./import_tiger_zip.pl aborted due to compilation errors.

I can unzip the tiger files and use import_tiger.pl, but it *appears*  (i'm
not 100% sure yet) but it appears that I have to make a separate DB file for
each individual tiger file.   For example, the state of Michigan Tiger files
are broken up into county files... is  there anyway to put all of those into
a single DB, or do I have to make a DB for each county?   It seems like if I
import to an existing DB it overwrites the data instead of appending to it.

Thanks a lot, I really appreciate the great information about geocoding.

-Jeff

----- Original Message -----
From: "Camden Daily" <cdaily at GMAIL.COM>
To: <MAPSERVER-USERS at LISTS.UMN.EDU>
Sent: Tuesday, January 11, 2005 11:31 AM
Subject: Re: [UMN_MAPSERVER-USERS] How to access shapefile attributes?


> 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