On Fri, May 1, 2009 at 8:56 AM, Dane Springmeyer <[email protected]> wrote:

>
> I would start by importing your shapefiles into a single PostGIS table
> (don't worry about VIEW for now), and creating good spatial indexes and
> attribute indexes on any fields you plan to apply attribute filters upon.
>

So I did figure out how to import the multiple shapefiles into a single
table.  You'll be hearing from me again if I decide to break the tables up,
cause I haven't figured out how to do that.  We aren't rendering on the fly,
so performance is not critical.  However, as more data gets added to these
maps, it may be necessary to speed things up.

Here's the script I used to import the multiple shapefiles.  Did I miss
anything?

#!/bin/bash

# name of a preexisting PostGIS database
database="vmap0"
# name of the table to store the shapefiles in
table="world"
# name of the directory where the shapefiles are located
dir="/Users/intern1/map_data/global-1.0/data/vmap0/world_tiles"
# change name of the geometry attribute to something specific to this table
newgeom="world_geom"
# name of the GiST spatial index to be created, specific to the table
indexname="world_geom_gist"
# original name of the geometry attribute in the shapefile
geometry="the_geom"
# trigger to create a new table (1 to create, 0 to append)
create=1

# loop through all the shapefiles, and add them to the database
cd $dir
for name in *.shp; do                    # filenames in the directory
    if [ -f "$name" ]; then                # it's a file
        bname="${name%.shp}"            # chop off the extension
        if [ $create -eq 1 ]; then        # use the first shapefile to
create the table
            shp2pgsql -d $bname $table | sudo -u postgres psql -Upostgres
$database
            create=0
        else                            # append the other shapefiles
            shp2pgsql -a $bname $table | sudo -u postgres psql -Upostgres
$database
        fi
    fi
done
# change the geometry column name to be specific to this table, and register
it so Mapnik knows
echo "ALTER TABLE $table RENAME COLUMN $geometry TO $newgeom;" | sudo -u
postgres psql -Upostgres $database
echo "UPDATE geometry_columns SET f_geometry_column='$newgeom' WHERE
f_table_name='$table'" | sudo -u postgres psql -Upostgres $database
# once all the data is in the table, create the spatial index
echo "GRANT SELECT ON $table TO public;" | sudo -u postgres psql -Upostgres
$database
echo "CREATE INDEX $indexname ON $table USING GIST ( $newgeom );"   | sudo
-u postgres psql -Upostgres $database
echo "VACUUM ANALYZE $table;" | sudo -u postgres psql -Upostgres $database
echo "CLUSTER $indexname ON $table;" | sudo -u postgres psql -Upostgres
$database
_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to