[postgis-users] shape file loading

Wood Brent pcreso at pcreso.com
Fri Sep 17 15:02:08 PDT 2004


--- Stefano Bonnin <stefano.bonnin at comai.to> wrote:

> Hi,
> 
> I have one spatial table (my_postgis_table) with a schema like
> 
>     the_geom,object_name,object_id ......
> 
> I'd like to know if is possible in a simple way to load data from a generic
> shape file into "my_postgis_table".
> 
> The shp2pgsql load data into postgis spatial table creating a table with the
> same schema of the shape, so, the problem here is to "create a mapping" from
> shp file fields and my table.
> 
> The most simple way that I found is the following:
> 
> 1) use the shp2pgsql loader in order to load the data into postgres spatial
> table (my_spatial_table_temp)
> 2) read the schema of "my_spatial_table_temp" and give to the user a page
> where to create the mapping between the 2 tables
>             Example:
> 
>                             my_spatial_table_temp.generic_field1 -->
> my_postgis_table.object_name
>                             my_spatial_table_temp.generic_field2 -->
> my_postgis_table.object_name
> 
>                             ...
> 
>                             and obviously:
>                             my_spatial_table_temp.geom -->
> my_postgis_table.the geom
>                             ....
>                             and so on ...
> 
> 

Not sure, but another approach (may or may not be simpler) would be to work out
the attribute mapping and parse the shp2pgsql SQL file prior to running so it
loads directly into your generic table, and doesn't use unecessary temporary
tables.

My approach would be to run shape2pgsql to create the sql, then shapelib to get
a list of attr names (dbfdump?), then summat like 
grep 's/dbfattrname/tabattrname/g' the sql for each attr & the tabname, then
run the sql to load the data straight into the generic table.

Just because I feel tools for parsing text & table/attr names etc are a bit
more flexible outside of SQL.....


Cheers,

  Brent Wood



More information about the postgis-users mailing list